Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6a42666

Browse filesBrowse files
authored
Merge pull request GoogleCloudPlatform#1374 from GoogleCloudPlatform/iot-cleanup
Cleanup Cloud IoT region tags.
2 parents edcf98f + 1422d12 commit 6a42666
Copy full SHA for 6a42666

File tree

Expand file treeCollapse file tree

3 files changed

+44
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+44
-1
lines changed

‎iot/api-client/http_example/cloudiot_http_example.py

Copy file name to clipboardExpand all lines: iot/api-client/http_example/cloudiot_http_example.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
README in the parent folder.
2222
"""
2323

24+
# [START iot_http_includes]
2425
import argparse
2526
import base64
2627
import datetime
@@ -30,11 +31,13 @@
3031
from google.api_core import retry
3132
import jwt
3233
import requests
34+
# [END iot_http_includes]
3335

3436
_BASE_URL = 'https://cloudiotdevice.googleapis.com/v1'
3537
_BACKOFF_DURATION = 60
3638

3739

40+
# [START iot_http_jwt]
3841
def create_jwt(project_id, private_key_file, algorithm):
3942
token = {
4043
# The time the token was issued.
@@ -53,11 +56,13 @@ def create_jwt(project_id, private_key_file, algorithm):
5356
algorithm, private_key_file))
5457

5558
return jwt.encode(token, private_key, algorithm=algorithm).decode('ascii')
59+
# [END iot_http_jwt]
5660

5761

5862
@retry.Retry(
5963
predicate=retry.if_exception_type(AssertionError),
6064
deadline=_BACKOFF_DURATION)
65+
# [START iot_http_publish]
6166
def publish_message(
6267
message, message_type, base_url, project_id, cloud_region, registry_id,
6368
device_id, jwt_token):
@@ -92,6 +97,7 @@ def publish_message(
9297
raise AssertionError('Not OK response: {}'.format(resp.status_code))
9398

9499
return resp
100+
# [END iot_http_publish]
95101

96102

97103
@retry.Retry(
@@ -172,6 +178,7 @@ def parse_command_line_args():
172178
return parser.parse_args()
173179

174180

181+
# [START iot_http_run]
175182
def main():
176183
args = parse_command_line_args()
177184

@@ -208,6 +215,7 @@ def main():
208215
# Send events every second. State should not be updated as often
209216
time.sleep(1 if args.message_type == 'event' else 5)
210217
print('Finished.')
218+
# [END iot_http_run]
211219

212220

213221
if __name__ == '__main__':

‎iot/api-client/manager/manager.py

Copy file name to clipboardExpand all lines: iot/api-client/manager/manager.py
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def get_client(service_account_json):
8282
credentials=scoped_credentials)
8383

8484

85+
# [START iot_create_rsa_device]
8586
def create_rs256_device(
8687
service_account_json, project_id, cloud_region, registry_id, device_id,
8788
certificate_file):
@@ -107,8 +108,10 @@ def create_rs256_device(
107108

108109
devices = client.projects().locations().registries().devices()
109110
return devices.create(parent=registry_name, body=device_template).execute()
111+
# [END iot_create_rsa_device]
110112

111113

114+
# [START iot_create_es_device]
112115
def create_es256_device(
113116
service_account_json, project_id, cloud_region, registry_id,
114117
device_id, public_key_file):
@@ -134,8 +137,10 @@ def create_es256_device(
134137

135138
devices = client.projects().locations().registries().devices()
136139
return devices.create(parent=registry_name, body=device_template).execute()
140+
# [END iot_create_es_device]
137141

138142

143+
# [START iot_create_unauth_device]
139144
def create_unauth_device(
140145
service_account_json, project_id, cloud_region, registry_id,
141146
device_id):
@@ -150,8 +155,10 @@ def create_unauth_device(
150155

151156
devices = client.projects().locations().registries().devices()
152157
return devices.create(parent=registry_name, body=device_template).execute()
158+
# [END iot_create_unauth_device]
153159

154160

161+
# [START iot_delete_device]
155162
def delete_device(
156163
service_account_json, project_id, cloud_region, registry_id,
157164
device_id):
@@ -165,8 +172,10 @@ def delete_device(
165172

166173
devices = client.projects().locations().registries().devices()
167174
return devices.delete(name=device_name).execute()
175+
# [END iot_delete_device]
168176

169177

178+
# [START iot_delete_registry]
170179
def delete_registry(
171180
service_account_json, project_id, cloud_region, registry_id):
172181
"""Deletes the specified registry."""
@@ -177,8 +186,10 @@ def delete_registry(
177186

178187
registries = client.projects().locations().registries()
179188
return registries.delete(name=registry_name).execute()
189+
# [END iot_delete_registry]
180190

181191

192+
# [START iot_get_device]
182193
def get_device(
183194
service_account_json, project_id, cloud_region, registry_id,
184195
device_id):
@@ -209,8 +220,10 @@ def get_device(
209220
'cloudUpdateTime')))
210221

211222
return device
223+
# [END iot_get_device]
212224

213225

226+
# [START iot_get_device_state]
214227
def get_state(
215228
service_account_json, project_id, cloud_region, registry_id,
216229
device_id):
@@ -226,8 +239,10 @@ def get_state(
226239
print('State: {}\n'.format(state))
227240

228241
return state
242+
# [END iot_get_device_state]
229243

230244

245+
# [START iot_list_devices]
231246
def list_devices(
232247
service_account_json, project_id, cloud_region, registry_id):
233248
"""List all devices in the registry."""
@@ -244,8 +259,10 @@ def list_devices(
244259
device.get('id')))
245260

246261
return devices
262+
# [END iot_list_devices]
247263

248264

265+
# [START iot_list_registries]
249266
def list_registries(service_account_json, project_id, cloud_region):
250267
"""List all registries in the project."""
251268
print('Listing Registries')
@@ -261,8 +278,10 @@ def list_registries(service_account_json, project_id, cloud_region):
261278
registry.get('name')))
262279

263280
return registries
281+
# [END iot_list_devices]
264282

265283

284+
# [START iot_create_registry]
266285
def create_registry(
267286
service_account_json, project_id, cloud_region, pubsub_topic,
268287
registry_id):
@@ -288,8 +307,10 @@ def create_registry(
288307
except HttpError:
289308
print('Error, registry not created')
290309
return ""
310+
# [END iot_create_registry]
291311

292312

313+
# [START iot_get_registry]
293314
def get_registry(
294315
service_account_json, project_id, cloud_region, registry_id):
295316
""" Retrieves a device registry."""
@@ -300,6 +321,7 @@ def get_registry(
300321
topic_name = '{}/registries/{}'.format(registry_parent, registry_id)
301322
request = client.projects().locations().registries().get(name=topic_name)
302323
return request.execute()
324+
# [END iot_get_registry]
303325

304326

305327
def open_registry(
@@ -325,6 +347,7 @@ def open_registry(
325347
print(response)
326348

327349

350+
# [START iot_patch_es]
328351
def patch_es256_auth(
329352
service_account_json, project_id, cloud_region, registry_id,
330353
device_id, public_key_file):
@@ -350,8 +373,10 @@ def patch_es256_auth(
350373

351374
return client.projects().locations().registries().devices().patch(
352375
name=device_name, updateMask='credentials', body=patch).execute()
376+
# [END iot_patch_es]
353377

354378

379+
# [START iot_patch_rsa]
355380
def patch_rsa256_auth(
356381
service_account_json, project_id, cloud_region, registry_id, device_id,
357382
public_key_file):
@@ -377,8 +402,10 @@ def patch_rsa256_auth(
377402

378403
return client.projects().locations().registries().devices().patch(
379404
name=device_name, updateMask='credentials', body=patch).execute()
405+
# [END iot_patch_rsa]
380406

381407

408+
# [START iot_set_device_config]
382409
def set_config(
383410
service_account_json, project_id, cloud_region, registry_id, device_id,
384411
version, config):
@@ -397,8 +424,10 @@ def set_config(
397424
).locations().registries(
398425
).devices().modifyCloudToDeviceConfig(
399426
name=device_path, body=config_body).execute()
427+
# [END iot_set_device_config]
400428

401429

430+
# [START iot_get_device_configs]
402431
def get_config_versions(
403432
service_account_json, project_id, cloud_region, registry_id,
404433
device_id):
@@ -420,8 +449,10 @@ def get_config_versions(
420449
config.get('binaryData')))
421450

422451
return configs
452+
# [END iot_get_device_configs]
423453

424454

455+
# [START iot_get_iam_policy]
425456
def get_iam_permissions(
426457
service_account_json, project_id, cloud_region, registry_id):
427458
"""Retrieves IAM permissions for the given registry."""
@@ -433,8 +464,10 @@ def get_iam_permissions(
433464
resource=registry_path, body={}).execute()
434465

435466
return policy
467+
# [END iot_get_iam_policy]
436468

437469

470+
# [START iot_set_iam_policy]
438471
def set_iam_permissions(
439472
service_account_json, project_id, cloud_region, registry_id, role,
440473
member):
@@ -456,6 +489,7 @@ def set_iam_permissions(
456489

457490
return client.projects().locations().registries().setIamPolicy(
458491
resource=registry_path, body=body).execute()
492+
# [END iot_set_iam_policy]
459493

460494

461495
def parse_command_line_args():

‎iot/api-client/mqtt_example/cloudiot_mqtt_example.py

Copy file name to clipboardExpand all lines: iot/api-client/mqtt_example/cloudiot_mqtt_example.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
for this sample.
2222
"""
2323

24+
# [START iot_mqtt_includes]
2425
import argparse
2526
import datetime
2627
import os
@@ -30,7 +31,7 @@
3031

3132
import jwt
3233
import paho.mqtt.client as mqtt
33-
34+
# [END iot_mqtt_includes]
3435

3536
# The initial backoff time after a disconnection occurs, in seconds.
3637
minimum_backoff_time = 1

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.