@@ -399,6 +399,29 @@ def set_config(
399399 name = device_path , body = config_body ).execute ()
400400
401401
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+
402425def parse_command_line_args ():
403426 """Parse command line arguments."""
404427 default_registry = 'cloudiot_device_manager_example_registry_{}' .format (
@@ -469,6 +492,7 @@ def parse_command_line_args():
469492 command .add_parser ('patch-es256' , help = patch_es256_auth .__doc__ )
470493 command .add_parser ('patch-rs256' , help = patch_rsa256_auth .__doc__ )
471494 command .add_parser ('set-config' , help = patch_rsa256_auth .__doc__ )
495+ command .add_parser ('get-config-versions' , help = get_config_versions .__doc__ )
472496
473497 return parser .parse_args ()
474498
@@ -571,6 +595,11 @@ def run_command(args):
571595 args .cloud_region , args .registry_id , args .device_id ,
572596 args .version , args .config )
573597
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+
574603
575604def main ():
576605 args = parse_command_line_args ()
0 commit comments