5252example_template_id = None
5353example_template_etag = None
5454example_template_version = None
55+ example_basic_template_version = None
5556example_assignment_id = None
5657example_user_id = "IBMid-user1"
5758example_service_name = "iam-groups"
5859example_assignment_policy_id = None
5960example_updated_policy_etag = None
61+ example_target_account_id = None
62+ example_assignment_etag = None
6063
6164##############################################################################
6265# Start of Examples for Service: IamPolicyManagementV1
@@ -83,9 +86,10 @@ def setup_class(cls):
8386 assert iam_policy_management_service is not None
8487
8588 # Load the configuration
86- global config , example_account_id
89+ global config , example_account_id , example_target_account_id
8790 config = read_external_sources (IamPolicyManagementV1 .DEFAULT_SERVICE_NAME )
8891 example_account_id = config ['TEST_ACCOUNT_ID' ]
92+ example_target_account_id = config ['TEST_TARGET_ACCOUNT_ID' ]
8993
9094 print ('Setup complete.' )
9195
@@ -545,21 +549,31 @@ def test_create_policy_template_example(self):
545549 create_policy_template request example
546550 """
547551 try :
548- print ('\n create_policy_template () result:' )
552+ print ('\n create_policy_s2s_template () result:' )
549553 # begin-create_policy_template
550554
551555 v2_policy_resource_attribute_model = {
552- 'key' : 'serviceType ' ,
556+ 'key' : 'serviceName ' ,
553557 'operator' : 'stringEquals' ,
554- 'value' : 'service ' ,
558+ 'value' : 'cloud-object-storage ' ,
555559 }
556560
557561 v2_policy_resource_model = {
558562 'attributes' : [v2_policy_resource_attribute_model ],
559563 }
560564
565+ v2_policy_subject_attribute_model = {
566+ 'key' : 'serviceName' ,
567+ 'operator' : 'stringEquals' ,
568+ 'value' : 'compliance' ,
569+ }
570+
571+ v2_policy_subject_model = {
572+ 'attributes' : [v2_policy_subject_attribute_model ],
573+ }
574+
561575 roles_model = {
562- 'role_id' : 'crn:v1:bluemix:public:iam::::role:Viewer ' ,
576+ 'role_id' : 'crn:v1:bluemix:public:iam::::serviceRole:Writer ' ,
563577 }
564578
565579 grant_model = {
@@ -571,9 +585,10 @@ def test_create_policy_template_example(self):
571585 }
572586
573587 template_policy_model = {
574- 'type' : 'access ' ,
588+ 'type' : 'authorization ' ,
575589 'resource' : v2_policy_resource_model ,
576590 'control' : control_model ,
591+ 'subject' : v2_policy_subject_model ,
577592 }
578593
579594 response = iam_policy_management_service .create_policy_template (
@@ -585,8 +600,8 @@ def test_create_policy_template_example(self):
585600
586601 global example_template_id
587602 example_template_id = policy_template ['id' ]
588- global example_template_version
589- example_template_version = policy_template ['version' ]
603+ global example_basic_template_version
604+ example_basic_template_version = policy_template ['version' ]
590605
591606 print (json .dumps (policy_template , indent = 2 ))
592607
@@ -626,21 +641,31 @@ def test_replace_policy_template_example(self):
626641 replace_policy_template request example
627642 """
628643 try :
629- print ('\n replace_policy_template () result:' )
644+ print ('\n replace_policy_s2s_template () result:' )
630645 # begin-replace_policy_template
631646
632647 v2_policy_resource_attribute_model = {
633- 'key' : 'serviceType ' ,
648+ 'key' : 'serviceName ' ,
634649 'operator' : 'stringEquals' ,
635- 'value' : 'service ' ,
650+ 'value' : 'kms ' ,
636651 }
637652
638653 v2_policy_resource_model = {
639654 'attributes' : [v2_policy_resource_attribute_model ],
640655 }
641656
657+ v2_policy_subject_attribute_model = {
658+ 'key' : 'serviceName' ,
659+ 'operator' : 'stringEquals' ,
660+ 'value' : 'compliance' ,
661+ }
662+
663+ v2_policy_subject_model = {
664+ 'attributes' : [v2_policy_subject_attribute_model ],
665+ }
666+
642667 roles_model = {
643- 'role_id' : 'crn:v1:bluemix:public:iam::::role:Editor ' ,
668+ 'role_id' : 'crn:v1:bluemix:public:iam::::serviceRole:Reader ' ,
644669 }
645670
646671 grant_model = {
@@ -652,14 +677,15 @@ def test_replace_policy_template_example(self):
652677 }
653678
654679 template_policy_model = {
655- 'type' : 'access ' ,
680+ 'type' : 'authorization ' ,
656681 'resource' : v2_policy_resource_model ,
682+ 'subject' : v2_policy_subject_model ,
657683 'control' : control_model ,
658684 }
659685
660686 response = iam_policy_management_service .replace_policy_template (
661687 policy_template_id = example_template_id ,
662- version = example_template_version ,
688+ version = example_basic_template_version ,
663689 if_match = example_template_etag ,
664690 policy = template_policy_model ,
665691 )
@@ -703,17 +729,27 @@ def test_create_policy_template_version_example(self):
703729 # begin-create_policy_template_version
704730
705731 v2_policy_resource_attribute_model = {
706- 'key' : 'serviceType ' ,
732+ 'key' : 'serviceName ' ,
707733 'operator' : 'stringEquals' ,
708- 'value' : 'service ' ,
734+ 'value' : 'appid ' ,
709735 }
710736
711737 v2_policy_resource_model = {
712738 'attributes' : [v2_policy_resource_attribute_model ],
713739 }
714740
741+ v2_policy_subject_attribute_model = {
742+ 'key' : 'serviceName' ,
743+ 'operator' : 'stringEquals' ,
744+ 'value' : 'compliance' ,
745+ }
746+
747+ v2_policy_subject_model = {
748+ 'attributes' : [v2_policy_subject_attribute_model ],
749+ }
750+
715751 roles_model = {
716- 'role_id' : 'crn:v1:bluemix:public:iam::::role:Viewer ' ,
752+ 'role_id' : 'crn:v1:bluemix:public:iam::::serviceRole:Reader ' ,
717753 }
718754
719755 grant_model = {
@@ -725,17 +761,20 @@ def test_create_policy_template_version_example(self):
725761 }
726762
727763 template_policy_model = {
728- 'type' : 'access ' ,
764+ 'type' : 'authorization ' ,
729765 'resource' : v2_policy_resource_model ,
730766 'control' : control_model ,
767+ 'subject' : v2_policy_subject_model ,
731768 }
732769
733770 response = iam_policy_management_service .create_policy_template_version (
734771 policy_template_id = example_template_id ,
735772 policy = template_policy_model ,
773+ committed = True ,
736774 )
737775 policy_template = response .get_result ()
738-
776+ global example_template_version
777+ example_template_version = policy_template ['version' ]
739778 print (json .dumps (policy_template , indent = 2 ))
740779
741780 # end-create_policy_template_version
@@ -799,7 +838,7 @@ def test_commit_policy_template_example(self):
799838
800839 response = iam_policy_management_service .commit_policy_template (
801840 policy_template_id = example_template_id ,
802- version = example_template_version ,
841+ version = example_basic_template_version ,
803842 )
804843
805844 # end-commit_policy_template
@@ -808,6 +847,63 @@ def test_commit_policy_template_example(self):
808847 except ApiException as e :
809848 pytest .fail (str (e ))
810849
850+ @needscredentials
851+ def test_create_policy_assignment_example (self ):
852+ """
853+ create_policy_template_assignment request example
854+ """
855+ try :
856+ print ('\n create_policy_template_assignment() result:' )
857+ # begin-create_policy_template_assignment
858+ response = iam_policy_management_service .create_policy_template_assignment (
859+ version = "1.0" ,
860+ target = AssignmentTargetDetails (
861+ type = "Account" ,
862+ id = example_target_account_id ,
863+ ),
864+ options = PolicyAssignmentV1Options (
865+ root = PolicyAssignmentV1OptionsRoot (requester_id = "test_sdk" , assignment_id = "test" )
866+ ),
867+ templates = [AssignmentTemplateDetails (id = example_template_id , version = example_basic_template_version )],
868+ )
869+ result = response .get_result ()
870+ assert result is not None
871+
872+ global example_assignment_id
873+ example_assignment_id = result ['assignments' ][0 ]['id' ]
874+ global example_assignment_etag
875+ example_assignment_etag = response .get_headers ().get ("Etag" )
876+ print (json .dumps (result , indent = 2 ))
877+
878+ # end-create_policy_template_assignment
879+
880+ except ApiException as e :
881+ pytest .fail (str (e ))
882+
883+ @needscredentials
884+ def test_update_policy_assignment_example (self ):
885+ """
886+ update_policy_assignment request example
887+ """
888+ try :
889+ print ('\n update_policy_assignment() result:' )
890+ # begin-update_policy_assignment
891+
892+ response = iam_policy_management_service .update_policy_assignment (
893+ assignment_id = example_assignment_id ,
894+ version = "1.0" ,
895+ if_match = example_assignment_etag ,
896+ template_version = example_template_version ,
897+ )
898+ assignment = response .get_result ()
899+
900+ print (json .dumps (assignment , indent = 2 ))
901+
902+ # end-update_policy_assignment
903+
904+ except ApiException as e :
905+ pytest .fail (str (e ))
906+
811907 @needscredentials
812908 def test_list_policy_assignments_example (self ):
813909 """
@@ -819,12 +915,10 @@ def test_list_policy_assignments_example(self):
819915
820916 response = iam_policy_management_service .list_policy_assignments (
821917 account_id = example_account_id ,
918+ version = "1.0" ,
822919 )
823920 polcy_template_assignment_collection = response .get_result ()
824921
825- global example_assignment_id
826- example_assignment_id = polcy_template_assignment_collection ['assignments' ][0 ]['id' ]
827-
828922 print (json .dumps (polcy_template_assignment_collection , indent = 2 ))
829923
830924 # end-list_policy_assignments
@@ -843,6 +937,7 @@ def test_get_policy_assignment_example(self):
843937
844938 response = iam_policy_management_service .get_policy_assignment (
845939 assignment_id = example_assignment_id ,
940+ version = "1.0" ,
846941 )
847942 policy_assignment_record = response .get_result ()
848943
@@ -875,6 +970,24 @@ def test_get_v2_assignment_policy_example(self):
875970 except ApiException as e :
876971 pytest .fail (str (e ))
877972
973+ @needscredentials
974+ def test_delete_policy_assignment_example (self ):
975+ """
976+ delete_policy_assignment request example
977+ """
978+ try :
979+ # begin-delete_policy_assignment
980+
981+ response = iam_policy_management_service .delete_policy_assignment (
982+ assignment_id = example_assignment_id ,
983+ )
984+
985+ # end-delete_policy_assignment
986+ print ('\n delete_policy_assignment() response status code: ' , response .get_status_code ())
987+
988+ except ApiException as e :
989+ pytest .fail (str (e ))
990+
878991 @needscredentials
879992 def test_delete_policy_template_example (self ):
880993 """
0 commit comments