@@ -422,42 +422,6 @@ def get_config_versions(
422
422
return configs
423
423
424
424
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
-
461
425
def parse_command_line_args ():
462
426
"""Parse command line arguments."""
463
427
default_registry = 'cloudiot_device_manager_example_registry_{}' .format (
@@ -509,14 +473,6 @@ def parse_command_line_args():
509
473
'--version' ,
510
474
default = None ,
511
475
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.' )
520
476
521
477
# Command subparser
522
478
command = parser .add_subparsers (dest = 'command' )
@@ -529,16 +485,14 @@ def parse_command_line_args():
529
485
command .add_parser ('delete-device' , help = delete_device .__doc__ )
530
486
command .add_parser ('delete-registry' , help = delete_registry .__doc__ )
531
487
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__ )
534
488
command .add_parser ('get-registry' , help = get_registry .__doc__ )
535
489
command .add_parser ('get-state' , help = get_state .__doc__ )
536
490
command .add_parser ('list' , help = list_devices .__doc__ )
537
491
command .add_parser ('list-registries' , help = list_registries .__doc__ )
538
492
command .add_parser ('patch-es256' , help = patch_es256_auth .__doc__ )
539
493
command .add_parser ('patch-rs256' , help = patch_rsa256_auth .__doc__ )
540
494
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__ )
542
496
543
497
return parser .parse_args ()
544
498
@@ -571,45 +525,15 @@ def run_create(args):
571
525
create_iot_topic (args .project_id , args .pubsub_topic )
572
526
573
527
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
-
601
528
def run_command (args ):
602
529
"""Calls the program using the specified command."""
603
530
if args .project_id is None :
604
531
print ('You must specify a project ID or set the environment variable.' )
605
532
return
606
533
607
- elif args .command .startswith ('create' ):
534
+ if args .command .startswith ('create' ):
608
535
run_create (args )
609
536
610
- elif args .command .startswith ('get' ):
611
- run_get (args )
612
-
613
537
elif args .command == 'delete-device' :
614
538
delete_device (
615
539
args .service_account_json , args .project_id ,
@@ -620,6 +544,21 @@ def run_command(args):
620
544
args .service_account_json , args .project_id ,
621
545
args .cloud_region , args .registry_id )
622
546
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
+
623
562
elif args .command == 'list' :
624
563
list_devices (
625
564
args .service_account_json , args .project_id ,
@@ -646,15 +585,6 @@ def run_command(args):
646
585
args .cloud_region , args .registry_id , args .device_id ,
647
586
args .rsa_certificate_file )
648
587
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
-
658
588
elif args .command == 'set-config' :
659
589
if (args .config is None ):
660
590
sys .exit ('Error: specify --config' )
@@ -665,6 +595,11 @@ def run_command(args):
665
595
args .cloud_region , args .registry_id , args .device_id ,
666
596
args .version , args .config )
667
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
+
668
603
669
604
def main ():
670
605
args = parse_command_line_args ()
0 commit comments