@@ -110,6 +110,7 @@ public static Topic createIotTopic(String projectId, String topicId) throws Exce
110110    }
111111  }
112112
113+   // [START iot_create_registry] 
113114  /** Create a registry for Cloud IoT. */ 
114115  public  static  void  createRegistry (String  cloudRegion , String  projectId , String  registryName ,
115116                                    String  pubsubTopicPath )
@@ -137,7 +138,9 @@ public static void createRegistry(String cloudRegion, String projectId, String r
137138        registry ).execute ();
138139    System .out .println ("Created registry: "  + reg .getName ());
139140  }
141+   // [END iot_create_registry] 
140142
143+   // [START iot_delete_registry] 
141144  /** Delete this registry from Cloud IoT. */ 
142145  public  static  void  deleteRegistry (String  cloudRegion , String  projectId , String  registryName )
143146      throws  GeneralSecurityException , IOException  {
@@ -155,7 +158,9 @@ public static void deleteRegistry(String cloudRegion, String projectId, String r
155158    System .out .println ("Deleting: "  + registryPath );
156159    service .projects ().locations ().registries ().delete (registryPath ).execute ();
157160  }
161+   // [END iot_delete_registry] 
158162
163+   // [START iot_list_devices] 
159164  /** Print all of the devices in this registry to standard out. */ 
160165  public  static  void  listDevices (String  projectId , String  cloudRegion , String  registryName ) throws 
161166      GeneralSecurityException , IOException  {
@@ -194,7 +199,9 @@ public static void listDevices(String projectId, String cloudRegion, String regi
194199      System .out .println ("Registry has no devices." );
195200    }
196201  }
202+   // [END iot_list_devices] 
197203
204+   // [START iot_create_es_device] 
198205  /** Create a device that is authenticated using ES256. */ 
199206  public  static  void  createDeviceWithEs256 (String  deviceId , String  publicKeyFilePath ,
200207      String  projectId , String  cloudRegion , String  registryName )
@@ -234,7 +241,9 @@ public static void createDeviceWithEs256(String deviceId, String publicKeyFilePa
234241
235242    System .out .println ("Created device: "  + createdDevice .toPrettyString ());
236243  }
244+   // [END iot_create_es_device] 
237245
246+   // [START iot_create_rsa_device] 
238247  /** Create a device that is authenticated using RS256. */ 
239248  public  static  void  createDeviceWithRs256 (String  deviceId , String  certificateFilePath ,
240249                                           String  projectId , String  cloudRegion ,
@@ -274,7 +283,9 @@ public static void createDeviceWithRs256(String deviceId, String certificateFile
274283
275284    System .out .println ("Created device: "  + createdDevice .toPrettyString ());
276285  }
286+   // [END iot_create_rsa_device] 
277287
288+   // [START iot_create_unauth_device] 
278289  /** 
279290   * Create a device that has no credentials. 
280291   * 
@@ -310,7 +321,9 @@ public static void createDeviceWithNoAuth(String deviceId, String projectId, Str
310321
311322    System .out .println ("Created device: "  + createdDevice .toPrettyString ());
312323  }
324+   // [END iot_create_unauth_device] 
313325
326+   // [START iot_delete_device] 
314327  /** Delete the given device from the registry. */ 
315328  public  static  void  deleteDevice (String  deviceId , String  projectId , String  cloudRegion ,
316329                                  String  registryName )
@@ -329,7 +342,9 @@ public static void deleteDevice(String deviceId, String projectId, String cloudR
329342    System .out .println ("Deleting device "  + devicePath );
330343    service .projects ().locations ().registries ().devices ().delete (devicePath ).execute ();
331344  }
345+   // [END iot_delete_device] 
332346
347+   // [START iot_get_device] 
333348  /** Retrieves device metadata from a registry. **/ 
334349  public  static  Device  getDevice (String  deviceId , String  projectId , String  cloudRegion ,
335350                                 String  registryName ) throws  GeneralSecurityException , IOException  {
@@ -347,7 +362,9 @@ public static Device getDevice(String deviceId, String projectId, String cloudRe
347362    System .out .println ("Retrieving device "  + devicePath );
348363    return  service .projects ().locations ().registries ().devices ().get (devicePath ).execute ();
349364  }
365+   // [END iot_get_device] 
350366
367+   // [START iot_get_device_state] 
351368  /** Retrieves device metadata from a registry. **/ 
352369  public  static  List <DeviceState > getDeviceStates (
353370      String  deviceId , String  projectId , String  cloudRegion , String  registryName )
@@ -375,7 +392,9 @@ public static List<DeviceState> getDeviceStates(
375392
376393    return  resp .getDeviceStates ();
377394  }
395+   // [END iot_get_device_state] 
378396
397+   // [START iot_get_registry] 
379398  /** Retrieves registry metadata from a project. **/ 
380399  public  static  DeviceRegistry  getRegistry (
381400      String  projectId , String  cloudRegion , String  registryName )
@@ -393,7 +412,9 @@ public static DeviceRegistry getRegistry(
393412
394413    return  service .projects ().locations ().registries ().get (registryPath ).execute ();
395414  }
415+   // [END iot_get_registry] 
396416
417+   // [START iot_get_device_config] 
397418  /** List all of the configs for the given device. */ 
398419  public  static  void  listDeviceConfigs (
399420      String  deviceId , String  projectId , String  cloudRegion , String  registryName )
@@ -427,7 +448,9 @@ public static void listDeviceConfigs(
427448      System .out .println ();
428449    }
429450  }
451+   // [END iot_get_device_config] 
430452
453+   // [START iot_list_registries] 
431454  /** Lists all of the registries associated with the given project. */ 
432455  public  static  void  listRegistries (String  projectId , String  cloudRegion )
433456      throws  GeneralSecurityException , IOException  {
@@ -464,7 +487,9 @@ public static void listRegistries(String projectId, String cloudRegion)
464487      System .out .println ("Project has no registries." );
465488    }
466489  }
490+   // [END iot_list_registries] 
467491
492+   // [START iot_patch_es] 
468493  /** Patch the device to add an ES256 key for authentication. */ 
469494  public  static  void  patchEs256ForAuth (String  deviceId , String  publicKeyFilePath , String  projectId ,
470495                                       String  cloudRegion , String  registryName )
@@ -503,7 +528,9 @@ public static void patchEs256ForAuth(String deviceId, String publicKeyFilePath,
503528
504529    System .out .println ("Patched device is "  + patchedDevice .toPrettyString ());
505530  }
531+   // [END iot_patch_es] 
506532
533+   // [START iot_patch_rsa] 
507534  /** Patch the device to add an RSA256 key for authentication. */ 
508535  public  static  void  patchRsa256ForAuth (String  deviceId , String  publicKeyFilePath , String  projectId ,
509536                                        String  cloudRegion ,
@@ -543,7 +570,9 @@ public static void patchRsa256ForAuth(String deviceId, String publicKeyFilePath,
543570
544571    System .out .println ("Patched device is "  + patchedDevice .toPrettyString ());
545572  }
573+   // [END iot_patch_rsa] 
546574
575+   // [START iot_set_device_config] 
547576  /** Set a device configuration to the specified data (string, JSON) and version (0 for latest). */ 
548577  public  static  void  setDeviceConfiguration (
549578      String  deviceId , String  projectId , String  cloudRegion , String  registryName ,
@@ -578,7 +607,9 @@ public static void setDeviceConfiguration(
578607
579608    System .out .println ("Updated: "  + config .getVersion ());
580609  }
610+   // [END iot_set_device_config] 
581611
612+   // [START iot_get_iam_policy] 
582613  /** Retrieves IAM permissions for the given registry. */ 
583614  public  static  void  getIamPermissions (
584615      String  projectId , String  cloudRegion , String  registryName )
@@ -615,7 +646,9 @@ public static void getIamPermissions(
615646      System .out .println (String .format ("No policy bindings for %s" , registryName ));
616647    }
617648  }
649+   // [END iot_get_iam_policy] 
618650
651+   // [START iot_set_iam_policy] 
619652  /** Sets IAM permissions for the given registry. */ 
620653  public  static  void  setIamPermissions (
621654      String  projectId , String  cloudRegion , String  registryName ,
@@ -686,6 +719,7 @@ public static void setIamPermissions(
686719      }
687720    }
688721  }
722+   // [END iot_set_iam_policy] 
689723
690724  /** Entry poit for CLI. */ 
691725  public  static  void  main (String [] args ) throws  Exception  {
0 commit comments