@@ -399,6 +399,29 @@ def set_config(
399
399
name = device_path , body = config_body ).execute ()
400
400
401
401
402
+ def get_config_versions (
403
+ service_account_json , project_id , cloud_region , registry_id ,
404
+ device_id ):
405
+ """Lists versions of a device config in descending order (newest first)."""
406
+ client = get_client (service_account_json )
407
+ registry_name = 'projects/{}/locations/{}/registries/{}' .format (
408
+ project_id , cloud_region , registry_id )
409
+
410
+ device_name = '{}/devices/{}' .format (registry_name , device_id )
411
+ devices = client .projects ().locations ().registries ().devices ()
412
+ configs = devices .configVersions ().list (
413
+ name = device_name ).execute ().get (
414
+ 'deviceConfigs' , [])
415
+
416
+ for config in configs :
417
+ print ('version: {}\n \t cloudUpdateTime: {}\n \t binaryData: {}' .format (
418
+ config .get ('version' ),
419
+ config .get ('cloudUpdateTime' ),
420
+ config .get ('binaryData' )))
421
+
422
+ return configs
423
+
424
+
402
425
def parse_command_line_args ():
403
426
"""Parse command line arguments."""
404
427
default_registry = 'cloudiot_device_manager_example_registry_{}' .format (
@@ -469,6 +492,7 @@ def parse_command_line_args():
469
492
command .add_parser ('patch-es256' , help = patch_es256_auth .__doc__ )
470
493
command .add_parser ('patch-rs256' , help = patch_rsa256_auth .__doc__ )
471
494
command .add_parser ('set-config' , help = patch_rsa256_auth .__doc__ )
495
+ command .add_parser ('get-config-versions' , help = get_config_versions .__doc__ )
472
496
473
497
return parser .parse_args ()
474
498
@@ -571,6 +595,11 @@ def run_command(args):
571
595
args .cloud_region , args .registry_id , args .device_id ,
572
596
args .version , args .config )
573
597
598
+ elif args .command == 'get-config-versions' :
599
+ get_device (
600
+ args .service_account_json , args .project_id ,
601
+ args .cloud_region , args .registry_id , args .device_id )
602
+
574
603
575
604
def main ():
576
605
args = parse_command_line_args ()
0 commit comments