@@ -422,42 +422,6 @@ def get_config_versions(
422422 return configs
423423
424424
425- def get_iam_permissions (
426- service_account_json , project_id , cloud_region , registry_id ):
427- """Retrieves IAM permissions for the given registry."""
428- client = get_client (service_account_json )
429- registry_path = 'projects/{}/locations/{}/registries/{}' .format (
430- project_id , cloud_region , registry_id )
431-
432- policy = client .projects ().locations ().registries ().getIamPolicy (
433- resource = registry_path , body = {}).execute ()
434-
435- return policy
436-
437-
438- def set_iam_permissions (
439- service_account_json , project_id , cloud_region , registry_id , role ,
440- member ):
441- """Retrieves IAM permissions for the given registry."""
442- client = get_client (service_account_json )
443-
444- registry_path = 'projects/{}/locations/{}/registries/{}' .format (
445- project_id , cloud_region , registry_id )
446- body = {
447- "policy" :
448- {
449- "bindings" :
450- [{
451- "members" : [member ],
452- "role" : role
453- }]
454- }
455- }
456-
457- return client .projects ().locations ().registries ().setIamPolicy (
458- resource = registry_path , body = body ).execute ()
459-
460-
461425def parse_command_line_args ():
462426 """Parse command line arguments."""
463427 default_registry = 'cloudiot_device_manager_example_registry_{}' .format (
@@ -509,14 +473,6 @@ def parse_command_line_args():
509473 '--version' ,
510474 default = None ,
511475 help = 'Version number for setting device configuration.' )
512- parser .add_argument (
513- '--member' ,
514- default = None ,
515- help = 'Member used for IAM commands.' )
516- parser .add_argument (
517- '--role' ,
518- default = None ,
519- help = 'Role used for IAM commands.' )
520476
521477 # Command subparser
522478 command = parser .add_subparsers (dest = 'command' )
@@ -529,16 +485,14 @@ def parse_command_line_args():
529485 command .add_parser ('delete-device' , help = delete_device .__doc__ )
530486 command .add_parser ('delete-registry' , help = delete_registry .__doc__ )
531487 command .add_parser ('get' , help = get_device .__doc__ )
532- command .add_parser ('get-config-versions' , help = get_config_versions .__doc__ )
533- command .add_parser ('get-iam-permissions' , help = get_iam_permissions .__doc__ )
534488 command .add_parser ('get-registry' , help = get_registry .__doc__ )
535489 command .add_parser ('get-state' , help = get_state .__doc__ )
536490 command .add_parser ('list' , help = list_devices .__doc__ )
537491 command .add_parser ('list-registries' , help = list_registries .__doc__ )
538492 command .add_parser ('patch-es256' , help = patch_es256_auth .__doc__ )
539493 command .add_parser ('patch-rs256' , help = patch_rsa256_auth .__doc__ )
540494 command .add_parser ('set-config' , help = patch_rsa256_auth .__doc__ )
541- command .add_parser ('set-iam-permissions ' , help = set_iam_permissions .__doc__ )
495+ command .add_parser ('get-config-versions ' , help = get_config_versions .__doc__ )
542496
543497 return parser .parse_args ()
544498
@@ -571,45 +525,15 @@ def run_create(args):
571525 create_iot_topic (args .project_id , args .pubsub_topic )
572526
573527
574- def run_get (args ):
575- if args .command == 'get' :
576- get_device (
577- args .service_account_json , args .project_id ,
578- args .cloud_region , args .registry_id , args .device_id )
579-
580- elif args .command == 'get-config-versions' :
581- get_device (
582- args .service_account_json , args .project_id ,
583- args .cloud_region , args .registry_id , args .device_id )
584-
585- elif args .command == 'get-state' :
586- get_state (
587- args .service_account_json , args .project_id ,
588- args .cloud_region , args .registry_id , args .device_id )
589-
590- elif args .command == 'get-iam-permissions' :
591- print (get_iam_permissions (
592- args .service_account_json , args .project_id ,
593- args .cloud_region , args .registry_id ))
594-
595- elif args .command == 'get-registry' :
596- print (get_registry (
597- args .service_account_json , args .project_id ,
598- args .cloud_region , args .registry_id ))
599-
600-
601528def run_command (args ):
602529 """Calls the program using the specified command."""
603530 if args .project_id is None :
604531 print ('You must specify a project ID or set the environment variable.' )
605532 return
606533
607- elif args .command .startswith ('create' ):
534+ if args .command .startswith ('create' ):
608535 run_create (args )
609536
610- elif args .command .startswith ('get' ):
611- run_get (args )
612-
613537 elif args .command == 'delete-device' :
614538 delete_device (
615539 args .service_account_json , args .project_id ,
@@ -620,6 +544,21 @@ def run_command(args):
620544 args .service_account_json , args .project_id ,
621545 args .cloud_region , args .registry_id )
622546
547+ elif args .command == 'get' :
548+ get_device (
549+ args .service_account_json , args .project_id ,
550+ args .cloud_region , args .registry_id , args .device_id )
551+
552+ elif args .command == 'get-state' :
553+ get_state (
554+ args .service_account_json , args .project_id ,
555+ args .cloud_region , args .registry_id , args .device_id )
556+
557+ elif args .command == 'get-registry' :
558+ print (get_registry (
559+ args .service_account_json , args .project_id ,
560+ args .cloud_region , args .registry_id ))
561+
623562 elif args .command == 'list' :
624563 list_devices (
625564 args .service_account_json , args .project_id ,
@@ -646,15 +585,6 @@ def run_command(args):
646585 args .cloud_region , args .registry_id , args .device_id ,
647586 args .rsa_certificate_file )
648587
649- elif args .command == 'set-iam-permissions' :
650- if (args .member is None ):
651- sys .exit ('Error: specify --member' )
652- if (args .role is None ):
653- sys .exit ('Error: specify --role' )
654- set_iam_permissions (
655- args .service_account_json , args .project_id ,
656- args .cloud_region , args .registry_id , args .role , args .member )
657-
658588 elif args .command == 'set-config' :
659589 if (args .config is None ):
660590 sys .exit ('Error: specify --config' )
@@ -665,6 +595,11 @@ def run_command(args):
665595 args .cloud_region , args .registry_id , args .device_id ,
666596 args .version , args .config )
667597
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+
668603
669604def main ():
670605 args = parse_command_line_args ()
0 commit comments