@@ -64,7 +64,6 @@ def get_client(service_account_json, api_key):
64
64
"""Returns an authorized API client by discovering the IoT API using the
65
65
provided API key and creating a service object using the service account
66
66
credentials JSON."""
67
- # [START authorize]
68
67
api_scopes = ['https://www.googleapis.com/auth/cloud-platform' ]
69
68
api_version = 'v1beta1'
70
69
discovery_api = 'https://cloudiot.googleapis.com/$discovery/rest'
@@ -82,15 +81,13 @@ def get_client(service_account_json, api_key):
82
81
api_version ,
83
82
discoveryServiceUrl = discovery_url ,
84
83
credentials = scoped_credentials )
85
- # [END authorize]
86
84
87
85
88
86
def create_rs256_device (
89
87
service_account_json , api_key , project_id , cloud_region , registry_id ,
90
88
device_id , certificate_file ):
91
89
"""Create a new device with the given id, using RS256 for
92
90
authentication."""
93
- # [START create_rs256_device]
94
91
registry_name = 'projects/{}/locations/{}/registries/{}' .format (
95
92
project_id , cloud_region , registry_id )
96
93
@@ -111,15 +108,13 @@ def create_rs256_device(
111
108
112
109
devices = client .projects ().locations ().registries ().devices ()
113
110
return devices .create (parent = registry_name , body = device_template ).execute ()
114
- # [END create_rs256_device]
115
111
116
112
117
113
def create_es256_device (
118
114
service_account_json , api_key , project_id , cloud_region , registry_id ,
119
115
device_id , public_key_file ):
120
116
"""Create a new device with the given id, using ES256 for
121
117
authentication."""
122
- # [START create_rs256_device]
123
118
registry_name = 'projects/{}/locations/{}/registries/{}' .format (
124
119
project_id , cloud_region , registry_id )
125
120
@@ -140,14 +135,12 @@ def create_es256_device(
140
135
141
136
devices = client .projects ().locations ().registries ().devices ()
142
137
return devices .create (parent = registry_name , body = device_template ).execute ()
143
- # [END create_rs256_device]
144
138
145
139
146
140
def create_unauth_device (
147
141
service_account_json , api_key , project_id , cloud_region , registry_id ,
148
142
device_id ):
149
143
"""Create a new device without authentication."""
150
- # [START create_noauth_device]
151
144
registry_name = 'projects/{}/locations/{}/registries/{}' .format (
152
145
project_id , cloud_region , registry_id )
153
146
@@ -158,14 +151,12 @@ def create_unauth_device(
158
151
159
152
devices = client .projects ().locations ().registries ().devices ()
160
153
return devices .create (parent = registry_name , body = device_template ).execute ()
161
- # [END create_noauth_device]
162
154
163
155
164
156
def delete_device (
165
157
service_account_json , api_key , project_id , cloud_region , registry_id ,
166
158
device_id ):
167
159
"""Delete the device with the given id."""
168
- # [START delete_device]
169
160
print ('Delete device' )
170
161
client = get_client (service_account_json , api_key )
171
162
registry_name = 'projects/{}/locations/{}/registries/{}' .format (
@@ -175,28 +166,24 @@ def delete_device(
175
166
176
167
devices = client .projects ().locations ().registries ().devices ()
177
168
return devices .delete (name = device_name ).execute ()
178
- # [END delete_device]
179
169
180
170
181
171
def delete_registry (
182
172
service_account_json , api_key , project_id , cloud_region , registry_id ):
183
173
"""Deletes the specified registry."""
184
- # [START delete_registry]
185
174
print ('Delete registry' )
186
175
client = get_client (service_account_json , api_key )
187
176
registry_name = 'projects/{}/locations/{}/registries/{}' .format (
188
177
project_id , cloud_region , registry_id )
189
178
190
179
registries = client .projects ().locations ().registries ()
191
180
return registries .delete (name = registry_name ).execute ()
192
- # [END delete_registry]
193
181
194
182
195
183
def get_device (
196
184
service_account_json , api_key , project_id , cloud_region , registry_id ,
197
185
device_id ):
198
186
"""Retrieve the device with the given id."""
199
- # [START delete_device]
200
187
print ('Getting device' )
201
188
client = get_client (service_account_json , api_key )
202
189
registry_name = 'projects/{}/locations/{}/registries/{}' .format (
@@ -223,13 +210,11 @@ def get_device(
223
210
'cloudUpdateTime' )))
224
211
225
212
return device
226
- # [END delete_device]
227
213
228
214
229
215
def list_devices (
230
216
service_account_json , api_key , project_id , cloud_region , registry_id ):
231
217
"""List all devices in the registry."""
232
- # [START list_devices]
233
218
print ('Listing devices' )
234
219
registry_path = 'projects/{}/locations/{}/registries/{}' .format (
235
220
project_id , cloud_region , registry_id )
@@ -243,7 +228,6 @@ def list_devices(
243
228
device .get ('id' )))
244
229
245
230
return devices
246
- # [list_devices]
247
231
248
232
249
233
def open_registry (
0 commit comments