@@ -110,6 +110,7 @@ public static Topic createIotTopic(String projectId, String topicId) throws Exce
110
110
}
111
111
}
112
112
113
+ // [START iot_create_registry]
113
114
/** Create a registry for Cloud IoT. */
114
115
public static void createRegistry (String cloudRegion , String projectId , String registryName ,
115
116
String pubsubTopicPath )
@@ -137,7 +138,9 @@ public static void createRegistry(String cloudRegion, String projectId, String r
137
138
registry ).execute ();
138
139
System .out .println ("Created registry: " + reg .getName ());
139
140
}
141
+ // [END iot_create_registry]
140
142
143
+ // [START iot_delete_registry]
141
144
/** Delete this registry from Cloud IoT. */
142
145
public static void deleteRegistry (String cloudRegion , String projectId , String registryName )
143
146
throws GeneralSecurityException , IOException {
@@ -155,7 +158,9 @@ public static void deleteRegistry(String cloudRegion, String projectId, String r
155
158
System .out .println ("Deleting: " + registryPath );
156
159
service .projects ().locations ().registries ().delete (registryPath ).execute ();
157
160
}
161
+ // [END iot_delete_registry]
158
162
163
+ // [START iot_list_devices]
159
164
/** Print all of the devices in this registry to standard out. */
160
165
public static void listDevices (String projectId , String cloudRegion , String registryName ) throws
161
166
GeneralSecurityException , IOException {
@@ -194,7 +199,9 @@ public static void listDevices(String projectId, String cloudRegion, String regi
194
199
System .out .println ("Registry has no devices." );
195
200
}
196
201
}
202
+ // [END iot_list_devices]
197
203
204
+ // [START iot_create_es_device]
198
205
/** Create a device that is authenticated using ES256. */
199
206
public static void createDeviceWithEs256 (String deviceId , String publicKeyFilePath ,
200
207
String projectId , String cloudRegion , String registryName )
@@ -234,7 +241,9 @@ public static void createDeviceWithEs256(String deviceId, String publicKeyFilePa
234
241
235
242
System .out .println ("Created device: " + createdDevice .toPrettyString ());
236
243
}
244
+ // [END iot_create_es_device]
237
245
246
+ // [START iot_create_rsa_device]
238
247
/** Create a device that is authenticated using RS256. */
239
248
public static void createDeviceWithRs256 (String deviceId , String certificateFilePath ,
240
249
String projectId , String cloudRegion ,
@@ -274,7 +283,9 @@ public static void createDeviceWithRs256(String deviceId, String certificateFile
274
283
275
284
System .out .println ("Created device: " + createdDevice .toPrettyString ());
276
285
}
286
+ // [END iot_create_rsa_device]
277
287
288
+ // [START iot_create_unauth_device]
278
289
/**
279
290
* Create a device that has no credentials.
280
291
*
@@ -310,7 +321,9 @@ public static void createDeviceWithNoAuth(String deviceId, String projectId, Str
310
321
311
322
System .out .println ("Created device: " + createdDevice .toPrettyString ());
312
323
}
324
+ // [END iot_create_unauth_device]
313
325
326
+ // [START iot_delete_device]
314
327
/** Delete the given device from the registry. */
315
328
public static void deleteDevice (String deviceId , String projectId , String cloudRegion ,
316
329
String registryName )
@@ -329,7 +342,9 @@ public static void deleteDevice(String deviceId, String projectId, String cloudR
329
342
System .out .println ("Deleting device " + devicePath );
330
343
service .projects ().locations ().registries ().devices ().delete (devicePath ).execute ();
331
344
}
345
+ // [END iot_delete_device]
332
346
347
+ // [START iot_get_device]
333
348
/** Retrieves device metadata from a registry. **/
334
349
public static Device getDevice (String deviceId , String projectId , String cloudRegion ,
335
350
String registryName ) throws GeneralSecurityException , IOException {
@@ -347,7 +362,9 @@ public static Device getDevice(String deviceId, String projectId, String cloudRe
347
362
System .out .println ("Retrieving device " + devicePath );
348
363
return service .projects ().locations ().registries ().devices ().get (devicePath ).execute ();
349
364
}
365
+ // [END iot_get_device]
350
366
367
+ // [START iot_get_device_state]
351
368
/** Retrieves device metadata from a registry. **/
352
369
public static List <DeviceState > getDeviceStates (
353
370
String deviceId , String projectId , String cloudRegion , String registryName )
@@ -375,7 +392,9 @@ public static List<DeviceState> getDeviceStates(
375
392
376
393
return resp .getDeviceStates ();
377
394
}
395
+ // [END iot_get_device_state]
378
396
397
+ // [START iot_get_registry]
379
398
/** Retrieves registry metadata from a project. **/
380
399
public static DeviceRegistry getRegistry (
381
400
String projectId , String cloudRegion , String registryName )
@@ -393,7 +412,9 @@ public static DeviceRegistry getRegistry(
393
412
394
413
return service .projects ().locations ().registries ().get (registryPath ).execute ();
395
414
}
415
+ // [END iot_get_registry]
396
416
417
+ // [START iot_get_device_config]
397
418
/** List all of the configs for the given device. */
398
419
public static void listDeviceConfigs (
399
420
String deviceId , String projectId , String cloudRegion , String registryName )
@@ -427,7 +448,9 @@ public static void listDeviceConfigs(
427
448
System .out .println ();
428
449
}
429
450
}
451
+ // [END iot_get_device_config]
430
452
453
+ // [START iot_list_registries]
431
454
/** Lists all of the registries associated with the given project. */
432
455
public static void listRegistries (String projectId , String cloudRegion )
433
456
throws GeneralSecurityException , IOException {
@@ -464,7 +487,9 @@ public static void listRegistries(String projectId, String cloudRegion)
464
487
System .out .println ("Project has no registries." );
465
488
}
466
489
}
490
+ // [END iot_list_registries]
467
491
492
+ // [START iot_patch_es]
468
493
/** Patch the device to add an ES256 key for authentication. */
469
494
public static void patchEs256ForAuth (String deviceId , String publicKeyFilePath , String projectId ,
470
495
String cloudRegion , String registryName )
@@ -503,7 +528,9 @@ public static void patchEs256ForAuth(String deviceId, String publicKeyFilePath,
503
528
504
529
System .out .println ("Patched device is " + patchedDevice .toPrettyString ());
505
530
}
531
+ // [END iot_patch_es]
506
532
533
+ // [START iot_patch_rsa]
507
534
/** Patch the device to add an RSA256 key for authentication. */
508
535
public static void patchRsa256ForAuth (String deviceId , String publicKeyFilePath , String projectId ,
509
536
String cloudRegion ,
@@ -543,7 +570,9 @@ public static void patchRsa256ForAuth(String deviceId, String publicKeyFilePath,
543
570
544
571
System .out .println ("Patched device is " + patchedDevice .toPrettyString ());
545
572
}
573
+ // [END iot_patch_rsa]
546
574
575
+ // [START iot_set_device_config]
547
576
/** Set a device configuration to the specified data (string, JSON) and version (0 for latest). */
548
577
public static void setDeviceConfiguration (
549
578
String deviceId , String projectId , String cloudRegion , String registryName ,
@@ -578,7 +607,9 @@ public static void setDeviceConfiguration(
578
607
579
608
System .out .println ("Updated: " + config .getVersion ());
580
609
}
610
+ // [END iot_set_device_config]
581
611
612
+ // [START iot_get_iam_policy]
582
613
/** Retrieves IAM permissions for the given registry. */
583
614
public static void getIamPermissions (
584
615
String projectId , String cloudRegion , String registryName )
@@ -615,7 +646,9 @@ public static void getIamPermissions(
615
646
System .out .println (String .format ("No policy bindings for %s" , registryName ));
616
647
}
617
648
}
649
+ // [END iot_get_iam_policy]
618
650
651
+ // [START iot_set_iam_policy]
619
652
/** Sets IAM permissions for the given registry. */
620
653
public static void setIamPermissions (
621
654
String projectId , String cloudRegion , String registryName ,
@@ -686,6 +719,7 @@ public static void setIamPermissions(
686
719
}
687
720
}
688
721
}
722
+ // [END iot_set_iam_policy]
689
723
690
724
/** Entry poit for CLI. */
691
725
public static void main (String [] args ) throws Exception {
0 commit comments