diff --git a/examples/test_iam_policy_management_v1_examples.py b/examples/test_iam_policy_management_v1_examples.py index adf19132..1f2ca74c 100644 --- a/examples/test_iam_policy_management_v1_examples.py +++ b/examples/test_iam_policy_management_v1_examples.py @@ -49,6 +49,10 @@ example_policy_etag = None example_custom_role_id = None example_custom_role_etag = None +example_template_id = None +example_template_etag = None +example_template_version = None +example_assignment_id = None example_user_id = "IBMid-user1" example_service_name = "iam-groups" @@ -543,6 +547,341 @@ def test_delete_role_example(self): except ApiException as e: pytest.fail(str(e)) + @needscredentials + def test_create_policy_template_example(self): + """ + create_policy_template request example + """ + try: + print('\ncreate_policy_template() result:') + + global example_template_id + global example_template_version + # begin-create_policy_template + + v2_policy_resource_attribute_model = { + 'key': 'serviceType', + 'operator': 'stringEquals', + 'value': 'service', + } + + v2_policy_resource_model = { + 'attributes': [v2_policy_resource_attribute_model], + } + + roles_model = { + 'role_id': 'crn:v1:bluemix:public:iam::::role:Viewer', + } + + grant_model = { + 'roles': [roles_model], + } + + control_model = { + 'grant': grant_model, + } + + template_policy_model = { + 'type': 'access', + 'resource': v2_policy_resource_model, + 'control': control_model, + } + + response = iam_policy_management_service.create_policy_template( + name='SDKExamplesTest', + account_id=example_account_id, + policy=template_policy_model, + ) + policy_template = response.get_result() + + print(json.dumps(policy_template, indent=2)) + + # end-create_policy_template + + example_template_id = policy_template['id'] + example_template_version = policy_template['version'] + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_policy_template_example(self): + """ + get_policy_template request example + """ + try: + print('\nget_policy_template() result:') + + global example_template_etag + # begin-get_policy_template + + print('example_template_id: ', example_template_id) + response = iam_policy_management_service.get_policy_template( + policy_template_id=example_template_id, + ) + policy_template = response.get_result() + + print(json.dumps(policy_template, indent=2)) + + # end-get_policy_template + + example_template_etag = response.get_headers().get("Etag") + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_replace_policy_template_example(self): + """ + replace_policy_template request example + """ + try: + print('\nreplace_policy_template() result:') + # begin-replace_policy_template + + v2_policy_resource_attribute_model = { + 'key': 'serviceType', + 'operator': 'stringEquals', + 'value': 'service', + } + + v2_policy_resource_model = { + 'attributes': [v2_policy_resource_attribute_model], + } + + roles_model = { + 'role_id': 'crn:v1:bluemix:public:iam::::role:Editor', + } + + grant_model = { + 'roles': [roles_model], + } + + control_model = { + 'grant': grant_model, + } + + template_policy_model = { + 'type': 'access', + 'resource': v2_policy_resource_model, + 'control': control_model, + } + + response = iam_policy_management_service.replace_policy_template( + policy_template_id=example_template_id, + version=example_template_version, + if_match=example_template_etag, + policy=template_policy_model, + ) + policy_template = response.get_result() + + print(json.dumps(policy_template, indent=2)) + + # end-replace_policy_template + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_policy_templates_example(self): + """ + list_policy_templates request example + """ + try: + print('\nlist_policy_templates() result:') + # begin-list_policy_templates + + response = iam_policy_management_service.list_policy_templates( + account_id=example_account_id, + ) + policy_template_collection = response.get_result() + + print(json.dumps(policy_template_collection, indent=2)) + + # end-list_policy_templates + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_policy_template_version_example(self): + """ + create_policy_template_version request example + """ + try: + print('\ncreate_policy_template_version() result:') + # begin-create_policy_template_version + + v2_policy_resource_attribute_model = { + 'key': 'serviceType', + 'operator': 'stringEquals', + 'value': 'service', + } + + v2_policy_resource_model = { + 'attributes': [v2_policy_resource_attribute_model], + } + + roles_model = { + 'role_id': 'crn:v1:bluemix:public:iam::::role:Viewer', + } + + grant_model = { + 'roles': [roles_model], + } + + control_model = { + 'grant': grant_model, + } + + template_policy_model = { + 'type': 'access', + 'resource': v2_policy_resource_model, + 'control': control_model, + } + + response = iam_policy_management_service.create_policy_template_version( + policy_template_id=example_template_id, + policy=template_policy_model, + ) + policy_template = response.get_result() + + print(json.dumps(policy_template, indent=2)) + + # end-create_policy_template_version + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_policy_template_versions_example(self): + """ + list_policy_template_versions request example + """ + try: + print('\nlist_policy_template_versions() result:') + # begin-list_policy_template_versions + + response = iam_policy_management_service.list_policy_template_versions( + policy_template_id=example_template_id, + ) + policy_template_versions_collection = response.get_result() + + print(json.dumps(policy_template_versions_collection, indent=2)) + + # end-list_policy_template_versions + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_policy_template_version_example(self): + """ + get_policy_template_version request example + """ + try: + print('\nget_policy_template_version() result:') + # begin-get_policy_template_version + + response = iam_policy_management_service.get_policy_template_version( + policy_template_id=example_template_id, + version=example_template_version, + ) + policy_template = response.get_result() + + print(json.dumps(policy_template, indent=2)) + + # end-get_policy_template_version + + example_template_etag = response.get_headers().get("Etag") + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_commit_policy_template_example(self): + """ + commit_policy_template request example + """ + try: + # begin-commit_policy_template + + response = iam_policy_management_service.commit_policy_template( + policy_template_id=example_template_id, + version=example_template_version, + if_match=example_template_etag, + ) + + # end-commit_policy_template + print('\ncommit_policy_template() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_policy_assignments_example(self): + """ + list_policy_assignments request example + """ + try: + print('\nlist_policy_assignments() result:') + + global example_assignment_id + # begin-list_Policy Assignments + + response = iam_policy_management_service.list_policy_assignments( + account_id=example_account_id, + ) + polcy_template_assignment_collection = response.get_result() + + print(json.dumps(polcy_template_assignment_collection, indent=2)) + + # end-list_Policy Assignments + + example_assignment_id = polcy_template_assignment_collection['assignments'][0]['id'] + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_policy_assignment_example(self): + """ + get_policy_assignment request example + """ + try: + print('\nget_policy_assignment() result:') + # begin-get_policy_assignment + + response = iam_policy_management_service.get_policy_assignment( + assignment_id=example_assignment_id, + ) + policy_assignment_record = response.get_result() + + print(json.dumps(policy_assignment_record, indent=2)) + + # end-get_policy_assignment + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_policy_template_example(self): + """ + delete_policy_template request example + """ + try: + # begin-delete_policy_template + + response = iam_policy_management_service.delete_policy_template( + policy_template_id=example_template_id, + ) + + # end-delete_policy_template + print('\ndelete_policy_template() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + # endregion ############################################################################## diff --git a/ibm_platform_services/iam_policy_management_v1.py b/ibm_platform_services/iam_policy_management_v1.py index 07fb473d..8884950b 100644 --- a/ibm_platform_services/iam_policy_management_v1.py +++ b/ibm_platform_services/iam_policy_management_v1.py @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# IBM OpenAPI SDK Code Generator Version: 3.68.2-ac7def68-20230310-195410 +# IBM OpenAPI SDK Code Generator Version: 3.71.0-316eb5da-20230504-195406 """ IAM Policy Management API @@ -90,7 +90,7 @@ def list_policies( sort: str = None, format: str = None, state: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Get policies by attributes. @@ -137,7 +137,7 @@ def list_policies( * `deleted` - returns non-active policies. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. - :rtype: DetailedResponse with `dict` result representing a `PolicyList` object + :rtype: DetailedResponse with `dict` result representing a `PolicyCollection` object """ if not account_id: @@ -146,7 +146,9 @@ def list_policies( 'Accept-Language': accept_language, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='list_policies' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_policies', ) headers.update(sdk_headers) @@ -169,7 +171,12 @@ def list_policies( headers['Accept'] = 'application/json' url = '/v1/policies' - request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) response = self.send(request, **kwargs) return response @@ -183,7 +190,7 @@ def create_policy( *, description: str = None, accept_language: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Create a policy. @@ -275,7 +282,9 @@ def create_policy( 'Accept-Language': accept_language, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='create_policy' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_policy', ) headers.update(sdk_headers) @@ -296,7 +305,12 @@ def create_policy( headers['Accept'] = 'application/json' url = '/v1/policies' - request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response @@ -311,7 +325,7 @@ def replace_policy( resources: List['PolicyResource'], *, description: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Update a policy. @@ -393,7 +407,9 @@ def replace_policy( 'If-Match': if_match, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='replace_policy' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='replace_policy', ) headers.update(sdk_headers) @@ -417,12 +433,21 @@ def replace_policy( path_param_values = self.encode_path_vars(policy_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/policies/{policy_id}'.format(**path_param_dict) - request = self.prepare_request(method='PUT', url=url, headers=headers, data=data) + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response - def get_policy(self, policy_id: str, **kwargs) -> DetailedResponse: + def get_policy( + self, + policy_id: str, + **kwargs, + ) -> DetailedResponse: """ Retrieve a policy by ID. @@ -438,7 +463,9 @@ def get_policy(self, policy_id: str, **kwargs) -> DetailedResponse: raise ValueError('policy_id must be provided') headers = {} sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='get_policy' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_policy', ) headers.update(sdk_headers) @@ -451,12 +478,20 @@ def get_policy(self, policy_id: str, **kwargs) -> DetailedResponse: path_param_values = self.encode_path_vars(policy_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/policies/{policy_id}'.format(**path_param_dict) - request = self.prepare_request(method='GET', url=url, headers=headers) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response - def delete_policy(self, policy_id: str, **kwargs) -> DetailedResponse: + def delete_policy( + self, + policy_id: str, + **kwargs, + ) -> DetailedResponse: """ Delete a policy by ID. @@ -474,7 +509,9 @@ def delete_policy(self, policy_id: str, **kwargs) -> DetailedResponse: raise ValueError('policy_id must be provided') headers = {} sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='delete_policy' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_policy', ) headers.update(sdk_headers) @@ -486,12 +523,23 @@ def delete_policy(self, policy_id: str, **kwargs) -> DetailedResponse: path_param_values = self.encode_path_vars(policy_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/policies/{policy_id}'.format(**path_param_dict) - request = self.prepare_request(method='DELETE', url=url, headers=headers) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response - def update_policy_state(self, policy_id: str, if_match: str, *, state: str = None, **kwargs) -> DetailedResponse: + def update_policy_state( + self, + policy_id: str, + if_match: str, + *, + state: str = None, + **kwargs, + ) -> DetailedResponse: """ Restore a deleted policy by ID. @@ -518,7 +566,9 @@ def update_policy_state(self, policy_id: str, if_match: str, *, state: str = Non 'If-Match': if_match, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='update_policy_state' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='update_policy_state', ) headers.update(sdk_headers) @@ -538,7 +588,12 @@ def update_policy_state(self, policy_id: str, if_match: str, *, state: str = Non path_param_values = self.encode_path_vars(policy_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/policies/{policy_id}'.format(**path_param_dict) - request = self.prepare_request(method='PATCH', url=url, headers=headers, data=data) + request = self.prepare_request( + method='PATCH', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response @@ -556,7 +611,7 @@ def list_roles( source_service_name: str = None, policy_type: str = None, service_group_id: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Get roles by filters. @@ -590,14 +645,16 @@ def list_roles( :param str service_group_id: (optional) Optional id of service group. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. - :rtype: DetailedResponse with `dict` result representing a `RoleList` object + :rtype: DetailedResponse with `dict` result representing a `RoleCollection` object """ headers = { 'Accept-Language': accept_language, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='list_roles' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_roles', ) headers.update(sdk_headers) @@ -615,7 +672,12 @@ def list_roles( headers['Accept'] = 'application/json' url = '/v2/roles' - request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) response = self.send(request, **kwargs) return response @@ -630,7 +692,7 @@ def create_role( *, description: str = None, accept_language: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Create a role. @@ -682,7 +744,9 @@ def create_role( 'Accept-Language': accept_language, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='create_role' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_role', ) headers.update(sdk_headers) @@ -704,13 +768,25 @@ def create_role( headers['Accept'] = 'application/json' url = '/v2/roles' - request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response def replace_role( - self, role_id: str, if_match: str, display_name: str, actions: List[str], *, description: str = None, **kwargs + self, + role_id: str, + if_match: str, + display_name: str, + actions: List[str], + *, + description: str = None, + **kwargs, ) -> DetailedResponse: """ Update a role. @@ -746,7 +822,9 @@ def replace_role( 'If-Match': if_match, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='replace_role' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='replace_role', ) headers.update(sdk_headers) @@ -768,12 +846,21 @@ def replace_role( path_param_values = self.encode_path_vars(role_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v2/roles/{role_id}'.format(**path_param_dict) - request = self.prepare_request(method='PUT', url=url, headers=headers, data=data) + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response - def get_role(self, role_id: str, **kwargs) -> DetailedResponse: + def get_role( + self, + role_id: str, + **kwargs, + ) -> DetailedResponse: """ Retrieve a role by ID. @@ -789,7 +876,9 @@ def get_role(self, role_id: str, **kwargs) -> DetailedResponse: raise ValueError('role_id must be provided') headers = {} sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='get_role' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_role', ) headers.update(sdk_headers) @@ -802,12 +891,20 @@ def get_role(self, role_id: str, **kwargs) -> DetailedResponse: path_param_values = self.encode_path_vars(role_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v2/roles/{role_id}'.format(**path_param_dict) - request = self.prepare_request(method='GET', url=url, headers=headers) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response - def delete_role(self, role_id: str, **kwargs) -> DetailedResponse: + def delete_role( + self, + role_id: str, + **kwargs, + ) -> DetailedResponse: """ Delete a role by ID. @@ -823,7 +920,9 @@ def delete_role(self, role_id: str, **kwargs) -> DetailedResponse: raise ValueError('role_id must be provided') headers = {} sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='delete_role' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_role', ) headers.update(sdk_headers) @@ -835,7 +934,11 @@ def delete_role(self, role_id: str, **kwargs) -> DetailedResponse: path_param_values = self.encode_path_vars(role_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v2/roles/{role_id}'.format(**path_param_dict) - request = self.prepare_request(method='DELETE', url=url, headers=headers) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response @@ -858,7 +961,7 @@ def list_v2_policies( sort: str = None, format: str = None, state: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Get policies by attributes. @@ -925,7 +1028,9 @@ def list_v2_policies( 'Accept-Language': accept_language, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='list_v2_policies' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_v2_policies', ) headers.update(sdk_headers) @@ -948,7 +1053,12 @@ def list_v2_policies( headers['Accept'] = 'application/json' url = '/v2/policies' - request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) response = self.send(request, **kwargs) return response @@ -964,7 +1074,7 @@ def create_v2_policy( pattern: str = None, rule: 'V2PolicyRule' = None, accept_language: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Create a policy. @@ -987,7 +1097,7 @@ def create_v2_policy( **`resourceGroupId`** or **`service_group_id`** attribute and the **`accountId`** attribute. In the rule field, you can specify a single condition by using **`key`**, **`value`**, and condition **`operator`**, or a set of **`conditions`** - with a combination **`operator`**. The possible combination operators are + with a combination **`operator`**. The possible combination operators are **`and`** and **`or`**. Combine conditions to specify a time-based restriction (e.g., access only during business hours, during the Monday-Friday work week). For example, a policy can grant access Monday-Friday, 9:00am-5:00pm using the @@ -1038,8 +1148,7 @@ def create_v2_policy( :param Control control: Specifies the type of access granted by the policy. :param str type: The policy type; either 'access' or 'authorization'. - :param str description: (optional) Allows the customer to use their own - words to record the purpose/context related to a policy. + :param str description: (optional) Description of the policy. :param V2PolicySubject subject: (optional) The subject attributes for whom the policy grants access. :param V2PolicyResource resource: (optional) The resource attributes to @@ -1081,7 +1190,9 @@ def create_v2_policy( 'Accept-Language': accept_language, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='create_v2_policy' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_v2_policy', ) headers.update(sdk_headers) @@ -1104,7 +1215,12 @@ def create_v2_policy( headers['Accept'] = 'application/json' url = '/v2/policies' - request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response @@ -1121,7 +1237,7 @@ def replace_v2_policy( resource: 'V2PolicyResource' = None, pattern: str = None, rule: 'V2PolicyRule' = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Update a policy. @@ -1142,7 +1258,7 @@ def replace_v2_policy( **`resourceGroupId`** or **`service_group_id`** attribute and the **`accountId`** attribute. In the rule field, you can specify a single condition by using **`key`**, **`value`**, and condition **`operator`**, or a set of **`conditions`** - with a combination **`operator`**. The possible combination operators are + with a combination **`operator`**. The possible combination operators are **`and`** and **`or`**. Combine conditions to specify a time-based restriction (e.g., access only during business hours, during the Monday-Friday work week). For example, a policy can grant access Monday-Friday, 9:00am-5:00pm using the @@ -1196,8 +1312,7 @@ def replace_v2_policy( header. :param Control control: Specifies the type of access granted by the policy. :param str type: The policy type; either 'access' or 'authorization'. - :param str description: (optional) Allows the customer to use their own - words to record the purpose/context related to a policy. + :param str description: (optional) Description of the policy. :param V2PolicySubject subject: (optional) The subject attributes for whom the policy grants access. :param V2PolicyResource resource: (optional) The resource attributes to @@ -1231,7 +1346,9 @@ def replace_v2_policy( 'If-Match': if_match, } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='replace_v2_policy' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='replace_v2_policy', ) headers.update(sdk_headers) @@ -1257,12 +1374,23 @@ def replace_v2_policy( path_param_values = self.encode_path_vars(id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v2/policies/{id}'.format(**path_param_dict) - request = self.prepare_request(method='PUT', url=url, headers=headers, data=data) + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response - def get_v2_policy(self, id: str, *, format: str = None, **kwargs) -> DetailedResponse: + def get_v2_policy( + self, + id: str, + *, + format: str = None, + **kwargs, + ) -> DetailedResponse: """ Retrieve a policy by ID. @@ -1283,7 +1411,9 @@ def get_v2_policy(self, id: str, *, format: str = None, **kwargs) -> DetailedRes raise ValueError('id must be provided') headers = {} sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='get_v2_policy' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_v2_policy', ) headers.update(sdk_headers) @@ -1300,12 +1430,21 @@ def get_v2_policy(self, id: str, *, format: str = None, **kwargs) -> DetailedRes path_param_values = self.encode_path_vars(id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v2/policies/{id}'.format(**path_param_dict) - request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) response = self.send(request, **kwargs) return response - def delete_v2_policy(self, id: str, **kwargs) -> DetailedResponse: + def delete_v2_policy( + self, + id: str, + **kwargs, + ) -> DetailedResponse: """ Delete a policy by ID. @@ -1323,7 +1462,9 @@ def delete_v2_policy(self, id: str, **kwargs) -> DetailedResponse: raise ValueError('id must be provided') headers = {} sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='delete_v2_policy' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_v2_policy', ) headers.update(sdk_headers) @@ -1335,176 +1476,2455 @@ def delete_v2_policy(self, id: str, **kwargs) -> DetailedResponse: path_param_values = self.encode_path_vars(id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v2/policies/{id}'.format(**path_param_dict) - request = self.prepare_request(method='DELETE', url=url, headers=headers) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response + ######################### + # Policy templates + ######################### -class ListPoliciesEnums: - """ - Enums for list_policies parameters. - """ - - class Type(str, Enum): - """ - Optional type of policy. + def list_policy_templates( + self, + account_id: str, + *, + accept_language: str = None, + **kwargs, + ) -> DetailedResponse: """ + List policy templates by attributes. - ACCESS = 'access' - AUTHORIZATION = 'authorization' + List policy templates and filter by attributes by using query parameters. The + following attributes are supported: `account_id`. + `account_id` is a required query parameter. Only policy templates that have the + specified attributes and that the caller has read access to are returned. If the + caller does not have read access to any policy templates an empty array is + returned. - class ServiceType(str, Enum): - """ - Optional type of service. + :param str account_id: The account GUID that the policy templates belong + to. + :param str accept_language: (optional) Language code for translations + * `default` - English + * `de` - German (Standard) + * `en` - English + * `es` - Spanish (Spain) + * `fr` - French (Standard) + * `it` - Italian (Standard) + * `ja` - Japanese + * `ko` - Korean + * `pt-br` - Portuguese (Brazil) + * `zh-cn` - Chinese (Simplified, PRC) + * `zh-tw` - (Chinese, Taiwan). + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PolicyTemplateCollection` object """ - SERVICE = 'service' - PLATFORM_SERVICE = 'platform_service' + if not account_id: + raise ValueError('account_id must be provided') + headers = { + 'Accept-Language': accept_language, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_policy_templates', + ) + headers.update(sdk_headers) - class Sort(str, Enum): - """ - Optional top level policy field to sort results. Ascending sort is default. - Descending sort available by prepending '-' to field. Example '-last_modified_at'. - """ + params = { + 'account_id': account_id, + } - ID = 'id' - TYPE = 'type' - HREF = 'href' - CREATED_AT = 'created_at' - CREATED_BY_ID = 'created_by_id' - LAST_MODIFIED_AT = 'last_modified_at' - LAST_MODIFIED_BY_ID = 'last_modified_by_id' - STATE = 'state' + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' - class Format(str, Enum): - """ - Include additional data per policy returned - * `include_last_permit` - returns details of when the policy last granted a permit - decision and the number of times it has done so - * `display` - returns the list of all actions included in each of the policy - roles. - """ + url = '/v1/policy_templates' + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) - INCLUDE_LAST_PERMIT = 'include_last_permit' - DISPLAY = 'display' + response = self.send(request, **kwargs) + return response - class State(str, Enum): + def create_policy_template( + self, + name: str, + account_id: str, + policy: 'TemplatePolicy', + *, + description: str = None, + committed: bool = None, + accept_language: str = None, + **kwargs, + ) -> DetailedResponse: """ - The state of the policy. - * `active` - returns active policies - * `deleted` - returns non-active policies. + Create a policy template. + + Create a policy template. Policy templates define a policy without requiring a + subject, and you can use them to grant access to multiple subjects. + + :param str name: Required field when creating a new template. Otherwise + this field is optional. If the field is included it will change the name + value for all existing versions of the template. + :param str account_id: Enterprise account ID where this template will be + created. + :param TemplatePolicy policy: The core set of properties associated with + the template's policy objet. + :param str description: (optional) Description of the policy template. This + is shown to users in the enterprise account. Use this to describe the + purpose or context of the policy for enterprise users managing IAM + templates. + :param bool committed: (optional) Committed status of the template. + :param str accept_language: (optional) Language code for translations + * `default` - English + * `de` - German (Standard) + * `en` - English + * `es` - Spanish (Spain) + * `fr` - French (Standard) + * `it` - Italian (Standard) + * `ja` - Japanese + * `ko` - Korean + * `pt-br` - Portuguese (Brazil) + * `zh-cn` - Chinese (Simplified, PRC) + * `zh-tw` - (Chinese, Taiwan). + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PolicyTemplate` object """ - ACTIVE = 'active' - DELETED = 'deleted' + if name is None: + raise ValueError('name must be provided') + if account_id is None: + raise ValueError('account_id must be provided') + if policy is None: + raise ValueError('policy must be provided') + policy = convert_model(policy) + headers = { + 'Accept-Language': accept_language, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_policy_template', + ) + headers.update(sdk_headers) + data = { + 'name': name, + 'account_id': account_id, + 'policy': policy, + 'description': description, + 'committed': committed, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' -class ListV2PoliciesEnums: - """ - Enums for list_v2_policies parameters. - """ + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' - class Type(str, Enum): - """ - Optional type of policy. - """ + url = '/v1/policy_templates' + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) - ACCESS = 'access' - AUTHORIZATION = 'authorization' + response = self.send(request, **kwargs) + return response - class ServiceType(str, Enum): - """ - Optional type of service. + def get_policy_template( + self, + policy_template_id: str, + **kwargs, + ) -> DetailedResponse: """ + Retrieve latest version of a policy template. - SERVICE = 'service' - PLATFORM_SERVICE = 'platform_service' + Retrieve the latest version of a policy template by providing a policy template + ID. - class Format(str, Enum): - """ - Include additional data per policy returned - * `include_last_permit` - returns details of when the policy last granted a permit - decision and the number of times it has done so - * `display` - returns the list of all actions included in each of the policy roles - and translations for all relevant fields. + :param str policy_template_id: The policy template ID. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PolicyTemplate` object """ - INCLUDE_LAST_PERMIT = 'include_last_permit' - DISPLAY = 'display' - - class State(str, Enum): - """ - The state of the policy. - * `active` - returns active policies - * `deleted` - returns non-active policies. - """ + if not policy_template_id: + raise ValueError('policy_template_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_policy_template', + ) + headers.update(sdk_headers) - ACTIVE = 'active' - DELETED = 'deleted' + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + path_param_keys = ['policy_template_id'] + path_param_values = self.encode_path_vars(policy_template_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/policy_templates/{policy_template_id}'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) -class GetV2PolicyEnums: - """ - Enums for get_v2_policy parameters. - """ + response = self.send(request, **kwargs) + return response - class Format(str, Enum): - """ - Include additional data for policy returned - * `include_last_permit` - returns details of when the policy last granted a permit - decision and the number of times it has done so - * `display` - returns the list of all actions included in each of the policy roles - and translations for all relevant fields. + def delete_policy_template( + self, + policy_template_id: str, + **kwargs, + ) -> DetailedResponse: """ + Delete a policy template. - INCLUDE_LAST_PERMIT = 'include_last_permit' - DISPLAY = 'display' + Delete a policy template by providing the policy template ID. This deletes all + versions of this template. A policy template can't be deleted if any version of + the template is assigned to one or more child accounts. You must remove the policy + assignments first. + :param str policy_template_id: The policy template ID. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ -############################################################################## -# Models -############################################################################## + if not policy_template_id: + raise ValueError('policy_template_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_policy_template', + ) + headers.update(sdk_headers) + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] -class Control: - """ - Specifies the type of access granted by the policy. + path_param_keys = ['policy_template_id'] + path_param_values = self.encode_path_vars(policy_template_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/policy_templates/{policy_template_id}'.format(**path_param_dict) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + def create_policy_template_version( + self, + policy_template_id: str, + policy: 'TemplatePolicy', + *, + description: str = None, + committed: bool = None, + **kwargs, + ) -> DetailedResponse: + """ + Create a new policy template version. + + Create a new version of a policy template. Use this if you need to make updates to + a policy template that is committed. + + :param str policy_template_id: The policy template ID. + :param TemplatePolicy policy: The core set of properties associated with + the template's policy objet. + :param str description: (optional) Description of the policy template. This + is shown to users in the enterprise account. Use this to describe the + purpose or context of the policy for enterprise users managing IAM + templates. + :param bool committed: (optional) Committed status of the template version. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PolicyTemplate` object + """ + + if not policy_template_id: + raise ValueError('policy_template_id must be provided') + if policy is None: + raise ValueError('policy must be provided') + policy = convert_model(policy) + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_policy_template_version', + ) + headers.update(sdk_headers) + + data = { + 'policy': policy, + 'description': description, + 'committed': committed, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['policy_template_id'] + path_param_values = self.encode_path_vars(policy_template_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/policy_templates/{policy_template_id}/versions'.format(**path_param_dict) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) + + response = self.send(request, **kwargs) + return response + + def list_policy_template_versions( + self, + policy_template_id: str, + **kwargs, + ) -> DetailedResponse: + """ + Retrieve policy template versions. + + Retrieve the versions of a policy template by providing a policy template ID. + + :param str policy_template_id: The policy template ID. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PolicyTemplateVersionsCollection` object + """ + + if not policy_template_id: + raise ValueError('policy_template_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_policy_template_versions', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['policy_template_id'] + path_param_values = self.encode_path_vars(policy_template_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/policy_templates/{policy_template_id}/versions'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + def replace_policy_template( + self, + policy_template_id: str, + version: str, + if_match: str, + policy: 'TemplatePolicy', + *, + description: str = None, + committed: bool = None, + **kwargs, + ) -> DetailedResponse: + """ + Update a policy template version. + + Update a specific version of a policy template. You can use this only if the + version isn't committed. + + :param str policy_template_id: The policy template ID. + :param str version: The policy template version. + :param str if_match: The revision number for updating a policy template + version and must match the ETag value of the existing policy template + version. The Etag can be retrieved using the GET + /v1/policy_templates/{policy_template_id}/versions/{version} API and + looking at the ETag response header. + :param TemplatePolicy policy: The core set of properties associated with + the template's policy objet. + :param str description: (optional) Description of the policy template. This + is shown to users in the enterprise account. Use this to describe the + purpose or context of the policy for enterprise users managing IAM + templates. + :param bool committed: (optional) Committed status of the template version. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PolicyTemplate` object + """ + + if not policy_template_id: + raise ValueError('policy_template_id must be provided') + if not version: + raise ValueError('version must be provided') + if not if_match: + raise ValueError('if_match must be provided') + if policy is None: + raise ValueError('policy must be provided') + policy = convert_model(policy) + headers = { + 'If-Match': if_match, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='replace_policy_template', + ) + headers.update(sdk_headers) + + data = { + 'policy': policy, + 'description': description, + 'committed': committed, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['policy_template_id', 'version'] + path_param_values = self.encode_path_vars(policy_template_id, version) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/policy_templates/{policy_template_id}/versions/{version}'.format(**path_param_dict) + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + data=data, + ) + + response = self.send(request, **kwargs) + return response + + def delete_policy_template_version( + self, + policy_template_id: str, + version: str, + **kwargs, + ) -> DetailedResponse: + """ + Delete a policy template version. + + Delete a specific version of a policy template by providing a policy template ID + and version number. You can't delete a policy template version that is assigned to + one or more child accounts. You must remove the policy assignments first. + + :param str policy_template_id: The policy template ID. + :param str version: The policy template version. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not policy_template_id: + raise ValueError('policy_template_id must be provided') + if not version: + raise ValueError('version must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_policy_template_version', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['policy_template_id', 'version'] + path_param_values = self.encode_path_vars(policy_template_id, version) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/policy_templates/{policy_template_id}/versions/{version}'.format(**path_param_dict) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + def get_policy_template_version( + self, + policy_template_id: str, + version: str, + **kwargs, + ) -> DetailedResponse: + """ + Retrieve a policy template version. + + Retrieve a policy template by providing a policy template ID and version number. + + :param str policy_template_id: The policy template ID. + :param str version: The policy template version. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PolicyTemplate` object + """ + + if not policy_template_id: + raise ValueError('policy_template_id must be provided') + if not version: + raise ValueError('version must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_policy_template_version', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['policy_template_id', 'version'] + path_param_values = self.encode_path_vars(policy_template_id, version) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/policy_templates/{policy_template_id}/versions/{version}'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + def commit_policy_template( + self, + policy_template_id: str, + version: str, + if_match: str, + **kwargs, + ) -> DetailedResponse: + """ + Commit a policy template version. + + Commit a policy template version. You can make no further changes to the policy + template once it's committed. If you need to make updates after committing a + version, create a new version. + + :param str policy_template_id: The policy template ID. + :param str version: The policy template version. + :param str if_match: The revision number for updating a policy template + version and must match the ETag value of the existing policy template + version. The Etag can be retrieved using the GET + /v1/policy_templates/{policy_template_id}/versions/{version} API and + looking at the ETag response header. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not policy_template_id: + raise ValueError('policy_template_id must be provided') + if not version: + raise ValueError('version must be provided') + if not if_match: + raise ValueError('if_match must be provided') + headers = { + 'If-Match': if_match, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='commit_policy_template', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['policy_template_id', 'version'] + path_param_values = self.encode_path_vars(policy_template_id, version) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/policy_templates/{policy_template_id}/versions/{version}/commit'.format(**path_param_dict) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + ######################### + # Policy assignments + ######################### + + def list_policy_assignments( + self, + account_id: str, + *, + accept_language: str = None, + template_id: str = None, + template_version: str = None, + **kwargs, + ) -> DetailedResponse: + """ + Get policy template assignments. + + Get policy template assignments by attributes. The following attributes are + supported: + `account_id`, `template_id`, `template_version`, `sort`. + `account_id` is a required query parameter. Only policy template assignments that + have the specified attributes and that the caller has read access to are returned. + If the caller does not have read access to any policy template assignments an + empty array is returned. + + :param str account_id: The account GUID in which the policies belong to. + :param str accept_language: (optional) Language code for translations + * `default` - English + * `de` - German (Standard) + * `en` - English + * `es` - Spanish (Spain) + * `fr` - French (Standard) + * `it` - Italian (Standard) + * `ja` - Japanese + * `ko` - Korean + * `pt-br` - Portuguese (Brazil) + * `zh-cn` - Chinese (Simplified, PRC) + * `zh-tw` - (Chinese, Taiwan). + :param str template_id: (optional) Optional template id. + :param str template_version: (optional) Optional policy template version. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PolicyTemplateAssignmentCollection` object + """ + + if not account_id: + raise ValueError('account_id must be provided') + headers = { + 'Accept-Language': accept_language, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_policy_assignments', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + 'template_id': template_id, + 'template_version': template_version, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/v1/policy_assignments' + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) + + response = self.send(request, **kwargs) + return response + + def get_policy_assignment( + self, + assignment_id: str, + **kwargs, + ) -> DetailedResponse: + """ + Retrieve a policy assignment. + + Retrieve a policy template assignment by providing a policy assignment ID. + + :param str assignment_id: The policy template assignment ID. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PolicyAssignment` object + """ + + if not assignment_id: + raise ValueError('assignment_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_policy_assignment', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['assignment_id'] + path_param_values = self.encode_path_vars(assignment_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/policy_assignments/{assignment_id}'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + +class ListPoliciesEnums: + """ + Enums for list_policies parameters. + """ + + class Type(str, Enum): + """ + Optional type of policy. + """ + + ACCESS = 'access' + AUTHORIZATION = 'authorization' + + class ServiceType(str, Enum): + """ + Optional type of service. + """ + + SERVICE = 'service' + PLATFORM_SERVICE = 'platform_service' + + class Sort(str, Enum): + """ + Optional top level policy field to sort results. Ascending sort is default. + Descending sort available by prepending '-' to field. Example '-last_modified_at'. + """ + + ID = 'id' + TYPE = 'type' + HREF = 'href' + CREATED_AT = 'created_at' + CREATED_BY_ID = 'created_by_id' + LAST_MODIFIED_AT = 'last_modified_at' + LAST_MODIFIED_BY_ID = 'last_modified_by_id' + STATE = 'state' + + class Format(str, Enum): + """ + Include additional data per policy returned + * `include_last_permit` - returns details of when the policy last granted a permit + decision and the number of times it has done so + * `display` - returns the list of all actions included in each of the policy + roles. + """ + + INCLUDE_LAST_PERMIT = 'include_last_permit' + DISPLAY = 'display' + + class State(str, Enum): + """ + The state of the policy. + * `active` - returns active policies + * `deleted` - returns non-active policies. + """ + + ACTIVE = 'active' + DELETED = 'deleted' + + +class ListV2PoliciesEnums: + """ + Enums for list_v2_policies parameters. + """ + + class Type(str, Enum): + """ + Optional type of policy. + """ + + ACCESS = 'access' + AUTHORIZATION = 'authorization' + + class ServiceType(str, Enum): + """ + Optional type of service. + """ + + SERVICE = 'service' + PLATFORM_SERVICE = 'platform_service' + + class Format(str, Enum): + """ + Include additional data per policy returned + * `include_last_permit` - returns details of when the policy last granted a permit + decision and the number of times it has done so + * `display` - returns the list of all actions included in each of the policy roles + and translations for all relevant fields. + """ + + INCLUDE_LAST_PERMIT = 'include_last_permit' + DISPLAY = 'display' + + class State(str, Enum): + """ + The state of the policy. + * `active` - returns active policies + * `deleted` - returns non-active policies. + """ + + ACTIVE = 'active' + DELETED = 'deleted' + + +class GetV2PolicyEnums: + """ + Enums for get_v2_policy parameters. + """ + + class Format(str, Enum): + """ + Include additional data for policy returned + * `include_last_permit` - returns details of when the policy last granted a permit + decision and the number of times it has done so + * `display` - returns the list of all actions included in each of the policy roles + and translations for all relevant fields. + """ + + INCLUDE_LAST_PERMIT = 'include_last_permit' + DISPLAY = 'display' + + +############################################################################## +# Models +############################################################################## + + +class AssignmentResourceCreated: + """ + On success, includes the policy assigned. + + :attr str id: (optional) policy id. + """ + + def __init__( + self, + *, + id: str = None, + ) -> None: + """ + Initialize a AssignmentResourceCreated object. + + :param str id: (optional) policy id. + """ + self.id = id + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AssignmentResourceCreated': + """Initialize a AssignmentResourceCreated object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AssignmentResourceCreated object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AssignmentResourceCreated object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AssignmentResourceCreated') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AssignmentResourceCreated') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class ConflictsWith: + """ + Details of conflicting resource. + + :attr str etag: (optional) The revision number of the resource. + :attr str role: (optional) The conflicting role id. + :attr str policy: (optional) The conflicting policy id. + """ + + def __init__( + self, + *, + etag: str = None, + role: str = None, + policy: str = None, + ) -> None: + """ + Initialize a ConflictsWith object. + + :param str etag: (optional) The revision number of the resource. + :param str role: (optional) The conflicting role id. + :param str policy: (optional) The conflicting policy id. + """ + self.etag = etag + self.role = role + self.policy = policy + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ConflictsWith': + """Initialize a ConflictsWith object from a json dictionary.""" + args = {} + if 'etag' in _dict: + args['etag'] = _dict.get('etag') + if 'role' in _dict: + args['role'] = _dict.get('role') + if 'policy' in _dict: + args['policy'] = _dict.get('policy') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ConflictsWith object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'etag') and self.etag is not None: + _dict['etag'] = self.etag + if hasattr(self, 'role') and self.role is not None: + _dict['role'] = self.role + if hasattr(self, 'policy') and self.policy is not None: + _dict['policy'] = self.policy + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ConflictsWith object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ConflictsWith') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ConflictsWith') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class Control: + """ + Specifies the type of access granted by the policy. + + :attr Grant grant: Permission granted by the policy. + """ + + def __init__( + self, + grant: 'Grant', + ) -> None: + """ + Initialize a Control object. + + :param Grant grant: Permission granted by the policy. + """ + self.grant = grant + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Control': + """Initialize a Control object from a json dictionary.""" + args = {} + if 'grant' in _dict: + args['grant'] = Grant.from_dict(_dict.get('grant')) + else: + raise ValueError('Required property \'grant\' not present in Control JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Control object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'grant') and self.grant is not None: + if isinstance(self.grant, dict): + _dict['grant'] = self.grant + else: + _dict['grant'] = self.grant.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Control object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Control') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Control') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class ControlResponse: + """ + ControlResponse. + + """ + + def __init__( + self, + ) -> None: + """ + Initialize a ControlResponse object. + + """ + msg = "Cannot instantiate base class. Instead, instantiate one of the defined subclasses: {0}".format( + ", ".join(['ControlResponseControl', 'ControlResponseControlWithEnrichedRoles']) + ) + raise Exception(msg) + + +class CustomRole: + """ + An additional set of properties associated with a role. + + :attr str id: (optional) The role ID. Composed of hexadecimal characters. + :attr str display_name: The display name of the role that is shown in the + console. + :attr str description: (optional) The description of the role. + :attr List[str] actions: The actions of the role. For more information, see [IAM + roles and + actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + :attr str crn: (optional) The role Cloud Resource Name (CRN). Example CRN: + 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. + :attr str name: The name of the role that is used in the CRN. Can only be + alphanumeric and has to be capitalized. + :attr str account_id: The account GUID. + :attr str service_name: The service name. + :attr datetime created_at: (optional) The UTC timestamp when the role was + created. + :attr str created_by_id: (optional) The iam ID of the entity that created the + role. + :attr datetime last_modified_at: (optional) The UTC timestamp when the role was + last modified. + :attr str last_modified_by_id: (optional) The iam ID of the entity that last + modified the policy. + :attr str href: (optional) The href link back to the role. + """ + + def __init__( + self, + display_name: str, + actions: List[str], + name: str, + account_id: str, + service_name: str, + *, + id: str = None, + description: str = None, + crn: str = None, + created_at: datetime = None, + created_by_id: str = None, + last_modified_at: datetime = None, + last_modified_by_id: str = None, + href: str = None, + ) -> None: + """ + Initialize a CustomRole object. + + :param str display_name: The display name of the role that is shown in the + console. + :param List[str] actions: The actions of the role. For more information, + see [IAM roles and + actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + :param str name: The name of the role that is used in the CRN. Can only be + alphanumeric and has to be capitalized. + :param str account_id: The account GUID. + :param str service_name: The service name. + :param str description: (optional) The description of the role. + """ + self.id = id + self.display_name = display_name + self.description = description + self.actions = actions + self.crn = crn + self.name = name + self.account_id = account_id + self.service_name = service_name + self.created_at = created_at + self.created_by_id = created_by_id + self.last_modified_at = last_modified_at + self.last_modified_by_id = last_modified_by_id + self.href = href + + @classmethod + def from_dict(cls, _dict: Dict) -> 'CustomRole': + """Initialize a CustomRole object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + if 'display_name' in _dict: + args['display_name'] = _dict.get('display_name') + else: + raise ValueError('Required property \'display_name\' not present in CustomRole JSON') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'actions' in _dict: + args['actions'] = _dict.get('actions') + else: + raise ValueError('Required property \'actions\' not present in CustomRole JSON') + if 'crn' in _dict: + args['crn'] = _dict.get('crn') + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in CustomRole JSON') + if 'account_id' in _dict: + args['account_id'] = _dict.get('account_id') + else: + raise ValueError('Required property \'account_id\' not present in CustomRole JSON') + if 'service_name' in _dict: + args['service_name'] = _dict.get('service_name') + else: + raise ValueError('Required property \'service_name\' not present in CustomRole JSON') + if 'created_at' in _dict: + args['created_at'] = string_to_datetime(_dict.get('created_at')) + if 'created_by_id' in _dict: + args['created_by_id'] = _dict.get('created_by_id') + if 'last_modified_at' in _dict: + args['last_modified_at'] = string_to_datetime(_dict.get('last_modified_at')) + if 'last_modified_by_id' in _dict: + args['last_modified_by_id'] = _dict.get('last_modified_by_id') + if 'href' in _dict: + args['href'] = _dict.get('href') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a CustomRole object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and getattr(self, 'id') is not None: + _dict['id'] = getattr(self, 'id') + if hasattr(self, 'display_name') and self.display_name is not None: + _dict['display_name'] = self.display_name + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'actions') and self.actions is not None: + _dict['actions'] = self.actions + if hasattr(self, 'crn') and getattr(self, 'crn') is not None: + _dict['crn'] = getattr(self, 'crn') + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'account_id') and self.account_id is not None: + _dict['account_id'] = self.account_id + if hasattr(self, 'service_name') and self.service_name is not None: + _dict['service_name'] = self.service_name + if hasattr(self, 'created_at') and getattr(self, 'created_at') is not None: + _dict['created_at'] = datetime_to_string(getattr(self, 'created_at')) + if hasattr(self, 'created_by_id') and getattr(self, 'created_by_id') is not None: + _dict['created_by_id'] = getattr(self, 'created_by_id') + if hasattr(self, 'last_modified_at') and getattr(self, 'last_modified_at') is not None: + _dict['last_modified_at'] = datetime_to_string(getattr(self, 'last_modified_at')) + if hasattr(self, 'last_modified_by_id') and getattr(self, 'last_modified_by_id') is not None: + _dict['last_modified_by_id'] = getattr(self, 'last_modified_by_id') + if hasattr(self, 'href') and getattr(self, 'href') is not None: + _dict['href'] = getattr(self, 'href') + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this CustomRole object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'CustomRole') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'CustomRole') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class EnrichedRoles: + """ + A role associated with a policy with additional information (display_name, + description, actions) when `format=display`. + + :attr str role_id: The role Cloud Resource Name (CRN) granted by the policy. + Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. + :attr str display_name: (optional) The service defined (or user defined if a + custom role) display name of the role. + :attr str description: (optional) The service defined (or user defined if a + custom role) description of the role. + :attr List[RoleAction] actions: The actions of the role. For more information, + see [IAM roles and + actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + """ + + def __init__( + self, + role_id: str, + actions: List['RoleAction'], + *, + display_name: str = None, + description: str = None, + ) -> None: + """ + Initialize a EnrichedRoles object. + + :param str role_id: The role Cloud Resource Name (CRN) granted by the + policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. + :param List[RoleAction] actions: The actions of the role. For more + information, see [IAM roles and + actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + """ + self.role_id = role_id + self.display_name = display_name + self.description = description + self.actions = actions + + @classmethod + def from_dict(cls, _dict: Dict) -> 'EnrichedRoles': + """Initialize a EnrichedRoles object from a json dictionary.""" + args = {} + if 'role_id' in _dict: + args['role_id'] = _dict.get('role_id') + else: + raise ValueError('Required property \'role_id\' not present in EnrichedRoles JSON') + if 'display_name' in _dict: + args['display_name'] = _dict.get('display_name') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'actions' in _dict: + args['actions'] = [RoleAction.from_dict(v) for v in _dict.get('actions')] + else: + raise ValueError('Required property \'actions\' not present in EnrichedRoles JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a EnrichedRoles object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'role_id') and self.role_id is not None: + _dict['role_id'] = self.role_id + if hasattr(self, 'display_name') and getattr(self, 'display_name') is not None: + _dict['display_name'] = getattr(self, 'display_name') + if hasattr(self, 'description') and getattr(self, 'description') is not None: + _dict['description'] = getattr(self, 'description') + if hasattr(self, 'actions') and self.actions is not None: + actions_list = [] + for v in self.actions: + if isinstance(v, dict): + actions_list.append(v) + else: + actions_list.append(v.to_dict()) + _dict['actions'] = actions_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this EnrichedRoles object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'EnrichedRoles') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'EnrichedRoles') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class ErrorDetails: + """ + Additional error details. + + :attr ConflictsWith conflicts_with: (optional) Details of conflicting resource. + """ + + def __init__( + self, + *, + conflicts_with: 'ConflictsWith' = None, + ) -> None: + """ + Initialize a ErrorDetails object. + + :param ConflictsWith conflicts_with: (optional) Details of conflicting + resource. + """ + self.conflicts_with = conflicts_with + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ErrorDetails': + """Initialize a ErrorDetails object from a json dictionary.""" + args = {} + if 'conflicts_with' in _dict: + args['conflicts_with'] = ConflictsWith.from_dict(_dict.get('conflicts_with')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ErrorDetails object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'conflicts_with') and self.conflicts_with is not None: + if isinstance(self.conflicts_with, dict): + _dict['conflicts_with'] = self.conflicts_with + else: + _dict['conflicts_with'] = self.conflicts_with.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ErrorDetails object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ErrorDetails') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ErrorDetails') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class ErrorObject: + """ + ErrorObject. + + :attr str code: The API error code for the error. + :attr str message: The error message returned by the API. + :attr ErrorDetails details: (optional) Additional error details. + :attr str more_info: (optional) Additional info for error. + """ + + def __init__( + self, + code: str, + message: str, + *, + details: 'ErrorDetails' = None, + more_info: str = None, + ) -> None: + """ + Initialize a ErrorObject object. + + :param str code: The API error code for the error. + :param str message: The error message returned by the API. + :param ErrorDetails details: (optional) Additional error details. + :param str more_info: (optional) Additional info for error. + """ + self.code = code + self.message = message + self.details = details + self.more_info = more_info + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ErrorObject': + """Initialize a ErrorObject object from a json dictionary.""" + args = {} + if 'code' in _dict: + args['code'] = _dict.get('code') + else: + raise ValueError('Required property \'code\' not present in ErrorObject JSON') + if 'message' in _dict: + args['message'] = _dict.get('message') + else: + raise ValueError('Required property \'message\' not present in ErrorObject JSON') + if 'details' in _dict: + args['details'] = ErrorDetails.from_dict(_dict.get('details')) + if 'more_info' in _dict: + args['more_info'] = _dict.get('more_info') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ErrorObject object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'code') and self.code is not None: + _dict['code'] = self.code + if hasattr(self, 'message') and self.message is not None: + _dict['message'] = self.message + if hasattr(self, 'details') and self.details is not None: + if isinstance(self.details, dict): + _dict['details'] = self.details + else: + _dict['details'] = self.details.to_dict() + if hasattr(self, 'more_info') and self.more_info is not None: + _dict['more_info'] = self.more_info + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ErrorObject object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ErrorObject') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ErrorObject') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class CodeEnum(str, Enum): + """ + The API error code for the error. + """ + + INSUFFICENT_PERMISSIONS = 'insufficent_permissions' + INVALID_BODY = 'invalid_body' + INVALID_TOKEN = 'invalid_token' + MISSING_REQUIRED_QUERY_PARAMETER = 'missing_required_query_parameter' + NOT_FOUND = 'not_found' + POLICY_CONFLICT_ERROR = 'policy_conflict_error' + POLICY_NOT_FOUND = 'policy_not_found' + REQUEST_NOT_PROCESSED = 'request_not_processed' + ROLE_CONFLICT_ERROR = 'role_conflict_error' + ROLE_NOT_FOUND = 'role_not_found' + TOO_MANY_REQUESTS = 'too_many_requests' + UNABLE_TO_PROCESS = 'unable_to_process' + UNSUPPORTED_CONTENT_TYPE = 'unsupported_content_type' + POLICY_TEMPLATE_CONFLICT_ERROR = 'policy_template_conflict_error' + POLICY_TEMPLATE_NOT_FOUND = 'policy_template_not_found' + POLICY_ASSIGNMENT_NOT_FOUND = 'policy_assignment_not_found' + POLICY_ASSIGNMENT_CONFLICT_ERROR = 'policy_assignment_conflict_error' + + +class ErrorResponse: + """ + The error response from API. + + :attr str trace: (optional) The unique transaction id for the request. + :attr List[ErrorObject] errors: (optional) The errors encountered during the + response. + :attr int status_code: (optional) The http error code of the response. + """ + + def __init__( + self, + *, + trace: str = None, + errors: List['ErrorObject'] = None, + status_code: int = None, + ) -> None: + """ + Initialize a ErrorResponse object. + + :param str trace: (optional) The unique transaction id for the request. + :param List[ErrorObject] errors: (optional) The errors encountered during + the response. + :param int status_code: (optional) The http error code of the response. + """ + self.trace = trace + self.errors = errors + self.status_code = status_code + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ErrorResponse': + """Initialize a ErrorResponse object from a json dictionary.""" + args = {} + if 'trace' in _dict: + args['trace'] = _dict.get('trace') + if 'errors' in _dict: + args['errors'] = [ErrorObject.from_dict(v) for v in _dict.get('errors')] + if 'status_code' in _dict: + args['status_code'] = _dict.get('status_code') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ErrorResponse object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'trace') and self.trace is not None: + _dict['trace'] = self.trace + if hasattr(self, 'errors') and self.errors is not None: + errors_list = [] + for v in self.errors: + if isinstance(v, dict): + errors_list.append(v) + else: + errors_list.append(v.to_dict()) + _dict['errors'] = errors_list + if hasattr(self, 'status_code') and self.status_code is not None: + _dict['status_code'] = self.status_code + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ErrorResponse object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ErrorResponse') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ErrorResponse') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class Grant: + """ + Permission granted by the policy. + + :attr List[Roles] roles: A set of role cloud resource names (CRNs) granted by + the policy. + """ + + def __init__( + self, + roles: List['Roles'], + ) -> None: + """ + Initialize a Grant object. + + :param List[Roles] roles: A set of role cloud resource names (CRNs) granted + by the policy. + """ + self.roles = roles + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Grant': + """Initialize a Grant object from a json dictionary.""" + args = {} + if 'roles' in _dict: + args['roles'] = [Roles.from_dict(v) for v in _dict.get('roles')] + else: + raise ValueError('Required property \'roles\' not present in Grant JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Grant object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'roles') and self.roles is not None: + roles_list = [] + for v in self.roles: + if isinstance(v, dict): + roles_list.append(v) + else: + roles_list.append(v.to_dict()) + _dict['roles'] = roles_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Grant object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Grant') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Grant') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class GrantWithEnrichedRoles: + """ + Permission granted by the policy with translated roles and additional role + information. + + :attr List[EnrichedRoles] roles: A set of roles granted by the policy. + """ + + def __init__( + self, + roles: List['EnrichedRoles'], + ) -> None: + """ + Initialize a GrantWithEnrichedRoles object. + + :param List[EnrichedRoles] roles: A set of roles granted by the policy. + """ + self.roles = roles + + @classmethod + def from_dict(cls, _dict: Dict) -> 'GrantWithEnrichedRoles': + """Initialize a GrantWithEnrichedRoles object from a json dictionary.""" + args = {} + if 'roles' in _dict: + args['roles'] = [EnrichedRoles.from_dict(v) for v in _dict.get('roles')] + else: + raise ValueError('Required property \'roles\' not present in GrantWithEnrichedRoles JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a GrantWithEnrichedRoles object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'roles') and self.roles is not None: + roles_list = [] + for v in self.roles: + if isinstance(v, dict): + roles_list.append(v) + else: + roles_list.append(v.to_dict()) + _dict['roles'] = roles_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this GrantWithEnrichedRoles object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'GrantWithEnrichedRoles') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'GrantWithEnrichedRoles') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class Policy: + """ + The core set of properties associated with a policy. + + :attr str id: (optional) The policy ID. + :attr str type: The policy type; either 'access' or 'authorization'. + :attr str description: (optional) Customer-defined description. + :attr List[PolicySubject] subjects: The subjects associated with a policy. + :attr List[PolicyRole] roles: A set of role cloud resource names (CRNs) granted + by the policy. + :attr List[PolicyResource] resources: The resources associated with a policy. + :attr str href: (optional) The href link back to the policy. + :attr datetime created_at: (optional) The UTC timestamp when the policy was + created. + :attr str created_by_id: (optional) The iam ID of the entity that created the + policy. + :attr datetime last_modified_at: (optional) The UTC timestamp when the policy + was last modified. + :attr str last_modified_by_id: (optional) The iam ID of the entity that last + modified the policy. + :attr str state: (optional) The policy state. + :attr TemplateMetadata template: (optional) Origin Template information. + """ + + def __init__( + self, + type: str, + subjects: List['PolicySubject'], + roles: List['PolicyRole'], + resources: List['PolicyResource'], + *, + id: str = None, + description: str = None, + href: str = None, + created_at: datetime = None, + created_by_id: str = None, + last_modified_at: datetime = None, + last_modified_by_id: str = None, + state: str = None, + template: 'TemplateMetadata' = None, + ) -> None: + """ + Initialize a Policy object. + + :param str type: The policy type; either 'access' or 'authorization'. + :param List[PolicySubject] subjects: The subjects associated with a policy. + :param List[PolicyRole] roles: A set of role cloud resource names (CRNs) + granted by the policy. + :param List[PolicyResource] resources: The resources associated with a + policy. + :param str description: (optional) Customer-defined description. + :param str state: (optional) The policy state. + :param TemplateMetadata template: (optional) Origin Template information. + """ + self.id = id + self.type = type + self.description = description + self.subjects = subjects + self.roles = roles + self.resources = resources + self.href = href + self.created_at = created_at + self.created_by_id = created_by_id + self.last_modified_at = last_modified_at + self.last_modified_by_id = last_modified_by_id + self.state = state + self.template = template + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Policy': + """Initialize a Policy object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + if 'type' in _dict: + args['type'] = _dict.get('type') + else: + raise ValueError('Required property \'type\' not present in Policy JSON') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'subjects' in _dict: + args['subjects'] = [PolicySubject.from_dict(v) for v in _dict.get('subjects')] + else: + raise ValueError('Required property \'subjects\' not present in Policy JSON') + if 'roles' in _dict: + args['roles'] = [PolicyRole.from_dict(v) for v in _dict.get('roles')] + else: + raise ValueError('Required property \'roles\' not present in Policy JSON') + if 'resources' in _dict: + args['resources'] = [PolicyResource.from_dict(v) for v in _dict.get('resources')] + else: + raise ValueError('Required property \'resources\' not present in Policy JSON') + if 'href' in _dict: + args['href'] = _dict.get('href') + if 'created_at' in _dict: + args['created_at'] = string_to_datetime(_dict.get('created_at')) + if 'created_by_id' in _dict: + args['created_by_id'] = _dict.get('created_by_id') + if 'last_modified_at' in _dict: + args['last_modified_at'] = string_to_datetime(_dict.get('last_modified_at')) + if 'last_modified_by_id' in _dict: + args['last_modified_by_id'] = _dict.get('last_modified_by_id') + if 'state' in _dict: + args['state'] = _dict.get('state') + if 'template' in _dict: + args['template'] = TemplateMetadata.from_dict(_dict.get('template')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Policy object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and getattr(self, 'id') is not None: + _dict['id'] = getattr(self, 'id') + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'subjects') and self.subjects is not None: + subjects_list = [] + for v in self.subjects: + if isinstance(v, dict): + subjects_list.append(v) + else: + subjects_list.append(v.to_dict()) + _dict['subjects'] = subjects_list + if hasattr(self, 'roles') and self.roles is not None: + roles_list = [] + for v in self.roles: + if isinstance(v, dict): + roles_list.append(v) + else: + roles_list.append(v.to_dict()) + _dict['roles'] = roles_list + if hasattr(self, 'resources') and self.resources is not None: + resources_list = [] + for v in self.resources: + if isinstance(v, dict): + resources_list.append(v) + else: + resources_list.append(v.to_dict()) + _dict['resources'] = resources_list + if hasattr(self, 'href') and getattr(self, 'href') is not None: + _dict['href'] = getattr(self, 'href') + if hasattr(self, 'created_at') and getattr(self, 'created_at') is not None: + _dict['created_at'] = datetime_to_string(getattr(self, 'created_at')) + if hasattr(self, 'created_by_id') and getattr(self, 'created_by_id') is not None: + _dict['created_by_id'] = getattr(self, 'created_by_id') + if hasattr(self, 'last_modified_at') and getattr(self, 'last_modified_at') is not None: + _dict['last_modified_at'] = datetime_to_string(getattr(self, 'last_modified_at')) + if hasattr(self, 'last_modified_by_id') and getattr(self, 'last_modified_by_id') is not None: + _dict['last_modified_by_id'] = getattr(self, 'last_modified_by_id') + if hasattr(self, 'state') and self.state is not None: + _dict['state'] = self.state + if hasattr(self, 'template') and self.template is not None: + if isinstance(self.template, dict): + _dict['template'] = self.template + else: + _dict['template'] = self.template.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Policy object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Policy') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Policy') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class StateEnum(str, Enum): + """ + The policy state. + """ + + ACTIVE = 'active' + DELETED = 'deleted' + + +class PolicyAssignment: + """ + The set of properties associated with the policy template assignment. + + :attr str template_id: policy template id. + :attr str template_version: policy template version. + :attr str assignment_id: Passed in value to correlate with other assignments. + :attr str target_type: Assignment target type. + :attr str target: ID of the target account. + :attr List[PolicyAssignmentRequestOptionsItem] options: List of objects with + required properties for a policy assignment. + :attr str id: (optional) Policy assignment ID. + :attr str account_id: (optional) The account GUID that the policies assignments + belong to.. + :attr str href: (optional) The href URL that links to the policies assignments + API by policy assignment ID. + :attr datetime created_at: (optional) The UTC timestamp when the policy + assignment was created. + :attr str created_by_id: (optional) The iam ID of the entity that created the + policy assignment. + :attr datetime last_modified_at: (optional) The UTC timestamp when the policy + assignment was last modified. + :attr str last_modified_by_id: (optional) The iam ID of the entity that last + modified the policy assignment. + :attr List[PolicyAssignmentResources] resources: (optional) Object for each + account assigned. + :attr str status: The policy assignment status. + """ + + def __init__( + self, + template_id: str, + template_version: str, + assignment_id: str, + target_type: str, + target: str, + options: List['PolicyAssignmentRequestOptionsItem'], + status: str, + *, + id: str = None, + account_id: str = None, + href: str = None, + created_at: datetime = None, + created_by_id: str = None, + last_modified_at: datetime = None, + last_modified_by_id: str = None, + resources: List['PolicyAssignmentResources'] = None, + ) -> None: + """ + Initialize a PolicyAssignment object. + + :param str template_id: policy template id. + :param str template_version: policy template version. + :param str assignment_id: Passed in value to correlate with other + assignments. + :param str target_type: Assignment target type. + :param str target: ID of the target account. + :param List[PolicyAssignmentRequestOptionsItem] options: List of objects + with required properties for a policy assignment. + :param str status: The policy assignment status. + :param List[PolicyAssignmentResources] resources: (optional) Object for + each account assigned. + """ + self.template_id = template_id + self.template_version = template_version + self.assignment_id = assignment_id + self.target_type = target_type + self.target = target + self.options = options + self.id = id + self.account_id = account_id + self.href = href + self.created_at = created_at + self.created_by_id = created_by_id + self.last_modified_at = last_modified_at + self.last_modified_by_id = last_modified_by_id + self.resources = resources + self.status = status + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PolicyAssignment': + """Initialize a PolicyAssignment object from a json dictionary.""" + args = {} + if 'template_id' in _dict: + args['template_id'] = _dict.get('template_id') + else: + raise ValueError('Required property \'template_id\' not present in PolicyAssignment JSON') + if 'template_version' in _dict: + args['template_version'] = _dict.get('template_version') + else: + raise ValueError('Required property \'template_version\' not present in PolicyAssignment JSON') + if 'assignment_id' in _dict: + args['assignment_id'] = _dict.get('assignment_id') + else: + raise ValueError('Required property \'assignment_id\' not present in PolicyAssignment JSON') + if 'target_type' in _dict: + args['target_type'] = _dict.get('target_type') + else: + raise ValueError('Required property \'target_type\' not present in PolicyAssignment JSON') + if 'target' in _dict: + args['target'] = _dict.get('target') + else: + raise ValueError('Required property \'target\' not present in PolicyAssignment JSON') + if 'options' in _dict: + args['options'] = [PolicyAssignmentRequestOptionsItem.from_dict(v) for v in _dict.get('options')] + else: + raise ValueError('Required property \'options\' not present in PolicyAssignment JSON') + if 'id' in _dict: + args['id'] = _dict.get('id') + if 'account_id' in _dict: + args['account_id'] = _dict.get('account_id') + if 'href' in _dict: + args['href'] = _dict.get('href') + if 'created_at' in _dict: + args['created_at'] = string_to_datetime(_dict.get('created_at')) + if 'created_by_id' in _dict: + args['created_by_id'] = _dict.get('created_by_id') + if 'last_modified_at' in _dict: + args['last_modified_at'] = string_to_datetime(_dict.get('last_modified_at')) + if 'last_modified_by_id' in _dict: + args['last_modified_by_id'] = _dict.get('last_modified_by_id') + if 'resources' in _dict: + args['resources'] = [PolicyAssignmentResources.from_dict(v) for v in _dict.get('resources')] + if 'status' in _dict: + args['status'] = _dict.get('status') + else: + raise ValueError('Required property \'status\' not present in PolicyAssignment JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PolicyAssignment object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'template_id') and self.template_id is not None: + _dict['template_id'] = self.template_id + if hasattr(self, 'template_version') and self.template_version is not None: + _dict['template_version'] = self.template_version + if hasattr(self, 'assignment_id') and self.assignment_id is not None: + _dict['assignment_id'] = self.assignment_id + if hasattr(self, 'target_type') and self.target_type is not None: + _dict['target_type'] = self.target_type + if hasattr(self, 'target') and self.target is not None: + _dict['target'] = self.target + if hasattr(self, 'options') and self.options is not None: + options_list = [] + for v in self.options: + if isinstance(v, dict): + options_list.append(v) + else: + options_list.append(v.to_dict()) + _dict['options'] = options_list + if hasattr(self, 'id') and getattr(self, 'id') is not None: + _dict['id'] = getattr(self, 'id') + if hasattr(self, 'account_id') and getattr(self, 'account_id') is not None: + _dict['account_id'] = getattr(self, 'account_id') + if hasattr(self, 'href') and getattr(self, 'href') is not None: + _dict['href'] = getattr(self, 'href') + if hasattr(self, 'created_at') and getattr(self, 'created_at') is not None: + _dict['created_at'] = datetime_to_string(getattr(self, 'created_at')) + if hasattr(self, 'created_by_id') and getattr(self, 'created_by_id') is not None: + _dict['created_by_id'] = getattr(self, 'created_by_id') + if hasattr(self, 'last_modified_at') and getattr(self, 'last_modified_at') is not None: + _dict['last_modified_at'] = datetime_to_string(getattr(self, 'last_modified_at')) + if hasattr(self, 'last_modified_by_id') and getattr(self, 'last_modified_by_id') is not None: + _dict['last_modified_by_id'] = getattr(self, 'last_modified_by_id') + if hasattr(self, 'resources') and self.resources is not None: + resources_list = [] + for v in self.resources: + if isinstance(v, dict): + resources_list.append(v) + else: + resources_list.append(v.to_dict()) + _dict['resources'] = resources_list + if hasattr(self, 'status') and self.status is not None: + _dict['status'] = self.status + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PolicyAssignment object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PolicyAssignment') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PolicyAssignment') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class TargetTypeEnum(str, Enum): + """ + Assignment target type. + """ + + ACCOUNT = 'Account' + + class StatusEnum(str, Enum): + """ + The policy assignment status. + """ + + IN_PROGRESS = 'in_progress' + SUCCEEDED = 'succeeded' + SUCCEED_WITH_ERRORS = 'succeed_with_errors' + FAILED = 'failed' + + +class PolicyAssignmentRequestOptionsItem: + """ + The set of properties required for a policy assignment. + + :attr str subject_type: The policy subject type; either 'iam_id' or + 'access_group_id'. + :attr str subject_id: The policy subject id. + :attr str root_requester_id: The policy assignment requester id. + :attr str root_template_id: (optional) The template id where this policy is + being assigned from. + :attr str root_template_version: (optional) The template version where this + policy is being assigned from. + """ + + def __init__( + self, + subject_type: str, + subject_id: str, + root_requester_id: str, + *, + root_template_id: str = None, + root_template_version: str = None, + ) -> None: + """ + Initialize a PolicyAssignmentRequestOptionsItem object. + + :param str subject_type: The policy subject type; either 'iam_id' or + 'access_group_id'. + :param str subject_id: The policy subject id. + :param str root_requester_id: The policy assignment requester id. + :param str root_template_id: (optional) The template id where this policy + is being assigned from. + :param str root_template_version: (optional) The template version where + this policy is being assigned from. + """ + self.subject_type = subject_type + self.subject_id = subject_id + self.root_requester_id = root_requester_id + self.root_template_id = root_template_id + self.root_template_version = root_template_version + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PolicyAssignmentRequestOptionsItem': + """Initialize a PolicyAssignmentRequestOptionsItem object from a json dictionary.""" + args = {} + if 'subject_type' in _dict: + args['subject_type'] = _dict.get('subject_type') + else: + raise ValueError( + 'Required property \'subject_type\' not present in PolicyAssignmentRequestOptionsItem JSON' + ) + if 'subject_id' in _dict: + args['subject_id'] = _dict.get('subject_id') + else: + raise ValueError('Required property \'subject_id\' not present in PolicyAssignmentRequestOptionsItem JSON') + if 'root_requester_id' in _dict: + args['root_requester_id'] = _dict.get('root_requester_id') + else: + raise ValueError( + 'Required property \'root_requester_id\' not present in PolicyAssignmentRequestOptionsItem JSON' + ) + if 'root_template_id' in _dict: + args['root_template_id'] = _dict.get('root_template_id') + if 'root_template_version' in _dict: + args['root_template_version'] = _dict.get('root_template_version') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PolicyAssignmentRequestOptionsItem object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'subject_type') and self.subject_type is not None: + _dict['subject_type'] = self.subject_type + if hasattr(self, 'subject_id') and self.subject_id is not None: + _dict['subject_id'] = self.subject_id + if hasattr(self, 'root_requester_id') and self.root_requester_id is not None: + _dict['root_requester_id'] = self.root_requester_id + if hasattr(self, 'root_template_id') and self.root_template_id is not None: + _dict['root_template_id'] = self.root_template_id + if hasattr(self, 'root_template_version') and self.root_template_version is not None: + _dict['root_template_version'] = self.root_template_version + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PolicyAssignmentRequestOptionsItem object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PolicyAssignmentRequestOptionsItem') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PolicyAssignmentRequestOptionsItem') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class SubjectTypeEnum(str, Enum): + """ + The policy subject type; either 'iam_id' or 'access_group_id'. + """ + + IAM_ID = 'iam_id' + ACCESS_GROUP_ID = 'access_group_id' + + +class PolicyAssignmentResources: + """ + The policy assignment resources. + + :attr str target: (optional) Account ID where resources are assigned. + :attr PolicyAssignmentResourcesPolicy policy: (optional) Set of properties for + the assigned resource. + """ + + def __init__( + self, + *, + target: str = None, + policy: 'PolicyAssignmentResourcesPolicy' = None, + ) -> None: + """ + Initialize a PolicyAssignmentResources object. + + :param str target: (optional) Account ID where resources are assigned. + :param PolicyAssignmentResourcesPolicy policy: (optional) Set of properties + for the assigned resource. + """ + self.target = target + self.policy = policy + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PolicyAssignmentResources': + """Initialize a PolicyAssignmentResources object from a json dictionary.""" + args = {} + if 'target' in _dict: + args['target'] = _dict.get('target') + if 'policy' in _dict: + args['policy'] = PolicyAssignmentResourcesPolicy.from_dict(_dict.get('policy')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PolicyAssignmentResources object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'target') and self.target is not None: + _dict['target'] = self.target + if hasattr(self, 'policy') and self.policy is not None: + if isinstance(self.policy, dict): + _dict['policy'] = self.policy + else: + _dict['policy'] = self.policy.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PolicyAssignmentResources object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PolicyAssignmentResources') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PolicyAssignmentResources') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class PolicyAssignmentResourcesPolicy: + """ + Set of properties for the assigned resource. + + :attr AssignmentResourceCreated resource_created: On success, includes the + policy assigned. + :attr ErrorResponse error_message: (optional) The error response from API. + """ + + def __init__( + self, + resource_created: 'AssignmentResourceCreated', + *, + error_message: 'ErrorResponse' = None, + ) -> None: + """ + Initialize a PolicyAssignmentResourcesPolicy object. + + :param AssignmentResourceCreated resource_created: On success, includes the + policy assigned. + :param ErrorResponse error_message: (optional) The error response from API. + """ + self.resource_created = resource_created + self.error_message = error_message + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PolicyAssignmentResourcesPolicy': + """Initialize a PolicyAssignmentResourcesPolicy object from a json dictionary.""" + args = {} + if 'resource_created' in _dict: + args['resource_created'] = AssignmentResourceCreated.from_dict(_dict.get('resource_created')) + else: + raise ValueError( + 'Required property \'resource_created\' not present in PolicyAssignmentResourcesPolicy JSON' + ) + if 'error_message' in _dict: + args['error_message'] = ErrorResponse.from_dict(_dict.get('error_message')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PolicyAssignmentResourcesPolicy object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'resource_created') and self.resource_created is not None: + if isinstance(self.resource_created, dict): + _dict['resource_created'] = self.resource_created + else: + _dict['resource_created'] = self.resource_created.to_dict() + if hasattr(self, 'error_message') and self.error_message is not None: + if isinstance(self.error_message, dict): + _dict['error_message'] = self.error_message + else: + _dict['error_message'] = self.error_message.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PolicyAssignmentResourcesPolicy object.""" + return json.dumps(self.to_dict(), indent=2) - :attr Grant grant: Permission granted by the policy. + def __eq__(self, other: 'PolicyAssignmentResourcesPolicy') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PolicyAssignmentResourcesPolicy') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class PolicyCollection: + """ + A collection of policies. + + :attr List[Policy] policies: (optional) List of policies. """ - def __init__(self, grant: 'Grant') -> None: + def __init__( + self, + *, + policies: List['Policy'] = None, + ) -> None: """ - Initialize a Control object. + Initialize a PolicyCollection object. - :param Grant grant: Permission granted by the policy. + :param List[Policy] policies: (optional) List of policies. """ - self.grant = grant + self.policies = policies @classmethod - def from_dict(cls, _dict: Dict) -> 'Control': - """Initialize a Control object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'PolicyCollection': + """Initialize a PolicyCollection object from a json dictionary.""" args = {} - if 'grant' in _dict: - args['grant'] = Grant.from_dict(_dict.get('grant')) - else: - raise ValueError('Required property \'grant\' not present in Control JSON') + if 'policies' in _dict: + args['policies'] = [Policy.from_dict(v) for v in _dict.get('policies')] return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a Control object from a json dictionary.""" + """Initialize a PolicyCollection object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'grant') and self.grant is not None: - if isinstance(self.grant, dict): - _dict['grant'] = self.grant - else: - _dict['grant'] = self.grant.to_dict() + if hasattr(self, 'policies') and self.policies is not None: + policies_list = [] + for v in self.policies: + if isinstance(v, dict): + policies_list.append(v) + else: + policies_list.append(v.to_dict()) + _dict['policies'] = policies_list return _dict def _to_dict(self): @@ -1512,91 +3932,144 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this Control object.""" + """Return a `str` version of this PolicyCollection object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'Control') -> bool: + def __eq__(self, other: 'PolicyCollection') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'Control') -> bool: + def __ne__(self, other: 'PolicyCollection') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class ControlResponse: +class PolicyResource: """ - ControlResponse. + The attributes of the resource. Note that only one resource is allowed in a policy. + :attr List[ResourceAttribute] attributes: (optional) List of resource + attributes. + :attr List[ResourceTag] tags: (optional) List of access management tags. """ - def __init__(self) -> None: + def __init__( + self, + *, + attributes: List['ResourceAttribute'] = None, + tags: List['ResourceTag'] = None, + ) -> None: """ - Initialize a ControlResponse object. + Initialize a PolicyResource object. + :param List[ResourceAttribute] attributes: (optional) List of resource + attributes. + :param List[ResourceTag] tags: (optional) List of access management tags. """ - msg = "Cannot instantiate base class. Instead, instantiate one of the defined subclasses: {0}".format( - ", ".join(['ControlResponseControl', 'ControlResponseControlWithEnrichedRoles']) - ) - raise Exception(msg) + self.attributes = attributes + self.tags = tags + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PolicyResource': + """Initialize a PolicyResource object from a json dictionary.""" + args = {} + if 'attributes' in _dict: + args['attributes'] = [ResourceAttribute.from_dict(v) for v in _dict.get('attributes')] + if 'tags' in _dict: + args['tags'] = [ResourceTag.from_dict(v) for v in _dict.get('tags')] + return cls(**args) + @classmethod + def _from_dict(cls, _dict): + """Initialize a PolicyResource object from a json dictionary.""" + return cls.from_dict(_dict) -class EnrichedRoles: + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'attributes') and self.attributes is not None: + attributes_list = [] + for v in self.attributes: + if isinstance(v, dict): + attributes_list.append(v) + else: + attributes_list.append(v.to_dict()) + _dict['attributes'] = attributes_list + if hasattr(self, 'tags') and self.tags is not None: + tags_list = [] + for v in self.tags: + if isinstance(v, dict): + tags_list.append(v) + else: + tags_list.append(v.to_dict()) + _dict['tags'] = tags_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PolicyResource object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PolicyResource') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PolicyResource') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class PolicyRole: """ - A role associated with a policy with additional information (display_name, - description, actions) when `format=display`. + A role associated with a policy. :attr str role_id: The role Cloud Resource Name (CRN) granted by the policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. - :attr str display_name: (optional) The service defined (or user defined if a - custom role) display name of the role. - :attr str description: (optional) The service defined (or user defined if a - custom role) description of the role. - :attr List[RoleAction] actions: The actions of the role. For more information, - see [IAM roles and - actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + :attr str display_name: (optional) The display name of the role. + :attr str description: (optional) The description of the role. """ def __init__( - self, role_id: str, actions: List['RoleAction'], *, display_name: str = None, description: str = None + self, + role_id: str, + *, + display_name: str = None, + description: str = None, ) -> None: """ - Initialize a EnrichedRoles object. + Initialize a PolicyRole object. :param str role_id: The role Cloud Resource Name (CRN) granted by the policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. - :param List[RoleAction] actions: The actions of the role. For more - information, see [IAM roles and - actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). """ self.role_id = role_id self.display_name = display_name self.description = description - self.actions = actions @classmethod - def from_dict(cls, _dict: Dict) -> 'EnrichedRoles': - """Initialize a EnrichedRoles object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'PolicyRole': + """Initialize a PolicyRole object from a json dictionary.""" args = {} if 'role_id' in _dict: args['role_id'] = _dict.get('role_id') else: - raise ValueError('Required property \'role_id\' not present in EnrichedRoles JSON') + raise ValueError('Required property \'role_id\' not present in PolicyRole JSON') if 'display_name' in _dict: args['display_name'] = _dict.get('display_name') if 'description' in _dict: args['description'] = _dict.get('description') - if 'actions' in _dict: - args['actions'] = [RoleAction.from_dict(v) for v in _dict.get('actions')] - else: - raise ValueError('Required property \'actions\' not present in EnrichedRoles JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a EnrichedRoles object from a json dictionary.""" + """Initialize a PolicyRole object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: @@ -1608,14 +4081,72 @@ def to_dict(self) -> Dict: _dict['display_name'] = getattr(self, 'display_name') if hasattr(self, 'description') and getattr(self, 'description') is not None: _dict['description'] = getattr(self, 'description') - if hasattr(self, 'actions') and self.actions is not None: - actions_list = [] - for v in self.actions: + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PolicyRole object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PolicyRole') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PolicyRole') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class PolicySubject: + """ + The subject attribute values that must match in order for this policy to apply in a + permission decision. + + :attr List[SubjectAttribute] attributes: (optional) List of subject attributes. + """ + + def __init__( + self, + *, + attributes: List['SubjectAttribute'] = None, + ) -> None: + """ + Initialize a PolicySubject object. + + :param List[SubjectAttribute] attributes: (optional) List of subject + attributes. + """ + self.attributes = attributes + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PolicySubject': + """Initialize a PolicySubject object from a json dictionary.""" + args = {} + if 'attributes' in _dict: + args['attributes'] = [SubjectAttribute.from_dict(v) for v in _dict.get('attributes')] + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PolicySubject object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'attributes') and self.attributes is not None: + attributes_list = [] + for v in self.attributes: if isinstance(v, dict): - actions_list.append(v) + attributes_list.append(v) else: - actions_list.append(v.to_dict()) - _dict['actions'] = actions_list + attributes_list.append(v.to_dict()) + _dict['attributes'] = attributes_list return _dict def _to_dict(self): @@ -1623,63 +4154,167 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this EnrichedRoles object.""" + """Return a `str` version of this PolicySubject object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'EnrichedRoles') -> bool: + def __eq__(self, other: 'PolicySubject') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'EnrichedRoles') -> bool: + def __ne__(self, other: 'PolicySubject') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class Grant: +class PolicyTemplate: """ - Permission granted by the policy. - - :attr List[Roles] roles: A set of role cloud resource names (CRNs) granted by - the policy. + The core set of properties associated with the policy template. + + :attr str name: Required field when creating a new template. Otherwise this + field is optional. If the field is included it will change the name value for + all existing versions of the template. + :attr str description: (optional) Description of the policy template. This is + shown to users in the enterprise account. Use this to describe the purpose or + context of the policy for enterprise users managing IAM templates. + :attr str account_id: Enterprise account ID where this template will be created. + :attr str version: Template version. + :attr bool committed: (optional) Committed status of the template version. + :attr TemplatePolicy policy: The core set of properties associated with the + template's policy objet. + :attr str id: (optional) The policy template ID. + :attr str href: (optional) The href URL that links to the policy templates API + by policy template ID. + :attr datetime created_at: (optional) The UTC timestamp when the policy template + was created. + :attr str created_by_id: (optional) The iam ID of the entity that created the + policy template. + :attr datetime last_modified_at: (optional) The UTC timestamp when the policy + template was last modified. + :attr str last_modified_by_id: (optional) The iam ID of the entity that last + modified the policy template. """ - def __init__(self, roles: List['Roles']) -> None: + def __init__( + self, + name: str, + account_id: str, + version: str, + policy: 'TemplatePolicy', + *, + description: str = None, + committed: bool = None, + id: str = None, + href: str = None, + created_at: datetime = None, + created_by_id: str = None, + last_modified_at: datetime = None, + last_modified_by_id: str = None, + ) -> None: """ - Initialize a Grant object. - - :param List[Roles] roles: A set of role cloud resource names (CRNs) granted - by the policy. + Initialize a PolicyTemplate object. + + :param str name: Required field when creating a new template. Otherwise + this field is optional. If the field is included it will change the name + value for all existing versions of the template. + :param str account_id: Enterprise account ID where this template will be + created. + :param str version: Template version. + :param TemplatePolicy policy: The core set of properties associated with + the template's policy objet. + :param str description: (optional) Description of the policy template. This + is shown to users in the enterprise account. Use this to describe the + purpose or context of the policy for enterprise users managing IAM + templates. + :param bool committed: (optional) Committed status of the template version. """ - self.roles = roles + self.name = name + self.description = description + self.account_id = account_id + self.version = version + self.committed = committed + self.policy = policy + self.id = id + self.href = href + self.created_at = created_at + self.created_by_id = created_by_id + self.last_modified_at = last_modified_at + self.last_modified_by_id = last_modified_by_id @classmethod - def from_dict(cls, _dict: Dict) -> 'Grant': - """Initialize a Grant object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'PolicyTemplate': + """Initialize a PolicyTemplate object from a json dictionary.""" args = {} - if 'roles' in _dict: - args['roles'] = [Roles.from_dict(v) for v in _dict.get('roles')] + if 'name' in _dict: + args['name'] = _dict.get('name') else: - raise ValueError('Required property \'roles\' not present in Grant JSON') + raise ValueError('Required property \'name\' not present in PolicyTemplate JSON') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'account_id' in _dict: + args['account_id'] = _dict.get('account_id') + else: + raise ValueError('Required property \'account_id\' not present in PolicyTemplate JSON') + if 'version' in _dict: + args['version'] = _dict.get('version') + else: + raise ValueError('Required property \'version\' not present in PolicyTemplate JSON') + if 'committed' in _dict: + args['committed'] = _dict.get('committed') + if 'policy' in _dict: + args['policy'] = TemplatePolicy.from_dict(_dict.get('policy')) + else: + raise ValueError('Required property \'policy\' not present in PolicyTemplate JSON') + if 'id' in _dict: + args['id'] = _dict.get('id') + if 'href' in _dict: + args['href'] = _dict.get('href') + if 'created_at' in _dict: + args['created_at'] = string_to_datetime(_dict.get('created_at')) + if 'created_by_id' in _dict: + args['created_by_id'] = _dict.get('created_by_id') + if 'last_modified_at' in _dict: + args['last_modified_at'] = string_to_datetime(_dict.get('last_modified_at')) + if 'last_modified_by_id' in _dict: + args['last_modified_by_id'] = _dict.get('last_modified_by_id') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a Grant object from a json dictionary.""" + """Initialize a PolicyTemplate object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'roles') and self.roles is not None: - roles_list = [] - for v in self.roles: - if isinstance(v, dict): - roles_list.append(v) - else: - roles_list.append(v.to_dict()) - _dict['roles'] = roles_list + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'account_id') and self.account_id is not None: + _dict['account_id'] = self.account_id + if hasattr(self, 'version') and self.version is not None: + _dict['version'] = self.version + if hasattr(self, 'committed') and self.committed is not None: + _dict['committed'] = self.committed + if hasattr(self, 'policy') and self.policy is not None: + if isinstance(self.policy, dict): + _dict['policy'] = self.policy + else: + _dict['policy'] = self.policy.to_dict() + if hasattr(self, 'id') and getattr(self, 'id') is not None: + _dict['id'] = getattr(self, 'id') + if hasattr(self, 'href') and getattr(self, 'href') is not None: + _dict['href'] = getattr(self, 'href') + if hasattr(self, 'created_at') and getattr(self, 'created_at') is not None: + _dict['created_at'] = datetime_to_string(getattr(self, 'created_at')) + if hasattr(self, 'created_by_id') and getattr(self, 'created_by_id') is not None: + _dict['created_by_id'] = getattr(self, 'created_by_id') + if hasattr(self, 'last_modified_at') and getattr(self, 'last_modified_at') is not None: + _dict['last_modified_at'] = datetime_to_string(getattr(self, 'last_modified_at')) + if hasattr(self, 'last_modified_by_id') and getattr(self, 'last_modified_by_id') is not None: + _dict['last_modified_by_id'] = getattr(self, 'last_modified_by_id') return _dict def _to_dict(self): @@ -1687,62 +4322,64 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this Grant object.""" + """Return a `str` version of this PolicyTemplate object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'Grant') -> bool: + def __eq__(self, other: 'PolicyTemplate') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'Grant') -> bool: + def __ne__(self, other: 'PolicyTemplate') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class GrantWithEnrichedRoles: +class PolicyTemplateAssignmentCollection: """ - Permission granted by the policy with translated roles and additional role - information. + A collection of policies assignments. - :attr List[EnrichedRoles] roles: A set of roles granted by the policy. + :attr List[PolicyAssignment] assignments: (optional) List of policy assignments. """ - def __init__(self, roles: List['EnrichedRoles']) -> None: + def __init__( + self, + *, + assignments: List['PolicyAssignment'] = None, + ) -> None: """ - Initialize a GrantWithEnrichedRoles object. + Initialize a PolicyTemplateAssignmentCollection object. - :param List[EnrichedRoles] roles: A set of roles granted by the policy. + :param List[PolicyAssignment] assignments: (optional) List of policy + assignments. """ - self.roles = roles + self.assignments = assignments @classmethod - def from_dict(cls, _dict: Dict) -> 'GrantWithEnrichedRoles': - """Initialize a GrantWithEnrichedRoles object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'PolicyTemplateAssignmentCollection': + """Initialize a PolicyTemplateAssignmentCollection object from a json dictionary.""" args = {} - if 'roles' in _dict: - args['roles'] = [EnrichedRoles.from_dict(v) for v in _dict.get('roles')] - else: - raise ValueError('Required property \'roles\' not present in GrantWithEnrichedRoles JSON') + if 'assignments' in _dict: + args['assignments'] = [PolicyAssignment.from_dict(v) for v in _dict.get('assignments')] return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a GrantWithEnrichedRoles object from a json dictionary.""" + """Initialize a PolicyTemplateAssignmentCollection object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'roles') and self.roles is not None: - roles_list = [] - for v in self.roles: + if hasattr(self, 'assignments') and self.assignments is not None: + assignments_list = [] + for v in self.assignments: if isinstance(v, dict): - roles_list.append(v) + assignments_list.append(v) else: - roles_list.append(v.to_dict()) - _dict['roles'] = roles_list + assignments_list.append(v.to_dict()) + _dict['assignments'] = assignments_list return _dict def _to_dict(self): @@ -1750,69 +4387,65 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this GrantWithEnrichedRoles object.""" + """Return a `str` version of this PolicyTemplateAssignmentCollection object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'GrantWithEnrichedRoles') -> bool: + def __eq__(self, other: 'PolicyTemplateAssignmentCollection') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'GrantWithEnrichedRoles') -> bool: + def __ne__(self, other: 'PolicyTemplateAssignmentCollection') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class PolicyRole: +class PolicyTemplateCollection: """ - A role associated with a policy. + A collection of policy Templates. - :attr str role_id: The role Cloud Resource Name (CRN) granted by the policy. - Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. - :attr str display_name: (optional) The display name of the role. - :attr str description: (optional) The description of the role. + :attr List[PolicyTemplate] policy_templates: (optional) List of policy + templates. """ - def __init__(self, role_id: str, *, display_name: str = None, description: str = None) -> None: + def __init__( + self, + *, + policy_templates: List['PolicyTemplate'] = None, + ) -> None: """ - Initialize a PolicyRole object. + Initialize a PolicyTemplateCollection object. - :param str role_id: The role Cloud Resource Name (CRN) granted by the - policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. + :param List[PolicyTemplate] policy_templates: (optional) List of policy + templates. """ - self.role_id = role_id - self.display_name = display_name - self.description = description + self.policy_templates = policy_templates @classmethod - def from_dict(cls, _dict: Dict) -> 'PolicyRole': - """Initialize a PolicyRole object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'PolicyTemplateCollection': + """Initialize a PolicyTemplateCollection object from a json dictionary.""" args = {} - if 'role_id' in _dict: - args['role_id'] = _dict.get('role_id') - else: - raise ValueError('Required property \'role_id\' not present in PolicyRole JSON') - if 'display_name' in _dict: - args['display_name'] = _dict.get('display_name') - if 'description' in _dict: - args['description'] = _dict.get('description') + if 'policy_templates' in _dict: + args['policy_templates'] = [PolicyTemplate.from_dict(v) for v in _dict.get('policy_templates')] return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a PolicyRole object from a json dictionary.""" + """Initialize a PolicyTemplateCollection object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'role_id') and self.role_id is not None: - _dict['role_id'] = self.role_id - if hasattr(self, 'display_name') and getattr(self, 'display_name') is not None: - _dict['display_name'] = getattr(self, 'display_name') - if hasattr(self, 'description') and getattr(self, 'description') is not None: - _dict['description'] = getattr(self, 'description') + if hasattr(self, 'policy_templates') and self.policy_templates is not None: + policy_templates_list = [] + for v in self.policy_templates: + if isinstance(v, dict): + policy_templates_list.append(v) + else: + policy_templates_list.append(v.to_dict()) + _dict['policy_templates'] = policy_templates_list return _dict def _to_dict(self): @@ -1820,75 +4453,65 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this PolicyRole object.""" + """Return a `str` version of this PolicyTemplateCollection object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'PolicyRole') -> bool: + def __eq__(self, other: 'PolicyTemplateCollection') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'PolicyRole') -> bool: + def __ne__(self, other: 'PolicyTemplateCollection') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class RoleAction: +class PolicyTemplateVersionsCollection: """ - An action that can be performed by the policy subject when assigned role. + A collection of versions for a specific policy template. - :attr str id: Unique identifier for action with structure - service.resource.action e.g., cbr.rule.read. - :attr str display_name: Service defined display name for action. - :attr str description: Service defined description for action. + :attr List[PolicyTemplate] versions: (optional) List of policy templates + versions. """ - def __init__(self, id: str, display_name: str, description: str) -> None: + def __init__( + self, + *, + versions: List['PolicyTemplate'] = None, + ) -> None: """ - Initialize a RoleAction object. + Initialize a PolicyTemplateVersionsCollection object. - :param str id: Unique identifier for action with structure - service.resource.action e.g., cbr.rule.read. - :param str display_name: Service defined display name for action. - :param str description: Service defined description for action. + :param List[PolicyTemplate] versions: (optional) List of policy templates + versions. """ - self.id = id - self.display_name = display_name - self.description = description + self.versions = versions @classmethod - def from_dict(cls, _dict: Dict) -> 'RoleAction': - """Initialize a RoleAction object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'PolicyTemplateVersionsCollection': + """Initialize a PolicyTemplateVersionsCollection object from a json dictionary.""" args = {} - if 'id' in _dict: - args['id'] = _dict.get('id') - else: - raise ValueError('Required property \'id\' not present in RoleAction JSON') - if 'display_name' in _dict: - args['display_name'] = _dict.get('display_name') - else: - raise ValueError('Required property \'display_name\' not present in RoleAction JSON') - if 'description' in _dict: - args['description'] = _dict.get('description') - else: - raise ValueError('Required property \'description\' not present in RoleAction JSON') + if 'versions' in _dict: + args['versions'] = [PolicyTemplate.from_dict(v) for v in _dict.get('versions')] return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a RoleAction object from a json dictionary.""" + """Initialize a PolicyTemplateVersionsCollection object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'id') and self.id is not None: - _dict['id'] = self.id - if hasattr(self, 'display_name') and self.display_name is not None: - _dict['display_name'] = self.display_name - if hasattr(self, 'description') and self.description is not None: - _dict['description'] = self.description + if hasattr(self, 'versions') and self.versions is not None: + versions_list = [] + for v in self.versions: + if isinstance(v, dict): + versions_list.append(v) + else: + versions_list.append(v.to_dict()) + _dict['versions'] = versions_list return _dict def _to_dict(self): @@ -1896,57 +4519,77 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this RoleAction object.""" + """Return a `str` version of this PolicyTemplateVersionsCollection object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'RoleAction') -> bool: + def __eq__(self, other: 'PolicyTemplateVersionsCollection') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'RoleAction') -> bool: + def __ne__(self, other: 'PolicyTemplateVersionsCollection') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class Roles: +class ResourceAttribute: """ - A role associated with a policy. + An attribute associated with a resource. - :attr str role_id: The role Cloud Resource Name (CRN) granted by the policy. - Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. + :attr str name: The name of an attribute. + :attr str value: The value of an attribute. + :attr str operator: (optional) The operator of an attribute. """ - def __init__(self, role_id: str) -> None: + def __init__( + self, + name: str, + value: str, + *, + operator: str = None, + ) -> None: """ - Initialize a Roles object. + Initialize a ResourceAttribute object. - :param str role_id: The role Cloud Resource Name (CRN) granted by the - policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. + :param str name: The name of an attribute. + :param str value: The value of an attribute. + :param str operator: (optional) The operator of an attribute. """ - self.role_id = role_id + self.name = name + self.value = value + self.operator = operator @classmethod - def from_dict(cls, _dict: Dict) -> 'Roles': - """Initialize a Roles object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'ResourceAttribute': + """Initialize a ResourceAttribute object from a json dictionary.""" args = {} - if 'role_id' in _dict: - args['role_id'] = _dict.get('role_id') + if 'name' in _dict: + args['name'] = _dict.get('name') else: - raise ValueError('Required property \'role_id\' not present in Roles JSON') + raise ValueError('Required property \'name\' not present in ResourceAttribute JSON') + if 'value' in _dict: + args['value'] = _dict.get('value') + else: + raise ValueError('Required property \'value\' not present in ResourceAttribute JSON') + if 'operator' in _dict: + args['operator'] = _dict.get('operator') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a Roles object from a json dictionary.""" + """Initialize a ResourceAttribute object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'role_id') and self.role_id is not None: - _dict['role_id'] = self.role_id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'value') and self.value is not None: + _dict['value'] = self.value + if hasattr(self, 'operator') and self.operator is not None: + _dict['operator'] = self.operator return _dict def _to_dict(self): @@ -1954,77 +4597,77 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this Roles object.""" + """Return a `str` version of this ResourceAttribute object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'Roles') -> bool: + def __eq__(self, other: 'ResourceAttribute') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'Roles') -> bool: + def __ne__(self, other: 'ResourceAttribute') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class RuleAttribute: +class ResourceTag: """ - Rule that specifies additional access granted (e.g., time-based condition). + A tag associated with a resource. - :attr str key: The name of an attribute. - :attr str operator: The operator of an attribute. - :attr object value: The value of a rule or resource attribute; can be boolean or - string for resource attribute. Can be string or an array of strings (e.g., array - of days to permit access) for rule attribute. + :attr str name: The name of an access management tag. + :attr str value: The value of an access management tag. + :attr str operator: (optional) The operator of an access management tag. """ - def __init__(self, key: str, operator: str, value: object) -> None: + def __init__( + self, + name: str, + value: str, + *, + operator: str = None, + ) -> None: """ - Initialize a RuleAttribute object. + Initialize a ResourceTag object. - :param str key: The name of an attribute. - :param str operator: The operator of an attribute. - :param object value: The value of a rule or resource attribute; can be - boolean or string for resource attribute. Can be string or an array of - strings (e.g., array of days to permit access) for rule attribute. + :param str name: The name of an access management tag. + :param str value: The value of an access management tag. + :param str operator: (optional) The operator of an access management tag. """ - self.key = key - self.operator = operator + self.name = name self.value = value + self.operator = operator @classmethod - def from_dict(cls, _dict: Dict) -> 'RuleAttribute': - """Initialize a RuleAttribute object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'ResourceTag': + """Initialize a ResourceTag object from a json dictionary.""" args = {} - if 'key' in _dict: - args['key'] = _dict.get('key') - else: - raise ValueError('Required property \'key\' not present in RuleAttribute JSON') - if 'operator' in _dict: - args['operator'] = _dict.get('operator') + if 'name' in _dict: + args['name'] = _dict.get('name') else: - raise ValueError('Required property \'operator\' not present in RuleAttribute JSON') + raise ValueError('Required property \'name\' not present in ResourceTag JSON') if 'value' in _dict: args['value'] = _dict.get('value') else: - raise ValueError('Required property \'value\' not present in RuleAttribute JSON') + raise ValueError('Required property \'value\' not present in ResourceTag JSON') + if 'operator' in _dict: + args['operator'] = _dict.get('operator') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a RuleAttribute object from a json dictionary.""" + """Initialize a ResourceTag object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'key') and self.key is not None: - _dict['key'] = self.key - if hasattr(self, 'operator') and self.operator is not None: - _dict['operator'] = self.operator + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name if hasattr(self, 'value') and self.value is not None: _dict['value'] = self.value + if hasattr(self, 'operator') and self.operator is not None: + _dict['operator'] = self.operator return _dict def _to_dict(self): @@ -2032,228 +4675,91 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this RuleAttribute object.""" + """Return a `str` version of this ResourceTag object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'RuleAttribute') -> bool: + def __eq__(self, other: 'ResourceTag') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'RuleAttribute') -> bool: + def __ne__(self, other: 'ResourceTag') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other - class OperatorEnum(str, Enum): - """ - The operator of an attribute. - """ - - TIMELESSTHAN = 'timeLessThan' - TIMELESSTHANOREQUALS = 'timeLessThanOrEquals' - TIMEGREATERTHAN = 'timeGreaterThan' - TIMEGREATERTHANOREQUALS = 'timeGreaterThanOrEquals' - DATETIMELESSTHAN = 'dateTimeLessThan' - DATETIMELESSTHANOREQUALS = 'dateTimeLessThanOrEquals' - DATETIMEGREATERTHAN = 'dateTimeGreaterThan' - DATETIMEGREATERTHANOREQUALS = 'dateTimeGreaterThanOrEquals' - DAYOFWEEKEQUALS = 'dayOfWeekEquals' - DAYOFWEEKANYOF = 'dayOfWeekAnyOf' - -class V2Policy: +class Role: """ - The core set of properties associated with the policy. + A role resource. - :attr str type: The policy type; either 'access' or 'authorization'. - :attr str description: (optional) Allows the customer to use their own words to - record the purpose/context related to a policy. - :attr V2PolicySubject subject: (optional) The subject attributes for whom the - policy grants access. - :attr V2PolicyResource resource: (optional) The resource attributes to which the - policy grants access. - :attr str pattern: (optional) Indicates pattern of rule, either - 'time-based-conditions:once', 'time-based-conditions:weekly:all-day', or - 'time-based-conditions:weekly:custom-hours'. - :attr V2PolicyRule rule: (optional) Additional access conditions associated with - the policy. - :attr str id: (optional) The policy ID. - :attr str href: (optional) The href URL that links to the policies API by policy - ID. - :attr ControlResponse control: - :attr datetime created_at: (optional) The UTC timestamp when the policy was - created. - :attr str created_by_id: (optional) The iam ID of the entity that created the - policy. - :attr datetime last_modified_at: (optional) The UTC timestamp when the policy - was last modified. - :attr str last_modified_by_id: (optional) The iam ID of the entity that last - modified the policy. - :attr str state: The policy state, either 'deleted' or 'active'. - :attr str last_permit_at: (optional) The optional last permit time of policy, - when passing query parameter format=include_last_permit. - :attr int last_permit_frequency: (optional) The optional count of times that - policy has provided a permit, when passing query parameter - format=include_last_permit. + :attr str display_name: The display name of the role that is shown in the + console. + :attr str description: (optional) The description of the role. + :attr List[str] actions: The actions of the role. For more information, see [IAM + roles and + actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + :attr str crn: (optional) The role Cloud Resource Name (CRN). Example CRN: + 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. """ def __init__( self, - type: str, - control: 'ControlResponse', - state: str, + display_name: str, + actions: List[str], *, description: str = None, - subject: 'V2PolicySubject' = None, - resource: 'V2PolicyResource' = None, - pattern: str = None, - rule: 'V2PolicyRule' = None, - id: str = None, - href: str = None, - created_at: datetime = None, - created_by_id: str = None, - last_modified_at: datetime = None, - last_modified_by_id: str = None, - last_permit_at: str = None, - last_permit_frequency: int = None + crn: str = None, ) -> None: """ - Initialize a V2Policy object. + Initialize a Role object. - :param str type: The policy type; either 'access' or 'authorization'. - :param ControlResponse control: - :param str state: The policy state, either 'deleted' or 'active'. - :param str description: (optional) Allows the customer to use their own - words to record the purpose/context related to a policy. - :param V2PolicySubject subject: (optional) The subject attributes for whom - the policy grants access. - :param V2PolicyResource resource: (optional) The resource attributes to - which the policy grants access. - :param str pattern: (optional) Indicates pattern of rule, either - 'time-based-conditions:once', 'time-based-conditions:weekly:all-day', or - 'time-based-conditions:weekly:custom-hours'. - :param V2PolicyRule rule: (optional) Additional access conditions - associated with the policy. - :param str last_permit_at: (optional) The optional last permit time of - policy, when passing query parameter format=include_last_permit. - :param int last_permit_frequency: (optional) The optional count of times - that policy has provided a permit, when passing query parameter - format=include_last_permit. + :param str display_name: The display name of the role that is shown in the + console. + :param List[str] actions: The actions of the role. For more information, + see [IAM roles and + actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). + :param str description: (optional) The description of the role. """ - self.type = type + self.display_name = display_name self.description = description - self.subject = subject - self.resource = resource - self.pattern = pattern - self.rule = rule - self.id = id - self.href = href - self.control = control - self.created_at = created_at - self.created_by_id = created_by_id - self.last_modified_at = last_modified_at - self.last_modified_by_id = last_modified_by_id - self.state = state - self.last_permit_at = last_permit_at - self.last_permit_frequency = last_permit_frequency + self.actions = actions + self.crn = crn @classmethod - def from_dict(cls, _dict: Dict) -> 'V2Policy': - """Initialize a V2Policy object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'Role': + """Initialize a Role object from a json dictionary.""" args = {} - if 'type' in _dict: - args['type'] = _dict.get('type') + if 'display_name' in _dict: + args['display_name'] = _dict.get('display_name') else: - raise ValueError('Required property \'type\' not present in V2Policy JSON') + raise ValueError('Required property \'display_name\' not present in Role JSON') if 'description' in _dict: args['description'] = _dict.get('description') - if 'subject' in _dict: - args['subject'] = V2PolicySubject.from_dict(_dict.get('subject')) - if 'resource' in _dict: - args['resource'] = V2PolicyResource.from_dict(_dict.get('resource')) - if 'pattern' in _dict: - args['pattern'] = _dict.get('pattern') - if 'rule' in _dict: - args['rule'] = _dict.get('rule') - if 'id' in _dict: - args['id'] = _dict.get('id') - if 'href' in _dict: - args['href'] = _dict.get('href') - if 'control' in _dict: - args['control'] = _dict.get('control') - else: - raise ValueError('Required property \'control\' not present in V2Policy JSON') - if 'created_at' in _dict: - args['created_at'] = string_to_datetime(_dict.get('created_at')) - if 'created_by_id' in _dict: - args['created_by_id'] = _dict.get('created_by_id') - if 'last_modified_at' in _dict: - args['last_modified_at'] = string_to_datetime(_dict.get('last_modified_at')) - if 'last_modified_by_id' in _dict: - args['last_modified_by_id'] = _dict.get('last_modified_by_id') - if 'state' in _dict: - args['state'] = _dict.get('state') + if 'actions' in _dict: + args['actions'] = _dict.get('actions') else: - raise ValueError('Required property \'state\' not present in V2Policy JSON') - if 'last_permit_at' in _dict: - args['last_permit_at'] = _dict.get('last_permit_at') - if 'last_permit_frequency' in _dict: - args['last_permit_frequency'] = _dict.get('last_permit_frequency') + raise ValueError('Required property \'actions\' not present in Role JSON') + if 'crn' in _dict: + args['crn'] = _dict.get('crn') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a V2Policy object from a json dictionary.""" + """Initialize a Role object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: - """Return a json dictionary representing this model.""" - _dict = {} - if hasattr(self, 'type') and self.type is not None: - _dict['type'] = self.type - if hasattr(self, 'description') and self.description is not None: - _dict['description'] = self.description - if hasattr(self, 'subject') and self.subject is not None: - if isinstance(self.subject, dict): - _dict['subject'] = self.subject - else: - _dict['subject'] = self.subject.to_dict() - if hasattr(self, 'resource') and self.resource is not None: - if isinstance(self.resource, dict): - _dict['resource'] = self.resource - else: - _dict['resource'] = self.resource.to_dict() - if hasattr(self, 'pattern') and self.pattern is not None: - _dict['pattern'] = self.pattern - if hasattr(self, 'rule') and self.rule is not None: - if isinstance(self.rule, dict): - _dict['rule'] = self.rule - else: - _dict['rule'] = self.rule.to_dict() - if hasattr(self, 'id') and getattr(self, 'id') is not None: - _dict['id'] = getattr(self, 'id') - if hasattr(self, 'href') and getattr(self, 'href') is not None: - _dict['href'] = getattr(self, 'href') - if hasattr(self, 'control') and self.control is not None: - if isinstance(self.control, dict): - _dict['control'] = self.control - else: - _dict['control'] = self.control.to_dict() - if hasattr(self, 'created_at') and getattr(self, 'created_at') is not None: - _dict['created_at'] = datetime_to_string(getattr(self, 'created_at')) - if hasattr(self, 'created_by_id') and getattr(self, 'created_by_id') is not None: - _dict['created_by_id'] = getattr(self, 'created_by_id') - if hasattr(self, 'last_modified_at') and getattr(self, 'last_modified_at') is not None: - _dict['last_modified_at'] = datetime_to_string(getattr(self, 'last_modified_at')) - if hasattr(self, 'last_modified_by_id') and getattr(self, 'last_modified_by_id') is not None: - _dict['last_modified_by_id'] = getattr(self, 'last_modified_by_id') - if hasattr(self, 'state') and self.state is not None: - _dict['state'] = self.state - if hasattr(self, 'last_permit_at') and self.last_permit_at is not None: - _dict['last_permit_at'] = self.last_permit_at - if hasattr(self, 'last_permit_frequency') and self.last_permit_frequency is not None: - _dict['last_permit_frequency'] = self.last_permit_frequency + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'display_name') and self.display_name is not None: + _dict['display_name'] = self.display_name + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'actions') and self.actions is not None: + _dict['actions'] = self.actions + if hasattr(self, 'crn') and getattr(self, 'crn') is not None: + _dict['crn'] = getattr(self, 'crn') return _dict def _to_dict(self): @@ -2261,75 +4767,80 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this V2Policy object.""" + """Return a `str` version of this Role object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'V2Policy') -> bool: + def __eq__(self, other: 'Role') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'V2Policy') -> bool: + def __ne__(self, other: 'Role') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other - class TypeEnum(str, Enum): - """ - The policy type; either 'access' or 'authorization'. - """ - - ACCESS = 'access' - AUTHORIZATION = 'authorization' - - class StateEnum(str, Enum): - """ - The policy state, either 'deleted' or 'active'. - """ - - ACTIVE = 'active' - DELETED = 'deleted' - -class V2PolicyCollection: +class RoleAction: """ - A collection of policies. + An action that can be performed by the policy subject when assigned role. - :attr List[V2Policy] policies: (optional) List of policies. + :attr str id: Unique identifier for action with structure + service.resource.action e.g., cbr.rule.read. + :attr str display_name: Service defined display name for action. + :attr str description: Service defined description for action. """ - def __init__(self, *, policies: List['V2Policy'] = None) -> None: + def __init__( + self, + id: str, + display_name: str, + description: str, + ) -> None: """ - Initialize a V2PolicyCollection object. + Initialize a RoleAction object. - :param List[V2Policy] policies: (optional) List of policies. + :param str id: Unique identifier for action with structure + service.resource.action e.g., cbr.rule.read. + :param str display_name: Service defined display name for action. + :param str description: Service defined description for action. """ - self.policies = policies + self.id = id + self.display_name = display_name + self.description = description @classmethod - def from_dict(cls, _dict: Dict) -> 'V2PolicyCollection': - """Initialize a V2PolicyCollection object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'RoleAction': + """Initialize a RoleAction object from a json dictionary.""" args = {} - if 'policies' in _dict: - args['policies'] = [V2Policy.from_dict(v) for v in _dict.get('policies')] + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in RoleAction JSON') + if 'display_name' in _dict: + args['display_name'] = _dict.get('display_name') + else: + raise ValueError('Required property \'display_name\' not present in RoleAction JSON') + if 'description' in _dict: + args['description'] = _dict.get('description') + else: + raise ValueError('Required property \'description\' not present in RoleAction JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a V2PolicyCollection object from a json dictionary.""" + """Initialize a RoleAction object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'policies') and self.policies is not None: - policies_list = [] - for v in self.policies: - if isinstance(v, dict): - policies_list.append(v) - else: - policies_list.append(v.to_dict()) - _dict['policies'] = policies_list + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'display_name') and self.display_name is not None: + _dict['display_name'] = self.display_name + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description return _dict def _to_dict(self): @@ -2337,80 +4848,91 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this V2PolicyCollection object.""" + """Return a `str` version of this RoleAction object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'V2PolicyCollection') -> bool: + def __eq__(self, other: 'RoleAction') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'V2PolicyCollection') -> bool: + def __ne__(self, other: 'RoleAction') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class V2PolicyResource: +class RoleCollection: """ - The resource attributes to which the policy grants access. + A collection of roles returned by the 'list roles' operation. - :attr List[V2PolicyResourceAttribute] attributes: List of resource attributes to - which the policy grants access. - :attr List[V2PolicyResourceTag] tags: (optional) Optional list of resource tags - to which the policy grants access. + :attr List[CustomRole] custom_roles: (optional) List of custom roles. + :attr List[Role] service_roles: (optional) List of service roles. + :attr List[Role] system_roles: (optional) List of system roles. """ def __init__( - self, attributes: List['V2PolicyResourceAttribute'], *, tags: List['V2PolicyResourceTag'] = None + self, + *, + custom_roles: List['CustomRole'] = None, + service_roles: List['Role'] = None, + system_roles: List['Role'] = None, ) -> None: """ - Initialize a V2PolicyResource object. + Initialize a RoleCollection object. - :param List[V2PolicyResourceAttribute] attributes: List of resource - attributes to which the policy grants access. - :param List[V2PolicyResourceTag] tags: (optional) Optional list of resource - tags to which the policy grants access. + :param List[CustomRole] custom_roles: (optional) List of custom roles. + :param List[Role] service_roles: (optional) List of service roles. + :param List[Role] system_roles: (optional) List of system roles. """ - self.attributes = attributes - self.tags = tags + self.custom_roles = custom_roles + self.service_roles = service_roles + self.system_roles = system_roles @classmethod - def from_dict(cls, _dict: Dict) -> 'V2PolicyResource': - """Initialize a V2PolicyResource object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'RoleCollection': + """Initialize a RoleCollection object from a json dictionary.""" args = {} - if 'attributes' in _dict: - args['attributes'] = [V2PolicyResourceAttribute.from_dict(v) for v in _dict.get('attributes')] - else: - raise ValueError('Required property \'attributes\' not present in V2PolicyResource JSON') - if 'tags' in _dict: - args['tags'] = [V2PolicyResourceTag.from_dict(v) for v in _dict.get('tags')] + if 'custom_roles' in _dict: + args['custom_roles'] = [CustomRole.from_dict(v) for v in _dict.get('custom_roles')] + if 'service_roles' in _dict: + args['service_roles'] = [Role.from_dict(v) for v in _dict.get('service_roles')] + if 'system_roles' in _dict: + args['system_roles'] = [Role.from_dict(v) for v in _dict.get('system_roles')] return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a V2PolicyResource object from a json dictionary.""" + """Initialize a RoleCollection object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'attributes') and self.attributes is not None: - attributes_list = [] - for v in self.attributes: + if hasattr(self, 'custom_roles') and self.custom_roles is not None: + custom_roles_list = [] + for v in self.custom_roles: if isinstance(v, dict): - attributes_list.append(v) + custom_roles_list.append(v) else: - attributes_list.append(v.to_dict()) - _dict['attributes'] = attributes_list - if hasattr(self, 'tags') and self.tags is not None: - tags_list = [] - for v in self.tags: + custom_roles_list.append(v.to_dict()) + _dict['custom_roles'] = custom_roles_list + if hasattr(self, 'service_roles') and self.service_roles is not None: + service_roles_list = [] + for v in self.service_roles: if isinstance(v, dict): - tags_list.append(v) + service_roles_list.append(v) else: - tags_list.append(v.to_dict()) - _dict['tags'] = tags_list + service_roles_list.append(v.to_dict()) + _dict['service_roles'] = service_roles_list + if hasattr(self, 'system_roles') and self.system_roles is not None: + system_roles_list = [] + for v in self.system_roles: + if isinstance(v, dict): + system_roles_list.append(v) + else: + system_roles_list.append(v.to_dict()) + _dict['system_roles'] = system_roles_list return _dict def _to_dict(self): @@ -2418,77 +4940,60 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this V2PolicyResource object.""" + """Return a `str` version of this RoleCollection object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'V2PolicyResource') -> bool: + def __eq__(self, other: 'RoleCollection') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'V2PolicyResource') -> bool: + def __ne__(self, other: 'RoleCollection') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class V2PolicyResourceAttribute: +class Roles: """ - Resource attribute to which the policy grants access. + A role associated with a policy. - :attr str key: The name of a resource attribute. - :attr str operator: The operator of an attribute. - :attr object value: The value of a rule or resource attribute; can be boolean or - string for resource attribute. Can be string or an array of strings (e.g., array - of days to permit access) for rule attribute. + :attr str role_id: The role Cloud Resource Name (CRN) granted by the policy. + Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. """ - def __init__(self, key: str, operator: str, value: object) -> None: + def __init__( + self, + role_id: str, + ) -> None: """ - Initialize a V2PolicyResourceAttribute object. + Initialize a Roles object. - :param str key: The name of a resource attribute. - :param str operator: The operator of an attribute. - :param object value: The value of a rule or resource attribute; can be - boolean or string for resource attribute. Can be string or an array of - strings (e.g., array of days to permit access) for rule attribute. + :param str role_id: The role Cloud Resource Name (CRN) granted by the + policy. Example CRN: 'crn:v1:bluemix:public:iam::::role:Editor'. """ - self.key = key - self.operator = operator - self.value = value + self.role_id = role_id @classmethod - def from_dict(cls, _dict: Dict) -> 'V2PolicyResourceAttribute': - """Initialize a V2PolicyResourceAttribute object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'Roles': + """Initialize a Roles object from a json dictionary.""" args = {} - if 'key' in _dict: - args['key'] = _dict.get('key') - else: - raise ValueError('Required property \'key\' not present in V2PolicyResourceAttribute JSON') - if 'operator' in _dict: - args['operator'] = _dict.get('operator') - else: - raise ValueError('Required property \'operator\' not present in V2PolicyResourceAttribute JSON') - if 'value' in _dict: - args['value'] = _dict.get('value') + if 'role_id' in _dict: + args['role_id'] = _dict.get('role_id') else: - raise ValueError('Required property \'value\' not present in V2PolicyResourceAttribute JSON') + raise ValueError('Required property \'role_id\' not present in Roles JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a V2PolicyResourceAttribute object from a json dictionary.""" + """Initialize a Roles object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'key') and self.key is not None: - _dict['key'] = self.key - if hasattr(self, 'operator') and self.operator is not None: - _dict['operator'] = self.operator - if hasattr(self, 'value') and self.value is not None: - _dict['value'] = self.value + if hasattr(self, 'role_id') and self.role_id is not None: + _dict['role_id'] = self.role_id return _dict def _to_dict(self): @@ -2496,71 +5001,71 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this V2PolicyResourceAttribute object.""" + """Return a `str` version of this Roles object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'V2PolicyResourceAttribute') -> bool: + def __eq__(self, other: 'Roles') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'V2PolicyResourceAttribute') -> bool: + def __ne__(self, other: 'Roles') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other - class OperatorEnum(str, Enum): - """ - The operator of an attribute. - """ - - STRINGEQUALS = 'stringEquals' - STRINGEXISTS = 'stringExists' - STRINGMATCH = 'stringMatch' - -class V2PolicyResourceTag: +class RuleAttribute: """ - A tag associated with a resource. + Rule that specifies additional access granted (e.g., time-based condition). - :attr str key: The name of an access management tag. - :attr str value: The value of an access management tag. - :attr str operator: The operator of an access management tag. + :attr str key: The name of an attribute. + :attr str operator: The operator of an attribute. + :attr object value: The value of a rule or resource attribute; can be boolean or + string for resource attribute. Can be string or an array of strings (e.g., array + of days to permit access) for rule attribute. """ - def __init__(self, key: str, value: str, operator: str) -> None: + def __init__( + self, + key: str, + operator: str, + value: object, + ) -> None: """ - Initialize a V2PolicyResourceTag object. + Initialize a RuleAttribute object. - :param str key: The name of an access management tag. - :param str value: The value of an access management tag. - :param str operator: The operator of an access management tag. + :param str key: The name of an attribute. + :param str operator: The operator of an attribute. + :param object value: The value of a rule or resource attribute; can be + boolean or string for resource attribute. Can be string or an array of + strings (e.g., array of days to permit access) for rule attribute. """ self.key = key - self.value = value self.operator = operator + self.value = value @classmethod - def from_dict(cls, _dict: Dict) -> 'V2PolicyResourceTag': - """Initialize a V2PolicyResourceTag object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'RuleAttribute': + """Initialize a RuleAttribute object from a json dictionary.""" args = {} if 'key' in _dict: args['key'] = _dict.get('key') else: - raise ValueError('Required property \'key\' not present in V2PolicyResourceTag JSON') - if 'value' in _dict: - args['value'] = _dict.get('value') - else: - raise ValueError('Required property \'value\' not present in V2PolicyResourceTag JSON') + raise ValueError('Required property \'key\' not present in RuleAttribute JSON') if 'operator' in _dict: args['operator'] = _dict.get('operator') else: - raise ValueError('Required property \'operator\' not present in V2PolicyResourceTag JSON') + raise ValueError('Required property \'operator\' not present in RuleAttribute JSON') + if 'value' in _dict: + args['value'] = _dict.get('value') + else: + raise ValueError('Required property \'value\' not present in RuleAttribute JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a V2PolicyResourceTag object from a json dictionary.""" + """Initialize a RuleAttribute object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: @@ -2568,10 +5073,10 @@ def to_dict(self) -> Dict: _dict = {} if hasattr(self, 'key') and self.key is not None: _dict['key'] = self.key - if hasattr(self, 'value') and self.value is not None: - _dict['value'] = self.value if hasattr(self, 'operator') and self.operator is not None: _dict['operator'] = self.operator + if hasattr(self, 'value') and self.value is not None: + _dict['value'] = self.value return _dict def _to_dict(self): @@ -2579,88 +5084,84 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this V2PolicyResourceTag object.""" + """Return a `str` version of this RuleAttribute object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'V2PolicyResourceTag') -> bool: + def __eq__(self, other: 'RuleAttribute') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'V2PolicyResourceTag') -> bool: + def __ne__(self, other: 'RuleAttribute') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other class OperatorEnum(str, Enum): """ - The operator of an access management tag. - """ - - STRINGEQUALS = 'stringEquals' - STRINGMATCH = 'stringMatch' - - -class V2PolicyRule: - """ - Additional access conditions associated with the policy. - - """ - - def __init__(self) -> None: + The operator of an attribute. """ - Initialize a V2PolicyRule object. - """ - msg = "Cannot instantiate base class. Instead, instantiate one of the defined subclasses: {0}".format( - ", ".join(['V2PolicyRuleRuleAttribute', 'V2PolicyRuleRuleWithConditions']) - ) - raise Exception(msg) + TIMELESSTHAN = 'timeLessThan' + TIMELESSTHANOREQUALS = 'timeLessThanOrEquals' + TIMEGREATERTHAN = 'timeGreaterThan' + TIMEGREATERTHANOREQUALS = 'timeGreaterThanOrEquals' + DATETIMELESSTHAN = 'dateTimeLessThan' + DATETIMELESSTHANOREQUALS = 'dateTimeLessThanOrEquals' + DATETIMEGREATERTHAN = 'dateTimeGreaterThan' + DATETIMEGREATERTHANOREQUALS = 'dateTimeGreaterThanOrEquals' + DAYOFWEEKEQUALS = 'dayOfWeekEquals' + DAYOFWEEKANYOF = 'dayOfWeekAnyOf' -class V2PolicySubject: +class SubjectAttribute: """ - The subject attributes for whom the policy grants access. + An attribute associated with a subject. - :attr List[V2PolicySubjectAttribute] attributes: List of subject attributes - associated with policy/. + :attr str name: The name of an attribute. + :attr str value: The value of an attribute. """ - def __init__(self, attributes: List['V2PolicySubjectAttribute']) -> None: + def __init__( + self, + name: str, + value: str, + ) -> None: """ - Initialize a V2PolicySubject object. + Initialize a SubjectAttribute object. - :param List[V2PolicySubjectAttribute] attributes: List of subject - attributes associated with policy/. + :param str name: The name of an attribute. + :param str value: The value of an attribute. """ - self.attributes = attributes + self.name = name + self.value = value @classmethod - def from_dict(cls, _dict: Dict) -> 'V2PolicySubject': - """Initialize a V2PolicySubject object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'SubjectAttribute': + """Initialize a SubjectAttribute object from a json dictionary.""" args = {} - if 'attributes' in _dict: - args['attributes'] = [V2PolicySubjectAttribute.from_dict(v) for v in _dict.get('attributes')] + if 'name' in _dict: + args['name'] = _dict.get('name') else: - raise ValueError('Required property \'attributes\' not present in V2PolicySubject JSON') + raise ValueError('Required property \'name\' not present in SubjectAttribute JSON') + if 'value' in _dict: + args['value'] = _dict.get('value') + else: + raise ValueError('Required property \'value\' not present in SubjectAttribute JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a V2PolicySubject object from a json dictionary.""" + """Initialize a SubjectAttribute object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'attributes') and self.attributes is not None: - attributes_list = [] - for v in self.attributes: - if isinstance(v, dict): - attributes_list.append(v) - else: - attributes_list.append(v.to_dict()) - _dict['attributes'] = attributes_list + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'value') and self.value is not None: + _dict['value'] = self.value return _dict def _to_dict(self): @@ -2668,76 +5169,65 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this V2PolicySubject object.""" + """Return a `str` version of this SubjectAttribute object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'V2PolicySubject') -> bool: + def __eq__(self, other: 'SubjectAttribute') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'V2PolicySubject') -> bool: + def __ne__(self, other: 'SubjectAttribute') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class V2PolicySubjectAttribute: +class TemplateMetadata: """ - Subject attribute for whom the policy grants access. + Origin Template information. - :attr str key: The name of a subject attribute, e.g., iam_id, access_group_id. - :attr str operator: The operator of an attribute. - :attr str value: The value of the ID of the subject, e.g., service ID, access - group ID, IAM ID. + :attr str crn: (optional) Origin Template CRN. + :attr str version: (optional) Template version. """ - def __init__(self, key: str, operator: str, value: str) -> None: + def __init__( + self, + *, + crn: str = None, + version: str = None, + ) -> None: """ - Initialize a V2PolicySubjectAttribute object. + Initialize a TemplateMetadata object. - :param str key: The name of a subject attribute, e.g., iam_id, - access_group_id. - :param str operator: The operator of an attribute. - :param str value: The value of the ID of the subject, e.g., service ID, - access group ID, IAM ID. + :param str crn: (optional) Origin Template CRN. + :param str version: (optional) Template version. """ - self.key = key - self.operator = operator - self.value = value + self.crn = crn + self.version = version @classmethod - def from_dict(cls, _dict: Dict) -> 'V2PolicySubjectAttribute': - """Initialize a V2PolicySubjectAttribute object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'TemplateMetadata': + """Initialize a TemplateMetadata object from a json dictionary.""" args = {} - if 'key' in _dict: - args['key'] = _dict.get('key') - else: - raise ValueError('Required property \'key\' not present in V2PolicySubjectAttribute JSON') - if 'operator' in _dict: - args['operator'] = _dict.get('operator') - else: - raise ValueError('Required property \'operator\' not present in V2PolicySubjectAttribute JSON') - if 'value' in _dict: - args['value'] = _dict.get('value') - else: - raise ValueError('Required property \'value\' not present in V2PolicySubjectAttribute JSON') + if 'crn' in _dict: + args['crn'] = _dict.get('crn') + if 'version' in _dict: + args['version'] = _dict.get('version') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a V2PolicySubjectAttribute object from a json dictionary.""" + """Initialize a TemplateMetadata object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'key') and self.key is not None: - _dict['key'] = self.key - if hasattr(self, 'operator') and self.operator is not None: - _dict['operator'] = self.operator - if hasattr(self, 'value') and self.value is not None: - _dict['value'] = self.value + if hasattr(self, 'crn') and self.crn is not None: + _dict['crn'] = self.crn + if hasattr(self, 'version') and self.version is not None: + _dict['version'] = self.version return _dict def _to_dict(self): @@ -2745,176 +5235,124 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this V2PolicySubjectAttribute object.""" + """Return a `str` version of this TemplateMetadata object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'V2PolicySubjectAttribute') -> bool: + def __eq__(self, other: 'TemplateMetadata') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'V2PolicySubjectAttribute') -> bool: + def __ne__(self, other: 'TemplateMetadata') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other - class OperatorEnum(str, Enum): - """ - The operator of an attribute. - """ - - STRINGEQUALS = 'stringEquals' - -class CustomRole: +class TemplatePolicy: """ - An additional set of properties associated with a role. + The core set of properties associated with the template's policy objet. - :attr str id: (optional) The role ID. Composed of hexadecimal characters. - :attr str display_name: The display name of the role that is shown in the - console. - :attr str description: (optional) The description of the role. - :attr List[str] actions: The actions of the role. For more information, see [IAM - roles and - actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). - :attr str crn: (optional) The role Cloud Resource Name (CRN). Example CRN: - 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. - :attr str name: The name of the role that is used in the CRN. Can only be - alphanumeric and has to be capitalized. - :attr str account_id: The account GUID. - :attr str service_name: The service name. - :attr datetime created_at: (optional) The UTC timestamp when the role was - created. - :attr str created_by_id: (optional) The iam ID of the entity that created the - role. - :attr datetime last_modified_at: (optional) The UTC timestamp when the role was - last modified. - :attr str last_modified_by_id: (optional) The iam ID of the entity that last - modified the policy. - :attr str href: (optional) The href link back to the role. + :attr str type: The policy type; either 'access' or 'authorization'. + :attr str description: (optional) Description of the policy. This is shown in + child accounts when an access group or trusted profile template uses the policy + template to assign access. + :attr V2PolicyResource resource: The resource attributes to which the policy + grants access. + :attr str pattern: (optional) Indicates pattern of rule, either + 'time-based-conditions:once', 'time-based-conditions:weekly:all-day', or + 'time-based-conditions:weekly:custom-hours'. + :attr V2PolicyRule rule: (optional) Additional access conditions associated with + the policy. + :attr Control control: Specifies the type of access granted by the policy. """ def __init__( self, - display_name: str, - actions: List[str], - name: str, - account_id: str, - service_name: str, + type: str, + resource: 'V2PolicyResource', + control: 'Control', *, - id: str = None, description: str = None, - crn: str = None, - created_at: datetime = None, - created_by_id: str = None, - last_modified_at: datetime = None, - last_modified_by_id: str = None, - href: str = None + pattern: str = None, + rule: 'V2PolicyRule' = None, ) -> None: """ - Initialize a CustomRole object. + Initialize a TemplatePolicy object. - :param str display_name: The display name of the role that is shown in the - console. - :param List[str] actions: The actions of the role. For more information, - see [IAM roles and - actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). - :param str name: The name of the role that is used in the CRN. Can only be - alphanumeric and has to be capitalized. - :param str account_id: The account GUID. - :param str service_name: The service name. - :param str description: (optional) The description of the role. - """ - self.id = id - self.display_name = display_name - self.description = description - self.actions = actions - self.crn = crn - self.name = name - self.account_id = account_id - self.service_name = service_name - self.created_at = created_at - self.created_by_id = created_by_id - self.last_modified_at = last_modified_at - self.last_modified_by_id = last_modified_by_id - self.href = href + :param str type: The policy type; either 'access' or 'authorization'. + :param V2PolicyResource resource: The resource attributes to which the + policy grants access. + :param Control control: Specifies the type of access granted by the policy. + :param str description: (optional) Description of the policy. This is shown + in child accounts when an access group or trusted profile template uses the + policy template to assign access. + :param str pattern: (optional) Indicates pattern of rule, either + 'time-based-conditions:once', 'time-based-conditions:weekly:all-day', or + 'time-based-conditions:weekly:custom-hours'. + :param V2PolicyRule rule: (optional) Additional access conditions + associated with the policy. + """ + self.type = type + self.description = description + self.resource = resource + self.pattern = pattern + self.rule = rule + self.control = control @classmethod - def from_dict(cls, _dict: Dict) -> 'CustomRole': - """Initialize a CustomRole object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'TemplatePolicy': + """Initialize a TemplatePolicy object from a json dictionary.""" args = {} - if 'id' in _dict: - args['id'] = _dict.get('id') - if 'display_name' in _dict: - args['display_name'] = _dict.get('display_name') + if 'type' in _dict: + args['type'] = _dict.get('type') else: - raise ValueError('Required property \'display_name\' not present in CustomRole JSON') + raise ValueError('Required property \'type\' not present in TemplatePolicy JSON') if 'description' in _dict: args['description'] = _dict.get('description') - if 'actions' in _dict: - args['actions'] = _dict.get('actions') - else: - raise ValueError('Required property \'actions\' not present in CustomRole JSON') - if 'crn' in _dict: - args['crn'] = _dict.get('crn') - if 'name' in _dict: - args['name'] = _dict.get('name') - else: - raise ValueError('Required property \'name\' not present in CustomRole JSON') - if 'account_id' in _dict: - args['account_id'] = _dict.get('account_id') + if 'resource' in _dict: + args['resource'] = V2PolicyResource.from_dict(_dict.get('resource')) else: - raise ValueError('Required property \'account_id\' not present in CustomRole JSON') - if 'service_name' in _dict: - args['service_name'] = _dict.get('service_name') + raise ValueError('Required property \'resource\' not present in TemplatePolicy JSON') + if 'pattern' in _dict: + args['pattern'] = _dict.get('pattern') + if 'rule' in _dict: + args['rule'] = _dict.get('rule') + if 'control' in _dict: + args['control'] = Control.from_dict(_dict.get('control')) else: - raise ValueError('Required property \'service_name\' not present in CustomRole JSON') - if 'created_at' in _dict: - args['created_at'] = string_to_datetime(_dict.get('created_at')) - if 'created_by_id' in _dict: - args['created_by_id'] = _dict.get('created_by_id') - if 'last_modified_at' in _dict: - args['last_modified_at'] = string_to_datetime(_dict.get('last_modified_at')) - if 'last_modified_by_id' in _dict: - args['last_modified_by_id'] = _dict.get('last_modified_by_id') - if 'href' in _dict: - args['href'] = _dict.get('href') + raise ValueError('Required property \'control\' not present in TemplatePolicy JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a CustomRole object from a json dictionary.""" + """Initialize a TemplatePolicy object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'id') and getattr(self, 'id') is not None: - _dict['id'] = getattr(self, 'id') - if hasattr(self, 'display_name') and self.display_name is not None: - _dict['display_name'] = self.display_name + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type if hasattr(self, 'description') and self.description is not None: _dict['description'] = self.description - if hasattr(self, 'actions') and self.actions is not None: - _dict['actions'] = self.actions - if hasattr(self, 'crn') and getattr(self, 'crn') is not None: - _dict['crn'] = getattr(self, 'crn') - if hasattr(self, 'name') and self.name is not None: - _dict['name'] = self.name - if hasattr(self, 'account_id') and self.account_id is not None: - _dict['account_id'] = self.account_id - if hasattr(self, 'service_name') and self.service_name is not None: - _dict['service_name'] = self.service_name - if hasattr(self, 'created_at') and getattr(self, 'created_at') is not None: - _dict['created_at'] = datetime_to_string(getattr(self, 'created_at')) - if hasattr(self, 'created_by_id') and getattr(self, 'created_by_id') is not None: - _dict['created_by_id'] = getattr(self, 'created_by_id') - if hasattr(self, 'last_modified_at') and getattr(self, 'last_modified_at') is not None: - _dict['last_modified_at'] = datetime_to_string(getattr(self, 'last_modified_at')) - if hasattr(self, 'last_modified_by_id') and getattr(self, 'last_modified_by_id') is not None: - _dict['last_modified_by_id'] = getattr(self, 'last_modified_by_id') - if hasattr(self, 'href') and getattr(self, 'href') is not None: - _dict['href'] = getattr(self, 'href') + if hasattr(self, 'resource') and self.resource is not None: + if isinstance(self.resource, dict): + _dict['resource'] = self.resource + else: + _dict['resource'] = self.resource.to_dict() + if hasattr(self, 'pattern') and self.pattern is not None: + _dict['pattern'] = self.pattern + if hasattr(self, 'rule') and self.rule is not None: + if isinstance(self.rule, dict): + _dict['rule'] = self.rule + else: + _dict['rule'] = self.rule.to_dict() + if hasattr(self, 'control') and self.control is not None: + if isinstance(self.control, dict): + _dict['control'] = self.control + else: + _dict['control'] = self.control.to_dict() return _dict def _to_dict(self): @@ -2922,32 +5360,47 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this CustomRole object.""" + """Return a `str` version of this TemplatePolicy object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'CustomRole') -> bool: + def __eq__(self, other: 'TemplatePolicy') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'CustomRole') -> bool: + def __ne__(self, other: 'TemplatePolicy') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other + class TypeEnum(str, Enum): + """ + The policy type; either 'access' or 'authorization'. + """ -class Policy: + ACCESS = 'access' + AUTHORIZATION = 'authorization' + + +class V2Policy: """ - The core set of properties associated with a policy. + The core set of properties associated with the policy. - :attr str id: (optional) The policy ID. :attr str type: The policy type; either 'access' or 'authorization'. - :attr str description: (optional) Customer-defined description. - :attr List[PolicySubject] subjects: The subjects associated with a policy. - :attr List[PolicyRole] roles: A set of role cloud resource names (CRNs) granted - by the policy. - :attr List[PolicyResource] resources: The resources associated with a policy. - :attr str href: (optional) The href link back to the policy. + :attr str description: (optional) Description of the policy. + :attr V2PolicySubject subject: (optional) The subject attributes for whom the + policy grants access. + :attr V2PolicyResource resource: (optional) The resource attributes to which the + policy grants access. + :attr str pattern: (optional) Indicates pattern of rule, either + 'time-based-conditions:once', 'time-based-conditions:weekly:all-day', or + 'time-based-conditions:weekly:custom-hours'. + :attr V2PolicyRule rule: (optional) Additional access conditions associated with + the policy. + :attr str id: (optional) The policy ID. + :attr str href: (optional) The href URL that links to the policies API by policy + ID. + :attr ControlResponse control: :attr datetime created_at: (optional) The UTC timestamp when the policy was created. :attr str created_by_id: (optional) The iam ID of the entity that created the @@ -2956,76 +5409,103 @@ class Policy: was last modified. :attr str last_modified_by_id: (optional) The iam ID of the entity that last modified the policy. - :attr str state: (optional) The policy state. + :attr str state: The policy state, either 'deleted' or 'active'. + :attr str last_permit_at: (optional) The optional last permit time of policy, + when passing query parameter format=include_last_permit. + :attr int last_permit_frequency: (optional) The optional count of times that + policy has provided a permit, when passing query parameter + format=include_last_permit. + :attr TemplateMetadata template: (optional) Origin Template information. """ def __init__( self, type: str, - subjects: List['PolicySubject'], - roles: List['PolicyRole'], - resources: List['PolicyResource'], + control: 'ControlResponse', + state: str, *, - id: str = None, description: str = None, + subject: 'V2PolicySubject' = None, + resource: 'V2PolicyResource' = None, + pattern: str = None, + rule: 'V2PolicyRule' = None, + id: str = None, href: str = None, created_at: datetime = None, created_by_id: str = None, last_modified_at: datetime = None, last_modified_by_id: str = None, - state: str = None + last_permit_at: str = None, + last_permit_frequency: int = None, + template: 'TemplateMetadata' = None, ) -> None: """ - Initialize a Policy object. + Initialize a V2Policy object. :param str type: The policy type; either 'access' or 'authorization'. - :param List[PolicySubject] subjects: The subjects associated with a policy. - :param List[PolicyRole] roles: A set of role cloud resource names (CRNs) - granted by the policy. - :param List[PolicyResource] resources: The resources associated with a - policy. - :param str description: (optional) Customer-defined description. - :param str state: (optional) The policy state. + :param ControlResponse control: + :param str state: The policy state, either 'deleted' or 'active'. + :param str description: (optional) Description of the policy. + :param V2PolicySubject subject: (optional) The subject attributes for whom + the policy grants access. + :param V2PolicyResource resource: (optional) The resource attributes to + which the policy grants access. + :param str pattern: (optional) Indicates pattern of rule, either + 'time-based-conditions:once', 'time-based-conditions:weekly:all-day', or + 'time-based-conditions:weekly:custom-hours'. + :param V2PolicyRule rule: (optional) Additional access conditions + associated with the policy. + :param str last_permit_at: (optional) The optional last permit time of + policy, when passing query parameter format=include_last_permit. + :param int last_permit_frequency: (optional) The optional count of times + that policy has provided a permit, when passing query parameter + format=include_last_permit. + :param TemplateMetadata template: (optional) Origin Template information. """ - self.id = id self.type = type self.description = description - self.subjects = subjects - self.roles = roles - self.resources = resources + self.subject = subject + self.resource = resource + self.pattern = pattern + self.rule = rule + self.id = id self.href = href + self.control = control self.created_at = created_at self.created_by_id = created_by_id self.last_modified_at = last_modified_at self.last_modified_by_id = last_modified_by_id self.state = state + self.last_permit_at = last_permit_at + self.last_permit_frequency = last_permit_frequency + self.template = template @classmethod - def from_dict(cls, _dict: Dict) -> 'Policy': - """Initialize a Policy object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'V2Policy': + """Initialize a V2Policy object from a json dictionary.""" args = {} - if 'id' in _dict: - args['id'] = _dict.get('id') if 'type' in _dict: args['type'] = _dict.get('type') else: - raise ValueError('Required property \'type\' not present in Policy JSON') + raise ValueError('Required property \'type\' not present in V2Policy JSON') if 'description' in _dict: args['description'] = _dict.get('description') - if 'subjects' in _dict: - args['subjects'] = [PolicySubject.from_dict(v) for v in _dict.get('subjects')] - else: - raise ValueError('Required property \'subjects\' not present in Policy JSON') - if 'roles' in _dict: - args['roles'] = [PolicyRole.from_dict(v) for v in _dict.get('roles')] - else: - raise ValueError('Required property \'roles\' not present in Policy JSON') - if 'resources' in _dict: - args['resources'] = [PolicyResource.from_dict(v) for v in _dict.get('resources')] - else: - raise ValueError('Required property \'resources\' not present in Policy JSON') + if 'subject' in _dict: + args['subject'] = V2PolicySubject.from_dict(_dict.get('subject')) + if 'resource' in _dict: + args['resource'] = V2PolicyResource.from_dict(_dict.get('resource')) + if 'pattern' in _dict: + args['pattern'] = _dict.get('pattern') + if 'rule' in _dict: + args['rule'] = _dict.get('rule') + if 'id' in _dict: + args['id'] = _dict.get('id') if 'href' in _dict: args['href'] = _dict.get('href') + if 'control' in _dict: + args['control'] = _dict.get('control') + else: + raise ValueError('Required property \'control\' not present in V2Policy JSON') if 'created_at' in _dict: args['created_at'] = string_to_datetime(_dict.get('created_at')) if 'created_by_id' in _dict: @@ -3036,48 +5516,54 @@ def from_dict(cls, _dict: Dict) -> 'Policy': args['last_modified_by_id'] = _dict.get('last_modified_by_id') if 'state' in _dict: args['state'] = _dict.get('state') + else: + raise ValueError('Required property \'state\' not present in V2Policy JSON') + if 'last_permit_at' in _dict: + args['last_permit_at'] = _dict.get('last_permit_at') + if 'last_permit_frequency' in _dict: + args['last_permit_frequency'] = _dict.get('last_permit_frequency') + if 'template' in _dict: + args['template'] = TemplateMetadata.from_dict(_dict.get('template')) return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a Policy object from a json dictionary.""" + """Initialize a V2Policy object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'id') and getattr(self, 'id') is not None: - _dict['id'] = getattr(self, 'id') if hasattr(self, 'type') and self.type is not None: _dict['type'] = self.type if hasattr(self, 'description') and self.description is not None: _dict['description'] = self.description - if hasattr(self, 'subjects') and self.subjects is not None: - subjects_list = [] - for v in self.subjects: - if isinstance(v, dict): - subjects_list.append(v) - else: - subjects_list.append(v.to_dict()) - _dict['subjects'] = subjects_list - if hasattr(self, 'roles') and self.roles is not None: - roles_list = [] - for v in self.roles: - if isinstance(v, dict): - roles_list.append(v) - else: - roles_list.append(v.to_dict()) - _dict['roles'] = roles_list - if hasattr(self, 'resources') and self.resources is not None: - resources_list = [] - for v in self.resources: - if isinstance(v, dict): - resources_list.append(v) - else: - resources_list.append(v.to_dict()) - _dict['resources'] = resources_list + if hasattr(self, 'subject') and self.subject is not None: + if isinstance(self.subject, dict): + _dict['subject'] = self.subject + else: + _dict['subject'] = self.subject.to_dict() + if hasattr(self, 'resource') and self.resource is not None: + if isinstance(self.resource, dict): + _dict['resource'] = self.resource + else: + _dict['resource'] = self.resource.to_dict() + if hasattr(self, 'pattern') and self.pattern is not None: + _dict['pattern'] = self.pattern + if hasattr(self, 'rule') and self.rule is not None: + if isinstance(self.rule, dict): + _dict['rule'] = self.rule + else: + _dict['rule'] = self.rule.to_dict() + if hasattr(self, 'id') and getattr(self, 'id') is not None: + _dict['id'] = getattr(self, 'id') if hasattr(self, 'href') and getattr(self, 'href') is not None: _dict['href'] = getattr(self, 'href') + if hasattr(self, 'control') and self.control is not None: + if isinstance(self.control, dict): + _dict['control'] = self.control + else: + _dict['control'] = self.control.to_dict() if hasattr(self, 'created_at') and getattr(self, 'created_at') is not None: _dict['created_at'] = datetime_to_string(getattr(self, 'created_at')) if hasattr(self, 'created_by_id') and getattr(self, 'created_by_id') is not None: @@ -3088,6 +5574,15 @@ def to_dict(self) -> Dict: _dict['last_modified_by_id'] = getattr(self, 'last_modified_by_id') if hasattr(self, 'state') and self.state is not None: _dict['state'] = self.state + if hasattr(self, 'last_permit_at') and self.last_permit_at is not None: + _dict['last_permit_at'] = self.last_permit_at + if hasattr(self, 'last_permit_frequency') and self.last_permit_frequency is not None: + _dict['last_permit_frequency'] = self.last_permit_frequency + if hasattr(self, 'template') and self.template is not None: + if isinstance(self.template, dict): + _dict['template'] = self.template + else: + _dict['template'] = self.template.to_dict() return _dict def _to_dict(self): @@ -3095,54 +5590,66 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this Policy object.""" + """Return a `str` version of this V2Policy object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'Policy') -> bool: + def __eq__(self, other: 'V2Policy') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'Policy') -> bool: + def __ne__(self, other: 'V2Policy') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other + class TypeEnum(str, Enum): + """ + The policy type; either 'access' or 'authorization'. + """ + + ACCESS = 'access' + AUTHORIZATION = 'authorization' + class StateEnum(str, Enum): """ - The policy state. + The policy state, either 'deleted' or 'active'. """ ACTIVE = 'active' DELETED = 'deleted' -class PolicyList: +class V2PolicyCollection: """ A collection of policies. - :attr List[Policy] policies: (optional) List of policies. + :attr List[V2Policy] policies: (optional) List of policies. """ - def __init__(self, *, policies: List['Policy'] = None) -> None: + def __init__( + self, + *, + policies: List['V2Policy'] = None, + ) -> None: """ - Initialize a PolicyList object. + Initialize a V2PolicyCollection object. - :param List[Policy] policies: (optional) List of policies. + :param List[V2Policy] policies: (optional) List of policies. """ self.policies = policies @classmethod - def from_dict(cls, _dict: Dict) -> 'PolicyList': - """Initialize a PolicyList object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'V2PolicyCollection': + """Initialize a V2PolicyCollection object from a json dictionary.""" args = {} if 'policies' in _dict: - args['policies'] = [Policy.from_dict(v) for v in _dict.get('policies')] + args['policies'] = [V2Policy.from_dict(v) for v in _dict.get('policies')] return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a PolicyList object from a json dictionary.""" + """Initialize a V2PolicyCollection object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: @@ -3163,53 +5670,62 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this PolicyList object.""" + """Return a `str` version of this V2PolicyCollection object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'PolicyList') -> bool: + def __eq__(self, other: 'V2PolicyCollection') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'PolicyList') -> bool: + def __ne__(self, other: 'V2PolicyCollection') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class PolicyResource: +class V2PolicyResource: """ - The attributes of the resource. Note that only one resource is allowed in a policy. + The resource attributes to which the policy grants access. - :attr List[ResourceAttribute] attributes: (optional) List of resource - attributes. - :attr List[ResourceTag] tags: (optional) List of access management tags. + :attr List[V2PolicyResourceAttribute] attributes: List of resource attributes to + which the policy grants access. + :attr List[V2PolicyResourceTag] tags: (optional) Optional list of resource tags + to which the policy grants access. """ - def __init__(self, *, attributes: List['ResourceAttribute'] = None, tags: List['ResourceTag'] = None) -> None: + def __init__( + self, + attributes: List['V2PolicyResourceAttribute'], + *, + tags: List['V2PolicyResourceTag'] = None, + ) -> None: """ - Initialize a PolicyResource object. + Initialize a V2PolicyResource object. - :param List[ResourceAttribute] attributes: (optional) List of resource - attributes. - :param List[ResourceTag] tags: (optional) List of access management tags. + :param List[V2PolicyResourceAttribute] attributes: List of resource + attributes to which the policy grants access. + :param List[V2PolicyResourceTag] tags: (optional) Optional list of resource + tags to which the policy grants access. """ self.attributes = attributes self.tags = tags @classmethod - def from_dict(cls, _dict: Dict) -> 'PolicyResource': - """Initialize a PolicyResource object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'V2PolicyResource': + """Initialize a V2PolicyResource object from a json dictionary.""" args = {} if 'attributes' in _dict: - args['attributes'] = [ResourceAttribute.from_dict(v) for v in _dict.get('attributes')] + args['attributes'] = [V2PolicyResourceAttribute.from_dict(v) for v in _dict.get('attributes')] + else: + raise ValueError('Required property \'attributes\' not present in V2PolicyResource JSON') if 'tags' in _dict: - args['tags'] = [ResourceTag.from_dict(v) for v in _dict.get('tags')] + args['tags'] = [V2PolicyResourceTag.from_dict(v) for v in _dict.get('tags')] return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a PolicyResource object from a json dictionary.""" + """Initialize a V2PolicyResource object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: @@ -3238,133 +5754,82 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this PolicyResource object.""" - return json.dumps(self.to_dict(), indent=2) - - def __eq__(self, other: 'PolicyResource') -> bool: - """Return `true` when self and other are equal, false otherwise.""" - if not isinstance(other, self.__class__): - return False - return self.__dict__ == other.__dict__ - - def __ne__(self, other: 'PolicyResource') -> bool: - """Return `true` when self and other are not equal, false otherwise.""" - return not self == other - - -class PolicySubject: - """ - The subject attribute values that must match in order for this policy to apply in a - permission decision. - - :attr List[SubjectAttribute] attributes: (optional) List of subject attributes. - """ - - def __init__(self, *, attributes: List['SubjectAttribute'] = None) -> None: - """ - Initialize a PolicySubject object. - - :param List[SubjectAttribute] attributes: (optional) List of subject - attributes. - """ - self.attributes = attributes - - @classmethod - def from_dict(cls, _dict: Dict) -> 'PolicySubject': - """Initialize a PolicySubject object from a json dictionary.""" - args = {} - if 'attributes' in _dict: - args['attributes'] = [SubjectAttribute.from_dict(v) for v in _dict.get('attributes')] - return cls(**args) - - @classmethod - def _from_dict(cls, _dict): - """Initialize a PolicySubject object from a json dictionary.""" - return cls.from_dict(_dict) - - def to_dict(self) -> Dict: - """Return a json dictionary representing this model.""" - _dict = {} - if hasattr(self, 'attributes') and self.attributes is not None: - attributes_list = [] - for v in self.attributes: - if isinstance(v, dict): - attributes_list.append(v) - else: - attributes_list.append(v.to_dict()) - _dict['attributes'] = attributes_list - return _dict - - def _to_dict(self): - """Return a json dictionary representing this model.""" - return self.to_dict() - - def __str__(self) -> str: - """Return a `str` version of this PolicySubject object.""" + """Return a `str` version of this V2PolicyResource object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'PolicySubject') -> bool: + def __eq__(self, other: 'V2PolicyResource') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'PolicySubject') -> bool: + def __ne__(self, other: 'V2PolicyResource') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class ResourceAttribute: +class V2PolicyResourceAttribute: """ - An attribute associated with a resource. + Resource attribute to which the policy grants access. - :attr str name: The name of an attribute. - :attr str value: The value of an attribute. - :attr str operator: (optional) The operator of an attribute. + :attr str key: The name of a resource attribute. + :attr str operator: The operator of an attribute. + :attr object value: The value of a rule or resource attribute; can be boolean or + string for resource attribute. Can be string or an array of strings (e.g., array + of days to permit access) for rule attribute. """ - def __init__(self, name: str, value: str, *, operator: str = None) -> None: + def __init__( + self, + key: str, + operator: str, + value: object, + ) -> None: """ - Initialize a ResourceAttribute object. + Initialize a V2PolicyResourceAttribute object. - :param str name: The name of an attribute. - :param str value: The value of an attribute. - :param str operator: (optional) The operator of an attribute. + :param str key: The name of a resource attribute. + :param str operator: The operator of an attribute. + :param object value: The value of a rule or resource attribute; can be + boolean or string for resource attribute. Can be string or an array of + strings (e.g., array of days to permit access) for rule attribute. """ - self.name = name - self.value = value + self.key = key self.operator = operator + self.value = value @classmethod - def from_dict(cls, _dict: Dict) -> 'ResourceAttribute': - """Initialize a ResourceAttribute object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'V2PolicyResourceAttribute': + """Initialize a V2PolicyResourceAttribute object from a json dictionary.""" args = {} - if 'name' in _dict: - args['name'] = _dict.get('name') + if 'key' in _dict: + args['key'] = _dict.get('key') else: - raise ValueError('Required property \'name\' not present in ResourceAttribute JSON') + raise ValueError('Required property \'key\' not present in V2PolicyResourceAttribute JSON') + if 'operator' in _dict: + args['operator'] = _dict.get('operator') + else: + raise ValueError('Required property \'operator\' not present in V2PolicyResourceAttribute JSON') if 'value' in _dict: args['value'] = _dict.get('value') else: - raise ValueError('Required property \'value\' not present in ResourceAttribute JSON') - if 'operator' in _dict: - args['operator'] = _dict.get('operator') + raise ValueError('Required property \'value\' not present in V2PolicyResourceAttribute JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a ResourceAttribute object from a json dictionary.""" + """Initialize a V2PolicyResourceAttribute object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'name') and self.name is not None: - _dict['name'] = self.name - if hasattr(self, 'value') and self.value is not None: - _dict['value'] = self.value + if hasattr(self, 'key') and self.key is not None: + _dict['key'] = self.key if hasattr(self, 'operator') and self.operator is not None: _dict['operator'] = self.operator + if hasattr(self, 'value') and self.value is not None: + _dict['value'] = self.value return _dict def _to_dict(self): @@ -3372,67 +5837,83 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this ResourceAttribute object.""" + """Return a `str` version of this V2PolicyResourceAttribute object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'ResourceAttribute') -> bool: + def __eq__(self, other: 'V2PolicyResourceAttribute') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'ResourceAttribute') -> bool: + def __ne__(self, other: 'V2PolicyResourceAttribute') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other + class OperatorEnum(str, Enum): + """ + The operator of an attribute. + """ + + STRINGEQUALS = 'stringEquals' + STRINGEXISTS = 'stringExists' + STRINGMATCH = 'stringMatch' + -class ResourceTag: +class V2PolicyResourceTag: """ A tag associated with a resource. - :attr str name: The name of an access management tag. + :attr str key: The name of an access management tag. :attr str value: The value of an access management tag. - :attr str operator: (optional) The operator of an access management tag. + :attr str operator: The operator of an access management tag. """ - def __init__(self, name: str, value: str, *, operator: str = None) -> None: + def __init__( + self, + key: str, + value: str, + operator: str, + ) -> None: """ - Initialize a ResourceTag object. + Initialize a V2PolicyResourceTag object. - :param str name: The name of an access management tag. + :param str key: The name of an access management tag. :param str value: The value of an access management tag. - :param str operator: (optional) The operator of an access management tag. + :param str operator: The operator of an access management tag. """ - self.name = name + self.key = key self.value = value self.operator = operator @classmethod - def from_dict(cls, _dict: Dict) -> 'ResourceTag': - """Initialize a ResourceTag object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'V2PolicyResourceTag': + """Initialize a V2PolicyResourceTag object from a json dictionary.""" args = {} - if 'name' in _dict: - args['name'] = _dict.get('name') + if 'key' in _dict: + args['key'] = _dict.get('key') else: - raise ValueError('Required property \'name\' not present in ResourceTag JSON') + raise ValueError('Required property \'key\' not present in V2PolicyResourceTag JSON') if 'value' in _dict: args['value'] = _dict.get('value') else: - raise ValueError('Required property \'value\' not present in ResourceTag JSON') + raise ValueError('Required property \'value\' not present in V2PolicyResourceTag JSON') if 'operator' in _dict: args['operator'] = _dict.get('operator') + else: + raise ValueError('Required property \'operator\' not present in V2PolicyResourceTag JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a ResourceTag object from a json dictionary.""" + """Initialize a V2PolicyResourceTag object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'name') and self.name is not None: - _dict['name'] = self.name + if hasattr(self, 'key') and self.key is not None: + _dict['key'] = self.key if hasattr(self, 'value') and self.value is not None: _dict['value'] = self.value if hasattr(self, 'operator') and self.operator is not None: @@ -3444,176 +5925,93 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this ResourceTag object.""" + """Return a `str` version of this V2PolicyResourceTag object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'ResourceTag') -> bool: + def __eq__(self, other: 'V2PolicyResourceTag') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'ResourceTag') -> bool: + def __ne__(self, other: 'V2PolicyResourceTag') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other - -class Role: - """ - A role resource. - - :attr str display_name: The display name of the role that is shown in the - console. - :attr str description: (optional) The description of the role. - :attr List[str] actions: The actions of the role. For more information, see [IAM - roles and - actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). - :attr str crn: (optional) The role Cloud Resource Name (CRN). Example CRN: - 'crn:v1:ibmcloud:public:iam-access-management::a/exampleAccountId::customRole:ExampleRoleName'. - """ - - def __init__(self, display_name: str, actions: List[str], *, description: str = None, crn: str = None) -> None: + class OperatorEnum(str, Enum): """ - Initialize a Role object. - - :param str display_name: The display name of the role that is shown in the - console. - :param List[str] actions: The actions of the role. For more information, - see [IAM roles and - actions](https://cloud.ibm.com/docs/account?topic=account-iam-service-roles-actions). - :param str description: (optional) The description of the role. + The operator of an access management tag. """ - self.display_name = display_name - self.description = description - self.actions = actions - self.crn = crn - - @classmethod - def from_dict(cls, _dict: Dict) -> 'Role': - """Initialize a Role object from a json dictionary.""" - args = {} - if 'display_name' in _dict: - args['display_name'] = _dict.get('display_name') - else: - raise ValueError('Required property \'display_name\' not present in Role JSON') - if 'description' in _dict: - args['description'] = _dict.get('description') - if 'actions' in _dict: - args['actions'] = _dict.get('actions') - else: - raise ValueError('Required property \'actions\' not present in Role JSON') - if 'crn' in _dict: - args['crn'] = _dict.get('crn') - return cls(**args) - @classmethod - def _from_dict(cls, _dict): - """Initialize a Role object from a json dictionary.""" - return cls.from_dict(_dict) + STRINGEQUALS = 'stringEquals' + STRINGMATCH = 'stringMatch' - def to_dict(self) -> Dict: - """Return a json dictionary representing this model.""" - _dict = {} - if hasattr(self, 'display_name') and self.display_name is not None: - _dict['display_name'] = self.display_name - if hasattr(self, 'description') and self.description is not None: - _dict['description'] = self.description - if hasattr(self, 'actions') and self.actions is not None: - _dict['actions'] = self.actions - if hasattr(self, 'crn') and getattr(self, 'crn') is not None: - _dict['crn'] = getattr(self, 'crn') - return _dict - def _to_dict(self): - """Return a json dictionary representing this model.""" - return self.to_dict() +class V2PolicyRule: + """ + Additional access conditions associated with the policy. - def __str__(self) -> str: - """Return a `str` version of this Role object.""" - return json.dumps(self.to_dict(), indent=2) + """ - def __eq__(self, other: 'Role') -> bool: - """Return `true` when self and other are equal, false otherwise.""" - if not isinstance(other, self.__class__): - return False - return self.__dict__ == other.__dict__ + def __init__( + self, + ) -> None: + """ + Initialize a V2PolicyRule object. - def __ne__(self, other: 'Role') -> bool: - """Return `true` when self and other are not equal, false otherwise.""" - return not self == other + """ + msg = "Cannot instantiate base class. Instead, instantiate one of the defined subclasses: {0}".format( + ", ".join(['V2PolicyRuleRuleAttribute', 'V2PolicyRuleRuleWithConditions']) + ) + raise Exception(msg) -class RoleList: +class V2PolicySubject: """ - A collection of roles returned by the 'list roles' operation. + The subject attributes for whom the policy grants access. - :attr List[CustomRole] custom_roles: (optional) List of custom roles. - :attr List[Role] service_roles: (optional) List of service roles. - :attr List[Role] system_roles: (optional) List of system roles. + :attr List[V2PolicySubjectAttribute] attributes: List of subject attributes + associated with policy/. """ def __init__( self, - *, - custom_roles: List['CustomRole'] = None, - service_roles: List['Role'] = None, - system_roles: List['Role'] = None + attributes: List['V2PolicySubjectAttribute'], ) -> None: """ - Initialize a RoleList object. + Initialize a V2PolicySubject object. - :param List[CustomRole] custom_roles: (optional) List of custom roles. - :param List[Role] service_roles: (optional) List of service roles. - :param List[Role] system_roles: (optional) List of system roles. + :param List[V2PolicySubjectAttribute] attributes: List of subject + attributes associated with policy/. """ - self.custom_roles = custom_roles - self.service_roles = service_roles - self.system_roles = system_roles + self.attributes = attributes @classmethod - def from_dict(cls, _dict: Dict) -> 'RoleList': - """Initialize a RoleList object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'V2PolicySubject': + """Initialize a V2PolicySubject object from a json dictionary.""" args = {} - if 'custom_roles' in _dict: - args['custom_roles'] = [CustomRole.from_dict(v) for v in _dict.get('custom_roles')] - if 'service_roles' in _dict: - args['service_roles'] = [Role.from_dict(v) for v in _dict.get('service_roles')] - if 'system_roles' in _dict: - args['system_roles'] = [Role.from_dict(v) for v in _dict.get('system_roles')] + if 'attributes' in _dict: + args['attributes'] = [V2PolicySubjectAttribute.from_dict(v) for v in _dict.get('attributes')] + else: + raise ValueError('Required property \'attributes\' not present in V2PolicySubject JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a RoleList object from a json dictionary.""" + """Initialize a V2PolicySubject object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'custom_roles') and self.custom_roles is not None: - custom_roles_list = [] - for v in self.custom_roles: - if isinstance(v, dict): - custom_roles_list.append(v) - else: - custom_roles_list.append(v.to_dict()) - _dict['custom_roles'] = custom_roles_list - if hasattr(self, 'service_roles') and self.service_roles is not None: - service_roles_list = [] - for v in self.service_roles: - if isinstance(v, dict): - service_roles_list.append(v) - else: - service_roles_list.append(v.to_dict()) - _dict['service_roles'] = service_roles_list - if hasattr(self, 'system_roles') and self.system_roles is not None: - system_roles_list = [] - for v in self.system_roles: + if hasattr(self, 'attributes') and self.attributes is not None: + attributes_list = [] + for v in self.attributes: if isinstance(v, dict): - system_roles_list.append(v) + attributes_list.append(v) else: - system_roles_list.append(v.to_dict()) - _dict['system_roles'] = system_roles_list + attributes_list.append(v.to_dict()) + _dict['attributes'] = attributes_list return _dict def _to_dict(self): @@ -3621,62 +6019,79 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this RoleList object.""" + """Return a `str` version of this V2PolicySubject object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'RoleList') -> bool: + def __eq__(self, other: 'V2PolicySubject') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'RoleList') -> bool: + def __ne__(self, other: 'V2PolicySubject') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class SubjectAttribute: +class V2PolicySubjectAttribute: """ - An attribute associated with a subject. + Subject attribute for whom the policy grants access. - :attr str name: The name of an attribute. - :attr str value: The value of an attribute. + :attr str key: The name of a subject attribute, e.g., iam_id, access_group_id. + :attr str operator: The operator of an attribute. + :attr str value: The value of the ID of the subject, e.g., service ID, access + group ID, IAM ID. """ - def __init__(self, name: str, value: str) -> None: + def __init__( + self, + key: str, + operator: str, + value: str, + ) -> None: """ - Initialize a SubjectAttribute object. + Initialize a V2PolicySubjectAttribute object. - :param str name: The name of an attribute. - :param str value: The value of an attribute. + :param str key: The name of a subject attribute, e.g., iam_id, + access_group_id. + :param str operator: The operator of an attribute. + :param str value: The value of the ID of the subject, e.g., service ID, + access group ID, IAM ID. """ - self.name = name + self.key = key + self.operator = operator self.value = value @classmethod - def from_dict(cls, _dict: Dict) -> 'SubjectAttribute': - """Initialize a SubjectAttribute object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'V2PolicySubjectAttribute': + """Initialize a V2PolicySubjectAttribute object from a json dictionary.""" args = {} - if 'name' in _dict: - args['name'] = _dict.get('name') + if 'key' in _dict: + args['key'] = _dict.get('key') else: - raise ValueError('Required property \'name\' not present in SubjectAttribute JSON') + raise ValueError('Required property \'key\' not present in V2PolicySubjectAttribute JSON') + if 'operator' in _dict: + args['operator'] = _dict.get('operator') + else: + raise ValueError('Required property \'operator\' not present in V2PolicySubjectAttribute JSON') if 'value' in _dict: args['value'] = _dict.get('value') else: - raise ValueError('Required property \'value\' not present in SubjectAttribute JSON') + raise ValueError('Required property \'value\' not present in V2PolicySubjectAttribute JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a SubjectAttribute object from a json dictionary.""" + """Initialize a V2PolicySubjectAttribute object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'name') and self.name is not None: - _dict['name'] = self.name + if hasattr(self, 'key') and self.key is not None: + _dict['key'] = self.key + if hasattr(self, 'operator') and self.operator is not None: + _dict['operator'] = self.operator if hasattr(self, 'value') and self.value is not None: _dict['value'] = self.value return _dict @@ -3686,19 +6101,26 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this SubjectAttribute object.""" + """Return a `str` version of this V2PolicySubjectAttribute object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'SubjectAttribute') -> bool: + def __eq__(self, other: 'V2PolicySubjectAttribute') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'SubjectAttribute') -> bool: + def __ne__(self, other: 'V2PolicySubjectAttribute') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other + class OperatorEnum(str, Enum): + """ + The operator of an attribute. + """ + + STRINGEQUALS = 'stringEquals' + class ControlResponseControl(ControlResponse): """ @@ -3707,7 +6129,10 @@ class ControlResponseControl(ControlResponse): :attr Grant grant: Permission granted by the policy. """ - def __init__(self, grant: 'Grant') -> None: + def __init__( + self, + grant: 'Grant', + ) -> None: """ Initialize a ControlResponseControl object. @@ -3768,7 +6193,10 @@ class ControlResponseControlWithEnrichedRoles(ControlResponse): translated roles and additional role information. """ - def __init__(self, grant: 'GrantWithEnrichedRoles') -> None: + def __init__( + self, + grant: 'GrantWithEnrichedRoles', + ) -> None: """ Initialize a ControlResponseControlWithEnrichedRoles object. @@ -3833,7 +6261,12 @@ class V2PolicyRuleRuleAttribute(V2PolicyRule): of days to permit access) for rule attribute. """ - def __init__(self, key: str, operator: str, value: object) -> None: + def __init__( + self, + key: str, + operator: str, + value: object, + ) -> None: """ Initialize a V2PolicyRuleRuleAttribute object. @@ -3928,7 +6361,11 @@ class V2PolicyRuleRuleWithConditions(V2PolicyRule): period. """ - def __init__(self, operator: str, conditions: List['RuleAttribute']) -> None: + def __init__( + self, + operator: str, + conditions: List['RuleAttribute'], + ) -> None: """ Initialize a V2PolicyRuleRuleWithConditions object. diff --git a/test/integration/test_iam_policy_management_v1.py b/test/integration/test_iam_policy_management_v1.py index c7e3b22a..754bffc0 100644 --- a/test/integration/test_iam_policy_management_v1.py +++ b/test/integration/test_iam_policy_management_v1.py @@ -116,6 +116,25 @@ def setUpClass(cls): actions=['iam-groups.groups.read'], ) + cls.testTemplateId = "" + cls.testTemplateETag = "" + cls.testTemplateVersion = "" + cls.testNewTemplateVersion = "" + cls.testAssignmentId = "" + cls.testV2PolicyTemplateResource = V2PolicyResource( + attributes=[ + V2PolicyResourceAttribute(key='serviceName', value='watson', operator='stringEquals'), + ], + ) + cls.testTemplatePolicy = TemplatePolicy( + type='access', + control=cls.testV2PolicyControl, + resource=cls.testV2PolicyTemplateResource, + description='SDK Test Policy', + ) + cls.testTemplatePrefix = 'SDKPython' + cls.testTemplateName = cls.testTemplatePrefix + str(random.randint(0, 99999)) + print('\nSetup complete.') @classmethod @@ -130,7 +149,7 @@ def tearDownClass(cls): result_dict = response.get_result() assert result_dict is not None - result = PolicyList.from_dict(result_dict) + result = PolicyCollection.from_dict(result_dict) assert result is not None # Iterate across the policies @@ -155,6 +174,27 @@ def tearDownClass(cls): assert response is not None assert response.get_status_code() == 204 + # Delete all the policy templates that we created during the test. + # + # List all policy templates in the account + response = cls.service.list_policy_templates(account_id=cls.testAccountId) + assert response is not None + assert response.get_status_code() == 200 + + result_dict = response.get_result() + assert result_dict is not None + + result = PolicyTemplateCollection.from_dict(result_dict) + assert result is not None + + for template in result.policy_templates: + now = datetime.now(timezone.utc) + minutesDifference = (now - policy.created_at).seconds / 60 + if cls.testTemplatePrefix in template.name and (template.id == cls.testTemplateId or minutesDifference < 5): + response = cls.service.delete_policy_template(policy_template_id=template.id) + assert response is not None + assert response.get_status_code() == 204 + print('\nClean up complete.') def test_00_account_id(self): @@ -244,7 +284,7 @@ def test_04_list_access_policies(self): result_dict = response.get_result() assert result_dict is not None - result = PolicyList.from_dict(result_dict) + result = PolicyCollection.from_dict(result_dict) assert result is not None print("Policy list: ", result) @@ -344,7 +384,7 @@ def test_08_list_custom_roles(self): result_dict = response.get_result() assert result_dict is not None - result = RoleList.from_dict(result_dict) + result = RoleCollection.from_dict(result_dict) assert result is not None print("Custom roles list: ", result) @@ -461,6 +501,9 @@ def test_12_update_v2_access_policy(self): self.__class__.testPolicyETag = response.get_headers().get(self.etagHeader) + # Set role_id back to default + self.testV2PolicyControl.grant.roles[0].role_id = self.testViewerRoleCrn + def test_13_list_v2_access_policies(self): print("Policy ID: ", self.testPolicyId) @@ -493,7 +536,7 @@ def test_14_list_v2_roles(self): result_dict = response.get_result() assert result_dict is not None - result = RoleList.from_dict(result_dict) + result = RoleCollection.from_dict(result_dict) assert result is not None print("List roles: ", result) @@ -511,3 +554,214 @@ def test_14_list_v2_roles(self): testServiceRolePresent = True break assert testServiceRolePresent + + def test_15_create_policy_template(self): + + response = self.service.create_policy_template( + name=self.testTemplateName, + account_id=self.testAccountId, + policy=self.testTemplatePolicy, + description='SDK Test Policy Template', + ) + assert response is not None + + assert response.get_status_code() == 201 + + result_dict = response.get_result() + assert result_dict is not None + + result = PolicyTemplate.from_dict(result_dict) + assert result is not None + + self.__class__.testTemplateId = result.id + self.__class__.testTemplateVersion = result.version + + def test_16_get_policy_template(self): + assert self.testTemplateId + print("Policy Tempate ID: ", self.testTemplateId) + + response = self.service.get_policy_template( + policy_template_id=self.testTemplateId, + ) + assert response is not None + assert response.get_status_code() == 200 + + result_dict = response.get_result() + assert result_dict is not None + + result = PolicyTemplate.from_dict(result_dict) + assert result is not None + + self.__class__.testTemplateETag = response.get_headers().get(self.etagHeader) + + def test_17_replace_policy_template(self): + assert self.testTemplateId + assert self.testTemplateETag + assert self.testTemplateVersion + + print("Policy Tempate ID: ", self.testTemplateId) + self.testV2PolicyControl.grant.roles[0].role_id = self.testEditorRoleCrn + + updated_template_description = 'SDK Updated Test Policy Template' + response = self.service.replace_policy_template( + policy_template_id=self.testTemplateId, + version=self.testTemplateVersion, + if_match=self.testTemplateETag, + policy=self.testTemplatePolicy, + description=updated_template_description, + ) + + result_dict = response.get_result() + assert result_dict is not None + + result = PolicyTemplate.from_dict(result_dict) + assert result is not None + assert result.description == updated_template_description + + def test_18_list_policy_templates(self): + response = self.service.list_policy_templates( + account_id=self.testAccountId, + accept_language='default', + ) + + assert response.get_status_code() == 200 + result_dict = response.get_result() + assert result_dict is not None + + result = PolicyTemplateCollection.from_dict(result_dict) + + print("Policy Template list: ", result) + + # Confirm the test policy template is present + foundTestTemplate = False + for policy_template in result.policy_templates: + if policy_template.id == self.testTemplateId: + foundTestTemplate = True + break + assert foundTestTemplate + + def test_19_create_policy_template_version(self): + + self.testV2PolicyControl.grant.roles[0].role_id = self.testViewerRoleCrn + response = self.service.create_policy_template_version( + policy_template_id=self.testTemplateId, + policy=self.testTemplatePolicy, + description='SDK New Test Policy Template', + ) + + assert response.get_status_code() == 201 + result_dict = response.get_result() + assert result_dict is not None + result = PolicyTemplate.from_dict(result_dict) + assert result is not None + + assert result.version > self.testTemplateVersion + self.__class__.testNewTemplateVersion = result.version + + def test_20_get_policy_template_version(self): + response = self.service.get_policy_template_version( + policy_template_id=self.testTemplateId, + version=self.testNewTemplateVersion, + ) + + assert response.get_status_code() == 200 + result_dict = response.get_result() + assert result_dict is not None + + self.__class__.testTemplateETag = response.get_headers().get(self.etagHeader) + + def test_21_commit_policy_template(self): + response = self.service.commit_policy_template( + policy_template_id=self.testTemplateId, + version=self.testTemplateVersion, + if_match=self.testTemplateETag, + ) + + assert response.get_status_code() == 204 + + response = self.service.get_policy_template_version( + policy_template_id=self.testTemplateId, + version=self.testTemplateVersion, + ) + + assert response.get_status_code() == 200 + self.__class__.testTemplateETag = response.get_headers().get(self.etagHeader) + assert self.testTemplateETag is not None + + # Now that policy template is committed, should fail to update version + try: + response = self.service.replace_policy_template( + policy_template_id=self.testTemplateId, + version=self.testTemplateVersion, + if_match=self.testTemplateETag, + policy=self.testTemplatePolicy, + description='SDK Fail to Update Committed Version', + ) + except ApiException as e: + assert ( + e.message + == "Policy template id '" + + self.testTemplateId + + "' and version '" + + self.testTemplateVersion + + "' is committed and cannot be updated" + ) + + def test_22_delete_policy_template_version(self): + + response = self.service.delete_policy_template_version( + policy_template_id=self.testTemplateId, + version=self.testTemplateVersion, + ) + + assert response.get_status_code() == 204 + + def test_23_list_policy_template_versions(self): + + response = self.service.list_policy_template_versions( + policy_template_id=self.testTemplateId, + ) + + assert response.get_status_code() == 200 + result_dict = response.get_result() + assert result_dict is not None + + result = PolicyTemplateVersionsCollection.from_dict(result_dict) + assert result is not None + assert len(result.versions) == 1 + + # Confirm the test policy template with new version is present + foundTestTemplateVersion = False + for version in result.versions: + if version.version == self.testNewTemplateVersion: + foundTestTemplateVersion = True + break + assert foundTestTemplateVersion + + def test_24_list_policy_assignments(self): + response = self.service.list_policy_assignments( + account_id=self.testAccountId, + accept_language='default', + ) + + assert response.get_status_code() == 200 + result_dict = response.get_result() + assert result_dict is not None + result = PolicyTemplateAssignmentCollection.from_dict(result_dict) + assert result is not None + + self.__class__.testAssignmentId = result.assignments[0].id + + def test_25_get_policy_assignment(self): + + response = self.service.get_policy_assignment( + assignment_id=self.testAssignmentId, + ) + + assert response.get_status_code() == 200 + result_dict = response.get_result() + assert result_dict is not None + + result = PolicyAssignment.from_dict(result_dict) + assert result is not None + assert result.id == self.testAssignmentId diff --git a/test/unit/test_iam_policy_management_v1.py b/test/unit/test_iam_policy_management_v1.py index 6bd944af..a6c6b96c 100644 --- a/test/unit/test_iam_policy_management_v1.py +++ b/test/unit/test_iam_policy_management_v1.py @@ -59,7 +59,8 @@ def preprocess_url(operation_path: str): # Otherwise, return a regular expression that matches one or more trailing /. if re.fullmatch('.*/+', request_url) is None: return request_url - return re.compile(request_url.rstrip('/') + '/+') + else: + return re.compile(request_url.rstrip('/') + '/+') ############################################################################## @@ -108,8 +109,14 @@ def test_list_policies_all_params(self): """ # Set up mock url = preprocess_url('/v1/policies') - mock_response = '{"policies": [{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"policies": [{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -173,14 +180,23 @@ def test_list_policies_required_params(self): """ # Set up mock url = preprocess_url('/v1/policies') - mock_response = '{"policies": [{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"policies": [{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' # Invoke method - response = _service.list_policies(account_id, headers={}) + response = _service.list_policies( + account_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -206,8 +222,14 @@ def test_list_policies_value_error(self): """ # Set up mock url = preprocess_url('/v1/policies') - mock_response = '{"policies": [{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"policies": [{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -243,8 +265,14 @@ def test_create_policy_all_params(self): """ # Set up mock url = preprocess_url('/v1/policies') - mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Construct a dict representation of a SubjectAttribute model subject_attribute_model = {} @@ -286,7 +314,13 @@ def test_create_policy_all_params(self): # Invoke method response = _service.create_policy( - type, subjects, roles, resources, description=description, accept_language=accept_language, headers={} + type, + subjects, + roles, + resources, + description=description, + accept_language=accept_language, + headers={}, ) # Check for correct operation @@ -316,8 +350,14 @@ def test_create_policy_required_params(self): """ # Set up mock url = preprocess_url('/v1/policies') - mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Construct a dict representation of a SubjectAttribute model subject_attribute_model = {} @@ -357,7 +397,14 @@ def test_create_policy_required_params(self): description = 'testString' # Invoke method - response = _service.create_policy(type, subjects, roles, resources, description=description, headers={}) + response = _service.create_policy( + type, + subjects, + roles, + resources, + description=description, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -386,8 +433,14 @@ def test_create_policy_value_error(self): """ # Set up mock url = preprocess_url('/v1/policies') - mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Construct a dict representation of a SubjectAttribute model subject_attribute_model = {} @@ -460,8 +513,14 @@ def test_replace_policy_all_params(self): """ # Set up mock url = preprocess_url('/v1/policies/testString') - mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Construct a dict representation of a SubjectAttribute model subject_attribute_model = {} @@ -504,7 +563,14 @@ def test_replace_policy_all_params(self): # Invoke method response = _service.replace_policy( - policy_id, if_match, type, subjects, roles, resources, description=description, headers={} + policy_id, + if_match, + type, + subjects, + roles, + resources, + description=description, + headers={}, ) # Check for correct operation @@ -534,8 +600,14 @@ def test_replace_policy_value_error(self): """ # Set up mock url = preprocess_url('/v1/policies/testString') - mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Construct a dict representation of a SubjectAttribute model subject_attribute_model = {} @@ -612,14 +684,23 @@ def test_get_policy_all_params(self): """ # Set up mock url = preprocess_url('/v1/policies/testString') - mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values policy_id = 'testString' # Invoke method - response = _service.get_policy(policy_id, headers={}) + response = _service.get_policy( + policy_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -641,8 +722,14 @@ def test_get_policy_value_error(self): """ # Set up mock url = preprocess_url('/v1/policies/testString') - mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values policy_id = 'testString' @@ -678,13 +765,20 @@ def test_delete_policy_all_params(self): """ # Set up mock url = preprocess_url('/v1/policies/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values policy_id = 'testString' # Invoke method - response = _service.delete_policy(policy_id, headers={}) + response = _service.delete_policy( + policy_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -706,7 +800,11 @@ def test_delete_policy_value_error(self): """ # Set up mock url = preprocess_url('/v1/policies/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values policy_id = 'testString' @@ -742,8 +840,14 @@ def test_update_policy_state_all_params(self): """ # Set up mock url = preprocess_url('/v1/policies/testString') - mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}' - responses.add(responses.PATCH, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.PATCH, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values policy_id = 'testString' @@ -751,7 +855,12 @@ def test_update_policy_state_all_params(self): state = 'active' # Invoke method - response = _service.update_policy_state(policy_id, if_match, state=state, headers={}) + response = _service.update_policy_state( + policy_id, + if_match, + state=state, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -776,8 +885,14 @@ def test_update_policy_state_value_error(self): """ # Set up mock url = preprocess_url('/v1/policies/testString') - mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active"}' - responses.add(responses.PATCH, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"id": "id", "type": "type", "description": "description", "subjects": [{"attributes": [{"name": "name", "value": "value"}]}], "roles": [{"role_id": "role_id", "display_name": "display_name", "description": "description"}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.PATCH, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values policy_id = 'testString' @@ -856,7 +971,13 @@ def test_list_roles_all_params(self): # Set up mock url = preprocess_url('/v2/roles') mock_response = '{"custom_roles": [{"id": "id", "display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn", "name": "Developer", "account_id": "account_id", "service_name": "iam-groups", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "href": "href"}], "service_roles": [{"display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn"}], "system_roles": [{"display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values accept_language = 'default' @@ -906,7 +1027,13 @@ def test_list_roles_required_params(self): # Set up mock url = preprocess_url('/v2/roles') mock_response = '{"custom_roles": [{"id": "id", "display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn", "name": "Developer", "account_id": "account_id", "service_name": "iam-groups", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "href": "href"}], "service_roles": [{"display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn"}], "system_roles": [{"display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Invoke method response = _service.list_roles() @@ -938,7 +1065,13 @@ def test_create_role_all_params(self): # Set up mock url = preprocess_url('/v2/roles') mock_response = '{"id": "id", "display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn", "name": "Developer", "account_id": "account_id", "service_name": "iam-groups", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "href": "href"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Set up parameter values display_name = 'testString' @@ -990,7 +1123,13 @@ def test_create_role_required_params(self): # Set up mock url = preprocess_url('/v2/roles') mock_response = '{"id": "id", "display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn", "name": "Developer", "account_id": "account_id", "service_name": "iam-groups", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "href": "href"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Set up parameter values display_name = 'testString' @@ -1002,7 +1141,13 @@ def test_create_role_required_params(self): # Invoke method response = _service.create_role( - display_name, actions, name, account_id, service_name, description=description, headers={} + display_name, + actions, + name, + account_id, + service_name, + description=description, + headers={}, ) # Check for correct operation @@ -1034,7 +1179,13 @@ def test_create_role_value_error(self): # Set up mock url = preprocess_url('/v2/roles') mock_response = '{"id": "id", "display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn", "name": "Developer", "account_id": "account_id", "service_name": "iam-groups", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "href": "href"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Set up parameter values display_name = 'testString' @@ -1080,7 +1231,13 @@ def test_replace_role_all_params(self): # Set up mock url = preprocess_url('/v2/roles/testString') mock_response = '{"id": "id", "display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn", "name": "Developer", "account_id": "account_id", "service_name": "iam-groups", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "href": "href"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values role_id = 'testString' @@ -1090,7 +1247,14 @@ def test_replace_role_all_params(self): description = 'testString' # Invoke method - response = _service.replace_role(role_id, if_match, display_name, actions, description=description, headers={}) + response = _service.replace_role( + role_id, + if_match, + display_name, + actions, + description=description, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -1118,7 +1282,13 @@ def test_replace_role_value_error(self): # Set up mock url = preprocess_url('/v2/roles/testString') mock_response = '{"id": "id", "display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn", "name": "Developer", "account_id": "account_id", "service_name": "iam-groups", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "href": "href"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values role_id = 'testString' @@ -1162,13 +1332,22 @@ def test_get_role_all_params(self): # Set up mock url = preprocess_url('/v2/roles/testString') mock_response = '{"id": "id", "display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn", "name": "Developer", "account_id": "account_id", "service_name": "iam-groups", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "href": "href"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values role_id = 'testString' # Invoke method - response = _service.get_role(role_id, headers={}) + response = _service.get_role( + role_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -1191,7 +1370,13 @@ def test_get_role_value_error(self): # Set up mock url = preprocess_url('/v2/roles/testString') mock_response = '{"id": "id", "display_name": "display_name", "description": "description", "actions": ["actions"], "crn": "crn", "name": "Developer", "account_id": "account_id", "service_name": "iam-groups", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "href": "href"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values role_id = 'testString' @@ -1227,13 +1412,20 @@ def test_delete_role_all_params(self): """ # Set up mock url = preprocess_url('/v2/roles/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values role_id = 'testString' # Invoke method - response = _service.delete_role(role_id, headers={}) + response = _service.delete_role( + role_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -1255,7 +1447,11 @@ def test_delete_role_value_error(self): """ # Set up mock url = preprocess_url('/v2/roles/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values role_id = 'testString' @@ -1330,8 +1526,14 @@ def test_list_v2_policies_all_params(self): """ # Set up mock url = preprocess_url('/v2/policies') - mock_response = '{"policies": [{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"policies": [{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -1395,14 +1597,23 @@ def test_list_v2_policies_required_params(self): """ # Set up mock url = preprocess_url('/v2/policies') - mock_response = '{"policies": [{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"policies": [{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' # Invoke method - response = _service.list_v2_policies(account_id, headers={}) + response = _service.list_v2_policies( + account_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -1428,8 +1639,14 @@ def test_list_v2_policies_value_error(self): """ # Set up mock url = preprocess_url('/v2/policies') - mock_response = '{"policies": [{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"policies": [{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -1465,8 +1682,14 @@ def test_create_v2_policy_all_params(self): """ # Set up mock url = preprocess_url('/v2/policies') - mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Construct a dict representation of a Roles model roles_model = {} @@ -1565,8 +1788,14 @@ def test_create_v2_policy_required_params(self): """ # Set up mock url = preprocess_url('/v2/policies') - mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Construct a dict representation of a Roles model roles_model = {} @@ -1663,8 +1892,14 @@ def test_create_v2_policy_value_error(self): """ # Set up mock url = preprocess_url('/v2/policies') - mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Construct a dict representation of a Roles model roles_model = {} @@ -1752,8 +1987,14 @@ def test_replace_v2_policy_all_params(self): """ # Set up mock url = preprocess_url('/v2/policies/testString') - mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Construct a dict representation of a Roles model roles_model = {} @@ -1854,8 +2095,14 @@ def test_replace_v2_policy_value_error(self): """ # Set up mock url = preprocess_url('/v2/policies/testString') - mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Construct a dict representation of a Roles model roles_model = {} @@ -1947,15 +2194,25 @@ def test_get_v2_policy_all_params(self): """ # Set up mock url = preprocess_url('/v2/policies/testString') - mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values id = 'testString' format = 'include_last_permit' # Invoke method - response = _service.get_v2_policy(id, format=format, headers={}) + response = _service.get_v2_policy( + id, + format=format, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -1981,14 +2238,23 @@ def test_get_v2_policy_required_params(self): """ # Set up mock url = preprocess_url('/v2/policies/testString') - mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values id = 'testString' # Invoke method - response = _service.get_v2_policy(id, headers={}) + response = _service.get_v2_policy( + id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -2010,8 +2276,14 @@ def test_get_v2_policy_value_error(self): """ # Set up mock url = preprocess_url('/v2/policies/testString') - mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"type": "access", "description": "description", "subject": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "value"}]}, "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "id": "id", "href": "href", "control": {"grant": {"roles": [{"role_id": "role_id"}]}}, "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "state": "active", "last_permit_at": "last_permit_at", "last_permit_frequency": 21, "template": {"crn": "crn", "version": "version"}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values id = 'testString' @@ -2047,13 +2319,20 @@ def test_delete_v2_policy_all_params(self): """ # Set up mock url = preprocess_url('/v2/policies/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values id = 'testString' # Invoke method - response = _service.delete_v2_policy(id, headers={}) + response = _service.delete_v2_policy( + id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -2075,7 +2354,11 @@ def test_delete_v2_policy_value_error(self): """ # Set up mock url = preprocess_url('/v2/policies/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values id = 'testString' @@ -2104,163 +2387,2380 @@ def test_delete_v2_policy_value_error_with_retries(self): # End of Service: V2Policies ############################################################################## - ############################################################################## -# Start of Model Tests +# Start of Service: PolicyTemplates ############################################################################## # region -class TestModel_Control: + + +class TestNewInstance: """ - Test Class for Control + Test Class for new_instance """ - def test_control_serialization(self): + def test_new_instance(self): """ - Test serialization/deserialization for Control + new_instance() """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' - # Construct dict forms of any model objects needed in order to build this model. - - roles_model = {} # Roles - roles_model['role_id'] = 'testString' - - grant_model = {} # Grant - grant_model['roles'] = [roles_model] - - # Construct a json representation of a Control model - control_model_json = {} - control_model_json['grant'] = grant_model - - # Construct a model instance of Control by calling from_dict on the json representation - control_model = Control.from_dict(control_model_json) - assert control_model != False - - # Construct a model instance of Control by calling from_dict on the json representation - control_model_dict = Control.from_dict(control_model_json).__dict__ - control_model2 = Control(**control_model_dict) + service = IamPolicyManagementV1.new_instance( + service_name='TEST_SERVICE', + ) - # Verify the model instances are equivalent - assert control_model == control_model2 + assert service is not None + assert isinstance(service, IamPolicyManagementV1) - # Convert model instance back to dict and verify no loss of data - control_model_json2 = control_model.to_dict() - assert control_model_json2 == control_model_json + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = IamPolicyManagementV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) -class TestModel_EnrichedRoles: +class TestListPolicyTemplates: """ - Test Class for EnrichedRoles + Test Class for list_policy_templates """ - def test_enriched_roles_serialization(self): + @responses.activate + def test_list_policy_templates_all_params(self): """ - Test serialization/deserialization for EnrichedRoles + list_policy_templates() """ + # Set up mock + url = preprocess_url('/v1/policy_templates') + mock_response = '{"policy_templates": [{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) - # Construct dict forms of any model objects needed in order to build this model. - - role_action_model = {} # RoleAction - role_action_model['id'] = 'testString' - role_action_model['display_name'] = 'testString' - role_action_model['description'] = 'testString' + # Set up parameter values + account_id = 'testString' + accept_language = 'default' - # Construct a json representation of a EnrichedRoles model - enriched_roles_model_json = {} - enriched_roles_model_json['role_id'] = 'testString' - enriched_roles_model_json['actions'] = [role_action_model] + # Invoke method + response = _service.list_policy_templates( + account_id, + accept_language=accept_language, + headers={}, + ) - # Construct a model instance of EnrichedRoles by calling from_dict on the json representation - enriched_roles_model = EnrichedRoles.from_dict(enriched_roles_model_json) - assert enriched_roles_model != False + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string - # Construct a model instance of EnrichedRoles by calling from_dict on the json representation - enriched_roles_model_dict = EnrichedRoles.from_dict(enriched_roles_model_json).__dict__ - enriched_roles_model2 = EnrichedRoles(**enriched_roles_model_dict) + def test_list_policy_templates_all_params_with_retries(self): + # Enable retries and run test_list_policy_templates_all_params. + _service.enable_retries() + self.test_list_policy_templates_all_params() - # Verify the model instances are equivalent - assert enriched_roles_model == enriched_roles_model2 + # Disable retries and run test_list_policy_templates_all_params. + _service.disable_retries() + self.test_list_policy_templates_all_params() - # Convert model instance back to dict and verify no loss of data - enriched_roles_model_json2 = enriched_roles_model.to_dict() - assert enriched_roles_model_json2 == enriched_roles_model_json + @responses.activate + def test_list_policy_templates_required_params(self): + """ + test_list_policy_templates_required_params() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates') + mock_response = '{"policy_templates": [{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + # Set up parameter values + account_id = 'testString' -class TestModel_Grant: - """ - Test Class for Grant - """ + # Invoke method + response = _service.list_policy_templates( + account_id, + headers={}, + ) - def test_grant_serialization(self): - """ - Test serialization/deserialization for Grant - """ + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string - # Construct dict forms of any model objects needed in order to build this model. + def test_list_policy_templates_required_params_with_retries(self): + # Enable retries and run test_list_policy_templates_required_params. + _service.enable_retries() + self.test_list_policy_templates_required_params() - roles_model = {} # Roles - roles_model['role_id'] = 'testString' + # Disable retries and run test_list_policy_templates_required_params. + _service.disable_retries() + self.test_list_policy_templates_required_params() - # Construct a json representation of a Grant model - grant_model_json = {} - grant_model_json['roles'] = [roles_model] + @responses.activate + def test_list_policy_templates_value_error(self): + """ + test_list_policy_templates_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates') + mock_response = '{"policy_templates": [{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) - # Construct a model instance of Grant by calling from_dict on the json representation - grant_model = Grant.from_dict(grant_model_json) - assert grant_model != False + # Set up parameter values + account_id = 'testString' - # Construct a model instance of Grant by calling from_dict on the json representation - grant_model_dict = Grant.from_dict(grant_model_json).__dict__ - grant_model2 = Grant(**grant_model_dict) + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_policy_templates(**req_copy) - # Verify the model instances are equivalent - assert grant_model == grant_model2 + def test_list_policy_templates_value_error_with_retries(self): + # Enable retries and run test_list_policy_templates_value_error. + _service.enable_retries() + self.test_list_policy_templates_value_error() - # Convert model instance back to dict and verify no loss of data - grant_model_json2 = grant_model.to_dict() - assert grant_model_json2 == grant_model_json + # Disable retries and run test_list_policy_templates_value_error. + _service.disable_retries() + self.test_list_policy_templates_value_error() -class TestModel_GrantWithEnrichedRoles: +class TestCreatePolicyTemplate: """ - Test Class for GrantWithEnrichedRoles + Test Class for create_policy_template """ - def test_grant_with_enriched_roles_serialization(self): + @responses.activate + def test_create_policy_template_all_params(self): """ - Test serialization/deserialization for GrantWithEnrichedRoles + create_policy_template() """ - + # Set up mock + url = preprocess_url('/v1/policy_templates') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a V2PolicyResourceAttribute model + v2_policy_resource_attribute_model = {} + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' + + # Construct a dict representation of a V2PolicyResourceTag model + v2_policy_resource_tag_model = {} + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + # Construct a dict representation of a V2PolicyResource model + v2_policy_resource_model = {} + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + + # Construct a dict representation of a V2PolicyRuleRuleAttribute model + v2_policy_rule_model = {} + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' + + # Construct a dict representation of a Roles model + roles_model = {} + roles_model['role_id'] = 'testString' + + # Construct a dict representation of a Grant model + grant_model = {} + grant_model['roles'] = [roles_model] + + # Construct a dict representation of a Control model + control_model = {} + control_model['grant'] = grant_model + + # Construct a dict representation of a TemplatePolicy model + template_policy_model = {} + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + # Set up parameter values + name = 'testString' + account_id = 'testString' + policy = template_policy_model + description = 'testString' + committed = True + accept_language = 'default' + + # Invoke method + response = _service.create_policy_template( + name, + account_id, + policy, + description=description, + committed=committed, + accept_language=accept_language, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'testString' + assert req_body['account_id'] == 'testString' + assert req_body['policy'] == template_policy_model + assert req_body['description'] == 'testString' + assert req_body['committed'] == True + + def test_create_policy_template_all_params_with_retries(self): + # Enable retries and run test_create_policy_template_all_params. + _service.enable_retries() + self.test_create_policy_template_all_params() + + # Disable retries and run test_create_policy_template_all_params. + _service.disable_retries() + self.test_create_policy_template_all_params() + + @responses.activate + def test_create_policy_template_required_params(self): + """ + test_create_policy_template_required_params() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a V2PolicyResourceAttribute model + v2_policy_resource_attribute_model = {} + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' + + # Construct a dict representation of a V2PolicyResourceTag model + v2_policy_resource_tag_model = {} + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + # Construct a dict representation of a V2PolicyResource model + v2_policy_resource_model = {} + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + + # Construct a dict representation of a V2PolicyRuleRuleAttribute model + v2_policy_rule_model = {} + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' + + # Construct a dict representation of a Roles model + roles_model = {} + roles_model['role_id'] = 'testString' + + # Construct a dict representation of a Grant model + grant_model = {} + grant_model['roles'] = [roles_model] + + # Construct a dict representation of a Control model + control_model = {} + control_model['grant'] = grant_model + + # Construct a dict representation of a TemplatePolicy model + template_policy_model = {} + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + # Set up parameter values + name = 'testString' + account_id = 'testString' + policy = template_policy_model + description = 'testString' + committed = True + + # Invoke method + response = _service.create_policy_template( + name, + account_id, + policy, + description=description, + committed=committed, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'testString' + assert req_body['account_id'] == 'testString' + assert req_body['policy'] == template_policy_model + assert req_body['description'] == 'testString' + assert req_body['committed'] == True + + def test_create_policy_template_required_params_with_retries(self): + # Enable retries and run test_create_policy_template_required_params. + _service.enable_retries() + self.test_create_policy_template_required_params() + + # Disable retries and run test_create_policy_template_required_params. + _service.disable_retries() + self.test_create_policy_template_required_params() + + @responses.activate + def test_create_policy_template_value_error(self): + """ + test_create_policy_template_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a V2PolicyResourceAttribute model + v2_policy_resource_attribute_model = {} + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' + + # Construct a dict representation of a V2PolicyResourceTag model + v2_policy_resource_tag_model = {} + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + # Construct a dict representation of a V2PolicyResource model + v2_policy_resource_model = {} + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + + # Construct a dict representation of a V2PolicyRuleRuleAttribute model + v2_policy_rule_model = {} + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' + + # Construct a dict representation of a Roles model + roles_model = {} + roles_model['role_id'] = 'testString' + + # Construct a dict representation of a Grant model + grant_model = {} + grant_model['roles'] = [roles_model] + + # Construct a dict representation of a Control model + control_model = {} + control_model['grant'] = grant_model + + # Construct a dict representation of a TemplatePolicy model + template_policy_model = {} + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + # Set up parameter values + name = 'testString' + account_id = 'testString' + policy = template_policy_model + description = 'testString' + committed = True + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "name": name, + "account_id": account_id, + "policy": policy, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_policy_template(**req_copy) + + def test_create_policy_template_value_error_with_retries(self): + # Enable retries and run test_create_policy_template_value_error. + _service.enable_retries() + self.test_create_policy_template_value_error() + + # Disable retries and run test_create_policy_template_value_error. + _service.disable_retries() + self.test_create_policy_template_value_error() + + +class TestGetPolicyTemplate: + """ + Test Class for get_policy_template + """ + + @responses.activate + def test_get_policy_template_all_params(self): + """ + get_policy_template() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + policy_template_id = 'testString' + + # Invoke method + response = _service.get_policy_template( + policy_template_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_policy_template_all_params_with_retries(self): + # Enable retries and run test_get_policy_template_all_params. + _service.enable_retries() + self.test_get_policy_template_all_params() + + # Disable retries and run test_get_policy_template_all_params. + _service.disable_retries() + self.test_get_policy_template_all_params() + + @responses.activate + def test_get_policy_template_value_error(self): + """ + test_get_policy_template_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + policy_template_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "policy_template_id": policy_template_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_policy_template(**req_copy) + + def test_get_policy_template_value_error_with_retries(self): + # Enable retries and run test_get_policy_template_value_error. + _service.enable_retries() + self.test_get_policy_template_value_error() + + # Disable retries and run test_get_policy_template_value_error. + _service.disable_retries() + self.test_get_policy_template_value_error() + + +class TestDeletePolicyTemplate: + """ + Test Class for delete_policy_template + """ + + @responses.activate + def test_delete_policy_template_all_params(self): + """ + delete_policy_template() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString') + responses.add( + responses.DELETE, + url, + status=204, + ) + + # Set up parameter values + policy_template_id = 'testString' + + # Invoke method + response = _service.delete_policy_template( + policy_template_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + def test_delete_policy_template_all_params_with_retries(self): + # Enable retries and run test_delete_policy_template_all_params. + _service.enable_retries() + self.test_delete_policy_template_all_params() + + # Disable retries and run test_delete_policy_template_all_params. + _service.disable_retries() + self.test_delete_policy_template_all_params() + + @responses.activate + def test_delete_policy_template_value_error(self): + """ + test_delete_policy_template_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString') + responses.add( + responses.DELETE, + url, + status=204, + ) + + # Set up parameter values + policy_template_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "policy_template_id": policy_template_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_policy_template(**req_copy) + + def test_delete_policy_template_value_error_with_retries(self): + # Enable retries and run test_delete_policy_template_value_error. + _service.enable_retries() + self.test_delete_policy_template_value_error() + + # Disable retries and run test_delete_policy_template_value_error. + _service.disable_retries() + self.test_delete_policy_template_value_error() + + +class TestCreatePolicyTemplateVersion: + """ + Test Class for create_policy_template_version + """ + + @responses.activate + def test_create_policy_template_version_all_params(self): + """ + create_policy_template_version() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a V2PolicyResourceAttribute model + v2_policy_resource_attribute_model = {} + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' + + # Construct a dict representation of a V2PolicyResourceTag model + v2_policy_resource_tag_model = {} + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + # Construct a dict representation of a V2PolicyResource model + v2_policy_resource_model = {} + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + + # Construct a dict representation of a V2PolicyRuleRuleAttribute model + v2_policy_rule_model = {} + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' + + # Construct a dict representation of a Roles model + roles_model = {} + roles_model['role_id'] = 'testString' + + # Construct a dict representation of a Grant model + grant_model = {} + grant_model['roles'] = [roles_model] + + # Construct a dict representation of a Control model + control_model = {} + control_model['grant'] = grant_model + + # Construct a dict representation of a TemplatePolicy model + template_policy_model = {} + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + # Set up parameter values + policy_template_id = 'testString' + policy = template_policy_model + description = 'testString' + committed = True + + # Invoke method + response = _service.create_policy_template_version( + policy_template_id, + policy, + description=description, + committed=committed, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['policy'] == template_policy_model + assert req_body['description'] == 'testString' + assert req_body['committed'] == True + + def test_create_policy_template_version_all_params_with_retries(self): + # Enable retries and run test_create_policy_template_version_all_params. + _service.enable_retries() + self.test_create_policy_template_version_all_params() + + # Disable retries and run test_create_policy_template_version_all_params. + _service.disable_retries() + self.test_create_policy_template_version_all_params() + + @responses.activate + def test_create_policy_template_version_value_error(self): + """ + test_create_policy_template_version_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a V2PolicyResourceAttribute model + v2_policy_resource_attribute_model = {} + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' + + # Construct a dict representation of a V2PolicyResourceTag model + v2_policy_resource_tag_model = {} + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + # Construct a dict representation of a V2PolicyResource model + v2_policy_resource_model = {} + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + + # Construct a dict representation of a V2PolicyRuleRuleAttribute model + v2_policy_rule_model = {} + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' + + # Construct a dict representation of a Roles model + roles_model = {} + roles_model['role_id'] = 'testString' + + # Construct a dict representation of a Grant model + grant_model = {} + grant_model['roles'] = [roles_model] + + # Construct a dict representation of a Control model + control_model = {} + control_model['grant'] = grant_model + + # Construct a dict representation of a TemplatePolicy model + template_policy_model = {} + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + # Set up parameter values + policy_template_id = 'testString' + policy = template_policy_model + description = 'testString' + committed = True + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "policy_template_id": policy_template_id, + "policy": policy, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_policy_template_version(**req_copy) + + def test_create_policy_template_version_value_error_with_retries(self): + # Enable retries and run test_create_policy_template_version_value_error. + _service.enable_retries() + self.test_create_policy_template_version_value_error() + + # Disable retries and run test_create_policy_template_version_value_error. + _service.disable_retries() + self.test_create_policy_template_version_value_error() + + +class TestListPolicyTemplateVersions: + """ + Test Class for list_policy_template_versions + """ + + @responses.activate + def test_list_policy_template_versions_all_params(self): + """ + list_policy_template_versions() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions') + mock_response = '{"versions": [{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + policy_template_id = 'testString' + + # Invoke method + response = _service.list_policy_template_versions( + policy_template_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_policy_template_versions_all_params_with_retries(self): + # Enable retries and run test_list_policy_template_versions_all_params. + _service.enable_retries() + self.test_list_policy_template_versions_all_params() + + # Disable retries and run test_list_policy_template_versions_all_params. + _service.disable_retries() + self.test_list_policy_template_versions_all_params() + + @responses.activate + def test_list_policy_template_versions_value_error(self): + """ + test_list_policy_template_versions_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions') + mock_response = '{"versions": [{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + policy_template_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "policy_template_id": policy_template_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_policy_template_versions(**req_copy) + + def test_list_policy_template_versions_value_error_with_retries(self): + # Enable retries and run test_list_policy_template_versions_value_error. + _service.enable_retries() + self.test_list_policy_template_versions_value_error() + + # Disable retries and run test_list_policy_template_versions_value_error. + _service.disable_retries() + self.test_list_policy_template_versions_value_error() + + +class TestReplacePolicyTemplate: + """ + Test Class for replace_policy_template + """ + + @responses.activate + def test_replace_policy_template_all_params(self): + """ + replace_policy_template() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions/testString') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Construct a dict representation of a V2PolicyResourceAttribute model + v2_policy_resource_attribute_model = {} + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' + + # Construct a dict representation of a V2PolicyResourceTag model + v2_policy_resource_tag_model = {} + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + # Construct a dict representation of a V2PolicyResource model + v2_policy_resource_model = {} + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + + # Construct a dict representation of a V2PolicyRuleRuleAttribute model + v2_policy_rule_model = {} + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' + + # Construct a dict representation of a Roles model + roles_model = {} + roles_model['role_id'] = 'testString' + + # Construct a dict representation of a Grant model + grant_model = {} + grant_model['roles'] = [roles_model] + + # Construct a dict representation of a Control model + control_model = {} + control_model['grant'] = grant_model + + # Construct a dict representation of a TemplatePolicy model + template_policy_model = {} + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + # Set up parameter values + policy_template_id = 'testString' + version = 'testString' + if_match = 'testString' + policy = template_policy_model + description = 'testString' + committed = True + + # Invoke method + response = _service.replace_policy_template( + policy_template_id, + version, + if_match, + policy, + description=description, + committed=committed, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['policy'] == template_policy_model + assert req_body['description'] == 'testString' + assert req_body['committed'] == True + + def test_replace_policy_template_all_params_with_retries(self): + # Enable retries and run test_replace_policy_template_all_params. + _service.enable_retries() + self.test_replace_policy_template_all_params() + + # Disable retries and run test_replace_policy_template_all_params. + _service.disable_retries() + self.test_replace_policy_template_all_params() + + @responses.activate + def test_replace_policy_template_value_error(self): + """ + test_replace_policy_template_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions/testString') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Construct a dict representation of a V2PolicyResourceAttribute model + v2_policy_resource_attribute_model = {} + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' + + # Construct a dict representation of a V2PolicyResourceTag model + v2_policy_resource_tag_model = {} + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + # Construct a dict representation of a V2PolicyResource model + v2_policy_resource_model = {} + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + + # Construct a dict representation of a V2PolicyRuleRuleAttribute model + v2_policy_rule_model = {} + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' + + # Construct a dict representation of a Roles model + roles_model = {} + roles_model['role_id'] = 'testString' + + # Construct a dict representation of a Grant model + grant_model = {} + grant_model['roles'] = [roles_model] + + # Construct a dict representation of a Control model + control_model = {} + control_model['grant'] = grant_model + + # Construct a dict representation of a TemplatePolicy model + template_policy_model = {} + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + # Set up parameter values + policy_template_id = 'testString' + version = 'testString' + if_match = 'testString' + policy = template_policy_model + description = 'testString' + committed = True + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "policy_template_id": policy_template_id, + "version": version, + "if_match": if_match, + "policy": policy, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.replace_policy_template(**req_copy) + + def test_replace_policy_template_value_error_with_retries(self): + # Enable retries and run test_replace_policy_template_value_error. + _service.enable_retries() + self.test_replace_policy_template_value_error() + + # Disable retries and run test_replace_policy_template_value_error. + _service.disable_retries() + self.test_replace_policy_template_value_error() + + +class TestDeletePolicyTemplateVersion: + """ + Test Class for delete_policy_template_version + """ + + @responses.activate + def test_delete_policy_template_version_all_params(self): + """ + delete_policy_template_version() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions/testString') + responses.add( + responses.DELETE, + url, + status=204, + ) + + # Set up parameter values + policy_template_id = 'testString' + version = 'testString' + + # Invoke method + response = _service.delete_policy_template_version( + policy_template_id, + version, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + def test_delete_policy_template_version_all_params_with_retries(self): + # Enable retries and run test_delete_policy_template_version_all_params. + _service.enable_retries() + self.test_delete_policy_template_version_all_params() + + # Disable retries and run test_delete_policy_template_version_all_params. + _service.disable_retries() + self.test_delete_policy_template_version_all_params() + + @responses.activate + def test_delete_policy_template_version_value_error(self): + """ + test_delete_policy_template_version_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions/testString') + responses.add( + responses.DELETE, + url, + status=204, + ) + + # Set up parameter values + policy_template_id = 'testString' + version = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "policy_template_id": policy_template_id, + "version": version, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_policy_template_version(**req_copy) + + def test_delete_policy_template_version_value_error_with_retries(self): + # Enable retries and run test_delete_policy_template_version_value_error. + _service.enable_retries() + self.test_delete_policy_template_version_value_error() + + # Disable retries and run test_delete_policy_template_version_value_error. + _service.disable_retries() + self.test_delete_policy_template_version_value_error() + + +class TestGetPolicyTemplateVersion: + """ + Test Class for get_policy_template_version + """ + + @responses.activate + def test_get_policy_template_version_all_params(self): + """ + get_policy_template_version() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions/testString') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + policy_template_id = 'testString' + version = 'testString' + + # Invoke method + response = _service.get_policy_template_version( + policy_template_id, + version, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_policy_template_version_all_params_with_retries(self): + # Enable retries and run test_get_policy_template_version_all_params. + _service.enable_retries() + self.test_get_policy_template_version_all_params() + + # Disable retries and run test_get_policy_template_version_all_params. + _service.disable_retries() + self.test_get_policy_template_version_all_params() + + @responses.activate + def test_get_policy_template_version_value_error(self): + """ + test_get_policy_template_version_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions/testString') + mock_response = '{"name": "name", "description": "description", "account_id": "account_id", "version": "version", "committed": false, "policy": {"type": "access", "description": "description", "resource": {"attributes": [{"key": "key", "operator": "stringEquals", "value": "anyValue"}], "tags": [{"key": "key", "value": "value", "operator": "stringEquals"}]}, "pattern": "pattern", "rule": {"key": "key", "operator": "timeLessThan", "value": "anyValue"}, "control": {"grant": {"roles": [{"role_id": "role_id"}]}}}, "id": "id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + policy_template_id = 'testString' + version = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "policy_template_id": policy_template_id, + "version": version, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_policy_template_version(**req_copy) + + def test_get_policy_template_version_value_error_with_retries(self): + # Enable retries and run test_get_policy_template_version_value_error. + _service.enable_retries() + self.test_get_policy_template_version_value_error() + + # Disable retries and run test_get_policy_template_version_value_error. + _service.disable_retries() + self.test_get_policy_template_version_value_error() + + +class TestCommitPolicyTemplate: + """ + Test Class for commit_policy_template + """ + + @responses.activate + def test_commit_policy_template_all_params(self): + """ + commit_policy_template() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions/testString/commit') + responses.add( + responses.POST, + url, + status=204, + ) + + # Set up parameter values + policy_template_id = 'testString' + version = 'testString' + if_match = 'testString' + + # Invoke method + response = _service.commit_policy_template( + policy_template_id, + version, + if_match, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + def test_commit_policy_template_all_params_with_retries(self): + # Enable retries and run test_commit_policy_template_all_params. + _service.enable_retries() + self.test_commit_policy_template_all_params() + + # Disable retries and run test_commit_policy_template_all_params. + _service.disable_retries() + self.test_commit_policy_template_all_params() + + @responses.activate + def test_commit_policy_template_value_error(self): + """ + test_commit_policy_template_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_templates/testString/versions/testString/commit') + responses.add( + responses.POST, + url, + status=204, + ) + + # Set up parameter values + policy_template_id = 'testString' + version = 'testString' + if_match = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "policy_template_id": policy_template_id, + "version": version, + "if_match": if_match, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.commit_policy_template(**req_copy) + + def test_commit_policy_template_value_error_with_retries(self): + # Enable retries and run test_commit_policy_template_value_error. + _service.enable_retries() + self.test_commit_policy_template_value_error() + + # Disable retries and run test_commit_policy_template_value_error. + _service.disable_retries() + self.test_commit_policy_template_value_error() + + +# endregion +############################################################################## +# End of Service: PolicyTemplates +############################################################################## + +############################################################################## +# Start of Service: PolicyAssignments +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = IamPolicyManagementV1.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, IamPolicyManagementV1) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = IamPolicyManagementV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestListPolicyAssignments: + """ + Test Class for list_policy_assignments + """ + + @responses.activate + def test_list_policy_assignments_all_params(self): + """ + list_policy_assignments() + """ + # Set up mock + url = preprocess_url('/v1/policy_assignments') + mock_response = '{"assignments": [{"template_id": "template_id", "template_version": "template_version", "assignment_id": "assignment_id", "target_type": "Account", "target": "target", "options": [{"subject_type": "iam_id", "subject_id": "subject_id", "root_requester_id": "root_requester_id", "root_template_id": "root_template_id", "root_template_version": "root_template_version"}], "id": "id", "account_id": "account_id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "resources": [{"target": "target", "policy": {"resource_created": {"id": "id"}, "error_message": {"trace": "trace", "errors": [{"code": "insufficent_permissions", "message": "message", "details": {"conflicts_with": {"etag": "etag", "role": "role", "policy": "policy"}}, "more_info": "more_info"}], "status_code": 11}}}], "status": "in_progress"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + account_id = 'testString' + accept_language = 'default' + template_id = 'testString' + template_version = 'testString' + + # Invoke method + response = _service.list_policy_assignments( + account_id, + accept_language=accept_language, + template_id=template_id, + template_version=template_version, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + assert 'template_id={}'.format(template_id) in query_string + assert 'template_version={}'.format(template_version) in query_string + + def test_list_policy_assignments_all_params_with_retries(self): + # Enable retries and run test_list_policy_assignments_all_params. + _service.enable_retries() + self.test_list_policy_assignments_all_params() + + # Disable retries and run test_list_policy_assignments_all_params. + _service.disable_retries() + self.test_list_policy_assignments_all_params() + + @responses.activate + def test_list_policy_assignments_required_params(self): + """ + test_list_policy_assignments_required_params() + """ + # Set up mock + url = preprocess_url('/v1/policy_assignments') + mock_response = '{"assignments": [{"template_id": "template_id", "template_version": "template_version", "assignment_id": "assignment_id", "target_type": "Account", "target": "target", "options": [{"subject_type": "iam_id", "subject_id": "subject_id", "root_requester_id": "root_requester_id", "root_template_id": "root_template_id", "root_template_version": "root_template_version"}], "id": "id", "account_id": "account_id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "resources": [{"target": "target", "policy": {"resource_created": {"id": "id"}, "error_message": {"trace": "trace", "errors": [{"code": "insufficent_permissions", "message": "message", "details": {"conflicts_with": {"etag": "etag", "role": "role", "policy": "policy"}}, "more_info": "more_info"}], "status_code": 11}}}], "status": "in_progress"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + account_id = 'testString' + + # Invoke method + response = _service.list_policy_assignments( + account_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + + def test_list_policy_assignments_required_params_with_retries(self): + # Enable retries and run test_list_policy_assignments_required_params. + _service.enable_retries() + self.test_list_policy_assignments_required_params() + + # Disable retries and run test_list_policy_assignments_required_params. + _service.disable_retries() + self.test_list_policy_assignments_required_params() + + @responses.activate + def test_list_policy_assignments_value_error(self): + """ + test_list_policy_assignments_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_assignments') + mock_response = '{"assignments": [{"template_id": "template_id", "template_version": "template_version", "assignment_id": "assignment_id", "target_type": "Account", "target": "target", "options": [{"subject_type": "iam_id", "subject_id": "subject_id", "root_requester_id": "root_requester_id", "root_template_id": "root_template_id", "root_template_version": "root_template_version"}], "id": "id", "account_id": "account_id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "resources": [{"target": "target", "policy": {"resource_created": {"id": "id"}, "error_message": {"trace": "trace", "errors": [{"code": "insufficent_permissions", "message": "message", "details": {"conflicts_with": {"etag": "etag", "role": "role", "policy": "policy"}}, "more_info": "more_info"}], "status_code": 11}}}], "status": "in_progress"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + account_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_policy_assignments(**req_copy) + + def test_list_policy_assignments_value_error_with_retries(self): + # Enable retries and run test_list_policy_assignments_value_error. + _service.enable_retries() + self.test_list_policy_assignments_value_error() + + # Disable retries and run test_list_policy_assignments_value_error. + _service.disable_retries() + self.test_list_policy_assignments_value_error() + + +class TestGetPolicyAssignment: + """ + Test Class for get_policy_assignment + """ + + @responses.activate + def test_get_policy_assignment_all_params(self): + """ + get_policy_assignment() + """ + # Set up mock + url = preprocess_url('/v1/policy_assignments/testString') + mock_response = '{"template_id": "template_id", "template_version": "template_version", "assignment_id": "assignment_id", "target_type": "Account", "target": "target", "options": [{"subject_type": "iam_id", "subject_id": "subject_id", "root_requester_id": "root_requester_id", "root_template_id": "root_template_id", "root_template_version": "root_template_version"}], "id": "id", "account_id": "account_id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "resources": [{"target": "target", "policy": {"resource_created": {"id": "id"}, "error_message": {"trace": "trace", "errors": [{"code": "insufficent_permissions", "message": "message", "details": {"conflicts_with": {"etag": "etag", "role": "role", "policy": "policy"}}, "more_info": "more_info"}], "status_code": 11}}}], "status": "in_progress"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + assignment_id = 'testString' + + # Invoke method + response = _service.get_policy_assignment( + assignment_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_policy_assignment_all_params_with_retries(self): + # Enable retries and run test_get_policy_assignment_all_params. + _service.enable_retries() + self.test_get_policy_assignment_all_params() + + # Disable retries and run test_get_policy_assignment_all_params. + _service.disable_retries() + self.test_get_policy_assignment_all_params() + + @responses.activate + def test_get_policy_assignment_value_error(self): + """ + test_get_policy_assignment_value_error() + """ + # Set up mock + url = preprocess_url('/v1/policy_assignments/testString') + mock_response = '{"template_id": "template_id", "template_version": "template_version", "assignment_id": "assignment_id", "target_type": "Account", "target": "target", "options": [{"subject_type": "iam_id", "subject_id": "subject_id", "root_requester_id": "root_requester_id", "root_template_id": "root_template_id", "root_template_version": "root_template_version"}], "id": "id", "account_id": "account_id", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id", "resources": [{"target": "target", "policy": {"resource_created": {"id": "id"}, "error_message": {"trace": "trace", "errors": [{"code": "insufficent_permissions", "message": "message", "details": {"conflicts_with": {"etag": "etag", "role": "role", "policy": "policy"}}, "more_info": "more_info"}], "status_code": 11}}}], "status": "in_progress"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + assignment_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "assignment_id": assignment_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_policy_assignment(**req_copy) + + def test_get_policy_assignment_value_error_with_retries(self): + # Enable retries and run test_get_policy_assignment_value_error. + _service.enable_retries() + self.test_get_policy_assignment_value_error() + + # Disable retries and run test_get_policy_assignment_value_error. + _service.disable_retries() + self.test_get_policy_assignment_value_error() + + +# endregion +############################################################################## +# End of Service: PolicyAssignments +############################################################################## + + +############################################################################## +# Start of Model Tests +############################################################################## +# region + + +class TestModel_AssignmentResourceCreated: + """ + Test Class for AssignmentResourceCreated + """ + + def test_assignment_resource_created_serialization(self): + """ + Test serialization/deserialization for AssignmentResourceCreated + """ + + # Construct a json representation of a AssignmentResourceCreated model + assignment_resource_created_model_json = {} + assignment_resource_created_model_json['id'] = 'testString' + + # Construct a model instance of AssignmentResourceCreated by calling from_dict on the json representation + assignment_resource_created_model = AssignmentResourceCreated.from_dict(assignment_resource_created_model_json) + assert assignment_resource_created_model != False + + # Construct a model instance of AssignmentResourceCreated by calling from_dict on the json representation + assignment_resource_created_model_dict = AssignmentResourceCreated.from_dict( + assignment_resource_created_model_json + ).__dict__ + assignment_resource_created_model2 = AssignmentResourceCreated(**assignment_resource_created_model_dict) + + # Verify the model instances are equivalent + assert assignment_resource_created_model == assignment_resource_created_model2 + + # Convert model instance back to dict and verify no loss of data + assignment_resource_created_model_json2 = assignment_resource_created_model.to_dict() + assert assignment_resource_created_model_json2 == assignment_resource_created_model_json + + +class TestModel_ConflictsWith: + """ + Test Class for ConflictsWith + """ + + def test_conflicts_with_serialization(self): + """ + Test serialization/deserialization for ConflictsWith + """ + + # Construct a json representation of a ConflictsWith model + conflicts_with_model_json = {} + conflicts_with_model_json['etag'] = 'testString' + conflicts_with_model_json['role'] = 'testString' + conflicts_with_model_json['policy'] = 'testString' + + # Construct a model instance of ConflictsWith by calling from_dict on the json representation + conflicts_with_model = ConflictsWith.from_dict(conflicts_with_model_json) + assert conflicts_with_model != False + + # Construct a model instance of ConflictsWith by calling from_dict on the json representation + conflicts_with_model_dict = ConflictsWith.from_dict(conflicts_with_model_json).__dict__ + conflicts_with_model2 = ConflictsWith(**conflicts_with_model_dict) + + # Verify the model instances are equivalent + assert conflicts_with_model == conflicts_with_model2 + + # Convert model instance back to dict and verify no loss of data + conflicts_with_model_json2 = conflicts_with_model.to_dict() + assert conflicts_with_model_json2 == conflicts_with_model_json + + +class TestModel_Control: + """ + Test Class for Control + """ + + def test_control_serialization(self): + """ + Test serialization/deserialization for Control + """ + + # Construct dict forms of any model objects needed in order to build this model. + + roles_model = {} # Roles + roles_model['role_id'] = 'testString' + + grant_model = {} # Grant + grant_model['roles'] = [roles_model] + + # Construct a json representation of a Control model + control_model_json = {} + control_model_json['grant'] = grant_model + + # Construct a model instance of Control by calling from_dict on the json representation + control_model = Control.from_dict(control_model_json) + assert control_model != False + + # Construct a model instance of Control by calling from_dict on the json representation + control_model_dict = Control.from_dict(control_model_json).__dict__ + control_model2 = Control(**control_model_dict) + + # Verify the model instances are equivalent + assert control_model == control_model2 + + # Convert model instance back to dict and verify no loss of data + control_model_json2 = control_model.to_dict() + assert control_model_json2 == control_model_json + + +class TestModel_CustomRole: + """ + Test Class for CustomRole + """ + + def test_custom_role_serialization(self): + """ + Test serialization/deserialization for CustomRole + """ + + # Construct a json representation of a CustomRole model + custom_role_model_json = {} + custom_role_model_json['display_name'] = 'testString' + custom_role_model_json['description'] = 'testString' + custom_role_model_json['actions'] = ['testString'] + custom_role_model_json['name'] = 'Developer' + custom_role_model_json['account_id'] = 'testString' + custom_role_model_json['service_name'] = 'iam-groups' + + # Construct a model instance of CustomRole by calling from_dict on the json representation + custom_role_model = CustomRole.from_dict(custom_role_model_json) + assert custom_role_model != False + + # Construct a model instance of CustomRole by calling from_dict on the json representation + custom_role_model_dict = CustomRole.from_dict(custom_role_model_json).__dict__ + custom_role_model2 = CustomRole(**custom_role_model_dict) + + # Verify the model instances are equivalent + assert custom_role_model == custom_role_model2 + + # Convert model instance back to dict and verify no loss of data + custom_role_model_json2 = custom_role_model.to_dict() + assert custom_role_model_json2 == custom_role_model_json + + +class TestModel_EnrichedRoles: + """ + Test Class for EnrichedRoles + """ + + def test_enriched_roles_serialization(self): + """ + Test serialization/deserialization for EnrichedRoles + """ + + # Construct dict forms of any model objects needed in order to build this model. + + role_action_model = {} # RoleAction + role_action_model['id'] = 'testString' + role_action_model['display_name'] = 'testString' + role_action_model['description'] = 'testString' + + # Construct a json representation of a EnrichedRoles model + enriched_roles_model_json = {} + enriched_roles_model_json['role_id'] = 'testString' + enriched_roles_model_json['actions'] = [role_action_model] + + # Construct a model instance of EnrichedRoles by calling from_dict on the json representation + enriched_roles_model = EnrichedRoles.from_dict(enriched_roles_model_json) + assert enriched_roles_model != False + + # Construct a model instance of EnrichedRoles by calling from_dict on the json representation + enriched_roles_model_dict = EnrichedRoles.from_dict(enriched_roles_model_json).__dict__ + enriched_roles_model2 = EnrichedRoles(**enriched_roles_model_dict) + + # Verify the model instances are equivalent + assert enriched_roles_model == enriched_roles_model2 + + # Convert model instance back to dict and verify no loss of data + enriched_roles_model_json2 = enriched_roles_model.to_dict() + assert enriched_roles_model_json2 == enriched_roles_model_json + + +class TestModel_ErrorDetails: + """ + Test Class for ErrorDetails + """ + + def test_error_details_serialization(self): + """ + Test serialization/deserialization for ErrorDetails + """ + + # Construct dict forms of any model objects needed in order to build this model. + + conflicts_with_model = {} # ConflictsWith + conflicts_with_model['etag'] = 'testString' + conflicts_with_model['role'] = 'testString' + conflicts_with_model['policy'] = 'testString' + + # Construct a json representation of a ErrorDetails model + error_details_model_json = {} + error_details_model_json['conflicts_with'] = conflicts_with_model + + # Construct a model instance of ErrorDetails by calling from_dict on the json representation + error_details_model = ErrorDetails.from_dict(error_details_model_json) + assert error_details_model != False + + # Construct a model instance of ErrorDetails by calling from_dict on the json representation + error_details_model_dict = ErrorDetails.from_dict(error_details_model_json).__dict__ + error_details_model2 = ErrorDetails(**error_details_model_dict) + + # Verify the model instances are equivalent + assert error_details_model == error_details_model2 + + # Convert model instance back to dict and verify no loss of data + error_details_model_json2 = error_details_model.to_dict() + assert error_details_model_json2 == error_details_model_json + + +class TestModel_ErrorObject: + """ + Test Class for ErrorObject + """ + + def test_error_object_serialization(self): + """ + Test serialization/deserialization for ErrorObject + """ + + # Construct dict forms of any model objects needed in order to build this model. + + conflicts_with_model = {} # ConflictsWith + conflicts_with_model['etag'] = 'testString' + conflicts_with_model['role'] = 'testString' + conflicts_with_model['policy'] = 'testString' + + error_details_model = {} # ErrorDetails + error_details_model['conflicts_with'] = conflicts_with_model + + # Construct a json representation of a ErrorObject model + error_object_model_json = {} + error_object_model_json['code'] = 'insufficent_permissions' + error_object_model_json['message'] = 'testString' + error_object_model_json['details'] = error_details_model + error_object_model_json['more_info'] = 'testString' + + # Construct a model instance of ErrorObject by calling from_dict on the json representation + error_object_model = ErrorObject.from_dict(error_object_model_json) + assert error_object_model != False + + # Construct a model instance of ErrorObject by calling from_dict on the json representation + error_object_model_dict = ErrorObject.from_dict(error_object_model_json).__dict__ + error_object_model2 = ErrorObject(**error_object_model_dict) + + # Verify the model instances are equivalent + assert error_object_model == error_object_model2 + + # Convert model instance back to dict and verify no loss of data + error_object_model_json2 = error_object_model.to_dict() + assert error_object_model_json2 == error_object_model_json + + +class TestModel_ErrorResponse: + """ + Test Class for ErrorResponse + """ + + def test_error_response_serialization(self): + """ + Test serialization/deserialization for ErrorResponse + """ + + # Construct dict forms of any model objects needed in order to build this model. + + conflicts_with_model = {} # ConflictsWith + conflicts_with_model['etag'] = 'testString' + conflicts_with_model['role'] = 'testString' + conflicts_with_model['policy'] = 'testString' + + error_details_model = {} # ErrorDetails + error_details_model['conflicts_with'] = conflicts_with_model + + error_object_model = {} # ErrorObject + error_object_model['code'] = 'insufficent_permissions' + error_object_model['message'] = 'testString' + error_object_model['details'] = error_details_model + error_object_model['more_info'] = 'testString' + + # Construct a json representation of a ErrorResponse model + error_response_model_json = {} + error_response_model_json['trace'] = 'testString' + error_response_model_json['errors'] = [error_object_model] + error_response_model_json['status_code'] = 38 + + # Construct a model instance of ErrorResponse by calling from_dict on the json representation + error_response_model = ErrorResponse.from_dict(error_response_model_json) + assert error_response_model != False + + # Construct a model instance of ErrorResponse by calling from_dict on the json representation + error_response_model_dict = ErrorResponse.from_dict(error_response_model_json).__dict__ + error_response_model2 = ErrorResponse(**error_response_model_dict) + + # Verify the model instances are equivalent + assert error_response_model == error_response_model2 + + # Convert model instance back to dict and verify no loss of data + error_response_model_json2 = error_response_model.to_dict() + assert error_response_model_json2 == error_response_model_json + + +class TestModel_Grant: + """ + Test Class for Grant + """ + + def test_grant_serialization(self): + """ + Test serialization/deserialization for Grant + """ + + # Construct dict forms of any model objects needed in order to build this model. + + roles_model = {} # Roles + roles_model['role_id'] = 'testString' + + # Construct a json representation of a Grant model + grant_model_json = {} + grant_model_json['roles'] = [roles_model] + + # Construct a model instance of Grant by calling from_dict on the json representation + grant_model = Grant.from_dict(grant_model_json) + assert grant_model != False + + # Construct a model instance of Grant by calling from_dict on the json representation + grant_model_dict = Grant.from_dict(grant_model_json).__dict__ + grant_model2 = Grant(**grant_model_dict) + + # Verify the model instances are equivalent + assert grant_model == grant_model2 + + # Convert model instance back to dict and verify no loss of data + grant_model_json2 = grant_model.to_dict() + assert grant_model_json2 == grant_model_json + + +class TestModel_GrantWithEnrichedRoles: + """ + Test Class for GrantWithEnrichedRoles + """ + + def test_grant_with_enriched_roles_serialization(self): + """ + Test serialization/deserialization for GrantWithEnrichedRoles + """ + + # Construct dict forms of any model objects needed in order to build this model. + + role_action_model = {} # RoleAction + role_action_model['id'] = 'testString' + role_action_model['display_name'] = 'testString' + role_action_model['description'] = 'testString' + + enriched_roles_model = {} # EnrichedRoles + enriched_roles_model['role_id'] = 'testString' + enriched_roles_model['actions'] = [role_action_model] + + # Construct a json representation of a GrantWithEnrichedRoles model + grant_with_enriched_roles_model_json = {} + grant_with_enriched_roles_model_json['roles'] = [enriched_roles_model] + + # Construct a model instance of GrantWithEnrichedRoles by calling from_dict on the json representation + grant_with_enriched_roles_model = GrantWithEnrichedRoles.from_dict(grant_with_enriched_roles_model_json) + assert grant_with_enriched_roles_model != False + + # Construct a model instance of GrantWithEnrichedRoles by calling from_dict on the json representation + grant_with_enriched_roles_model_dict = GrantWithEnrichedRoles.from_dict( + grant_with_enriched_roles_model_json + ).__dict__ + grant_with_enriched_roles_model2 = GrantWithEnrichedRoles(**grant_with_enriched_roles_model_dict) + + # Verify the model instances are equivalent + assert grant_with_enriched_roles_model == grant_with_enriched_roles_model2 + + # Convert model instance back to dict and verify no loss of data + grant_with_enriched_roles_model_json2 = grant_with_enriched_roles_model.to_dict() + assert grant_with_enriched_roles_model_json2 == grant_with_enriched_roles_model_json + + +class TestModel_Policy: + """ + Test Class for Policy + """ + + def test_policy_serialization(self): + """ + Test serialization/deserialization for Policy + """ + + # Construct dict forms of any model objects needed in order to build this model. + + subject_attribute_model = {} # SubjectAttribute + subject_attribute_model['name'] = 'testString' + subject_attribute_model['value'] = 'testString' + + policy_subject_model = {} # PolicySubject + policy_subject_model['attributes'] = [subject_attribute_model] + + policy_role_model = {} # PolicyRole + policy_role_model['role_id'] = 'testString' + + resource_attribute_model = {} # ResourceAttribute + resource_attribute_model['name'] = 'testString' + resource_attribute_model['value'] = 'testString' + resource_attribute_model['operator'] = 'testString' + + resource_tag_model = {} # ResourceTag + resource_tag_model['name'] = 'testString' + resource_tag_model['value'] = 'testString' + resource_tag_model['operator'] = 'testString' + + policy_resource_model = {} # PolicyResource + policy_resource_model['attributes'] = [resource_attribute_model] + policy_resource_model['tags'] = [resource_tag_model] + + template_metadata_model = {} # TemplateMetadata + template_metadata_model['crn'] = 'testString' + template_metadata_model['version'] = 'testString' + + # Construct a json representation of a Policy model + policy_model_json = {} + policy_model_json['type'] = 'testString' + policy_model_json['description'] = 'testString' + policy_model_json['subjects'] = [policy_subject_model] + policy_model_json['roles'] = [policy_role_model] + policy_model_json['resources'] = [policy_resource_model] + policy_model_json['state'] = 'active' + policy_model_json['template'] = template_metadata_model + + # Construct a model instance of Policy by calling from_dict on the json representation + policy_model = Policy.from_dict(policy_model_json) + assert policy_model != False + + # Construct a model instance of Policy by calling from_dict on the json representation + policy_model_dict = Policy.from_dict(policy_model_json).__dict__ + policy_model2 = Policy(**policy_model_dict) + + # Verify the model instances are equivalent + assert policy_model == policy_model2 + + # Convert model instance back to dict and verify no loss of data + policy_model_json2 = policy_model.to_dict() + assert policy_model_json2 == policy_model_json + + +class TestModel_PolicyAssignment: + """ + Test Class for PolicyAssignment + """ + + def test_policy_assignment_serialization(self): + """ + Test serialization/deserialization for PolicyAssignment + """ + + # Construct dict forms of any model objects needed in order to build this model. + + policy_assignment_request_options_item_model = {} # PolicyAssignmentRequestOptionsItem + policy_assignment_request_options_item_model['subject_type'] = 'iam_id' + policy_assignment_request_options_item_model['subject_id'] = 'testString' + policy_assignment_request_options_item_model['root_requester_id'] = 'testString' + policy_assignment_request_options_item_model['root_template_id'] = 'testString' + policy_assignment_request_options_item_model['root_template_version'] = 'testString' + + assignment_resource_created_model = {} # AssignmentResourceCreated + assignment_resource_created_model['id'] = 'testString' + + conflicts_with_model = {} # ConflictsWith + conflicts_with_model['etag'] = 'testString' + conflicts_with_model['role'] = 'testString' + conflicts_with_model['policy'] = 'testString' + + error_details_model = {} # ErrorDetails + error_details_model['conflicts_with'] = conflicts_with_model + + error_object_model = {} # ErrorObject + error_object_model['code'] = 'insufficent_permissions' + error_object_model['message'] = 'testString' + error_object_model['details'] = error_details_model + error_object_model['more_info'] = 'testString' + + error_response_model = {} # ErrorResponse + error_response_model['trace'] = 'testString' + error_response_model['errors'] = [error_object_model] + error_response_model['status_code'] = 38 + + policy_assignment_resources_policy_model = {} # PolicyAssignmentResourcesPolicy + policy_assignment_resources_policy_model['resource_created'] = assignment_resource_created_model + policy_assignment_resources_policy_model['error_message'] = error_response_model + + policy_assignment_resources_model = {} # PolicyAssignmentResources + policy_assignment_resources_model['target'] = 'testString' + policy_assignment_resources_model['policy'] = policy_assignment_resources_policy_model + + # Construct a json representation of a PolicyAssignment model + policy_assignment_model_json = {} + policy_assignment_model_json['template_id'] = 'testString' + policy_assignment_model_json['template_version'] = 'testString' + policy_assignment_model_json['assignment_id'] = 'testString' + policy_assignment_model_json['target_type'] = 'Account' + policy_assignment_model_json['target'] = 'testString' + policy_assignment_model_json['options'] = [policy_assignment_request_options_item_model] + policy_assignment_model_json['resources'] = [policy_assignment_resources_model] + policy_assignment_model_json['status'] = 'in_progress' + + # Construct a model instance of PolicyAssignment by calling from_dict on the json representation + policy_assignment_model = PolicyAssignment.from_dict(policy_assignment_model_json) + assert policy_assignment_model != False + + # Construct a model instance of PolicyAssignment by calling from_dict on the json representation + policy_assignment_model_dict = PolicyAssignment.from_dict(policy_assignment_model_json).__dict__ + policy_assignment_model2 = PolicyAssignment(**policy_assignment_model_dict) + + # Verify the model instances are equivalent + assert policy_assignment_model == policy_assignment_model2 + + # Convert model instance back to dict and verify no loss of data + policy_assignment_model_json2 = policy_assignment_model.to_dict() + assert policy_assignment_model_json2 == policy_assignment_model_json + + +class TestModel_PolicyAssignmentRequestOptionsItem: + """ + Test Class for PolicyAssignmentRequestOptionsItem + """ + + def test_policy_assignment_request_options_item_serialization(self): + """ + Test serialization/deserialization for PolicyAssignmentRequestOptionsItem + """ + + # Construct a json representation of a PolicyAssignmentRequestOptionsItem model + policy_assignment_request_options_item_model_json = {} + policy_assignment_request_options_item_model_json['subject_type'] = 'iam_id' + policy_assignment_request_options_item_model_json['subject_id'] = 'testString' + policy_assignment_request_options_item_model_json['root_requester_id'] = 'testString' + policy_assignment_request_options_item_model_json['root_template_id'] = 'testString' + policy_assignment_request_options_item_model_json['root_template_version'] = 'testString' + + # Construct a model instance of PolicyAssignmentRequestOptionsItem by calling from_dict on the json representation + policy_assignment_request_options_item_model = PolicyAssignmentRequestOptionsItem.from_dict( + policy_assignment_request_options_item_model_json + ) + assert policy_assignment_request_options_item_model != False + + # Construct a model instance of PolicyAssignmentRequestOptionsItem by calling from_dict on the json representation + policy_assignment_request_options_item_model_dict = PolicyAssignmentRequestOptionsItem.from_dict( + policy_assignment_request_options_item_model_json + ).__dict__ + policy_assignment_request_options_item_model2 = PolicyAssignmentRequestOptionsItem( + **policy_assignment_request_options_item_model_dict + ) + + # Verify the model instances are equivalent + assert policy_assignment_request_options_item_model == policy_assignment_request_options_item_model2 + + # Convert model instance back to dict and verify no loss of data + policy_assignment_request_options_item_model_json2 = policy_assignment_request_options_item_model.to_dict() + assert policy_assignment_request_options_item_model_json2 == policy_assignment_request_options_item_model_json + + +class TestModel_PolicyAssignmentResources: + """ + Test Class for PolicyAssignmentResources + """ + + def test_policy_assignment_resources_serialization(self): + """ + Test serialization/deserialization for PolicyAssignmentResources + """ + + # Construct dict forms of any model objects needed in order to build this model. + + assignment_resource_created_model = {} # AssignmentResourceCreated + assignment_resource_created_model['id'] = 'testString' + + conflicts_with_model = {} # ConflictsWith + conflicts_with_model['etag'] = 'testString' + conflicts_with_model['role'] = 'testString' + conflicts_with_model['policy'] = 'testString' + + error_details_model = {} # ErrorDetails + error_details_model['conflicts_with'] = conflicts_with_model + + error_object_model = {} # ErrorObject + error_object_model['code'] = 'insufficent_permissions' + error_object_model['message'] = 'testString' + error_object_model['details'] = error_details_model + error_object_model['more_info'] = 'testString' + + error_response_model = {} # ErrorResponse + error_response_model['trace'] = 'testString' + error_response_model['errors'] = [error_object_model] + error_response_model['status_code'] = 38 + + policy_assignment_resources_policy_model = {} # PolicyAssignmentResourcesPolicy + policy_assignment_resources_policy_model['resource_created'] = assignment_resource_created_model + policy_assignment_resources_policy_model['error_message'] = error_response_model + + # Construct a json representation of a PolicyAssignmentResources model + policy_assignment_resources_model_json = {} + policy_assignment_resources_model_json['target'] = 'testString' + policy_assignment_resources_model_json['policy'] = policy_assignment_resources_policy_model + + # Construct a model instance of PolicyAssignmentResources by calling from_dict on the json representation + policy_assignment_resources_model = PolicyAssignmentResources.from_dict(policy_assignment_resources_model_json) + assert policy_assignment_resources_model != False + + # Construct a model instance of PolicyAssignmentResources by calling from_dict on the json representation + policy_assignment_resources_model_dict = PolicyAssignmentResources.from_dict( + policy_assignment_resources_model_json + ).__dict__ + policy_assignment_resources_model2 = PolicyAssignmentResources(**policy_assignment_resources_model_dict) + + # Verify the model instances are equivalent + assert policy_assignment_resources_model == policy_assignment_resources_model2 + + # Convert model instance back to dict and verify no loss of data + policy_assignment_resources_model_json2 = policy_assignment_resources_model.to_dict() + assert policy_assignment_resources_model_json2 == policy_assignment_resources_model_json + + +class TestModel_PolicyAssignmentResourcesPolicy: + """ + Test Class for PolicyAssignmentResourcesPolicy + """ + + def test_policy_assignment_resources_policy_serialization(self): + """ + Test serialization/deserialization for PolicyAssignmentResourcesPolicy + """ + + # Construct dict forms of any model objects needed in order to build this model. + + assignment_resource_created_model = {} # AssignmentResourceCreated + assignment_resource_created_model['id'] = 'testString' + + conflicts_with_model = {} # ConflictsWith + conflicts_with_model['etag'] = 'testString' + conflicts_with_model['role'] = 'testString' + conflicts_with_model['policy'] = 'testString' + + error_details_model = {} # ErrorDetails + error_details_model['conflicts_with'] = conflicts_with_model + + error_object_model = {} # ErrorObject + error_object_model['code'] = 'insufficent_permissions' + error_object_model['message'] = 'testString' + error_object_model['details'] = error_details_model + error_object_model['more_info'] = 'testString' + + error_response_model = {} # ErrorResponse + error_response_model['trace'] = 'testString' + error_response_model['errors'] = [error_object_model] + error_response_model['status_code'] = 38 + + # Construct a json representation of a PolicyAssignmentResourcesPolicy model + policy_assignment_resources_policy_model_json = {} + policy_assignment_resources_policy_model_json['resource_created'] = assignment_resource_created_model + policy_assignment_resources_policy_model_json['error_message'] = error_response_model + + # Construct a model instance of PolicyAssignmentResourcesPolicy by calling from_dict on the json representation + policy_assignment_resources_policy_model = PolicyAssignmentResourcesPolicy.from_dict( + policy_assignment_resources_policy_model_json + ) + assert policy_assignment_resources_policy_model != False + + # Construct a model instance of PolicyAssignmentResourcesPolicy by calling from_dict on the json representation + policy_assignment_resources_policy_model_dict = PolicyAssignmentResourcesPolicy.from_dict( + policy_assignment_resources_policy_model_json + ).__dict__ + policy_assignment_resources_policy_model2 = PolicyAssignmentResourcesPolicy( + **policy_assignment_resources_policy_model_dict + ) + + # Verify the model instances are equivalent + assert policy_assignment_resources_policy_model == policy_assignment_resources_policy_model2 + + # Convert model instance back to dict and verify no loss of data + policy_assignment_resources_policy_model_json2 = policy_assignment_resources_policy_model.to_dict() + assert policy_assignment_resources_policy_model_json2 == policy_assignment_resources_policy_model_json + + +class TestModel_PolicyCollection: + """ + Test Class for PolicyCollection + """ + + def test_policy_collection_serialization(self): + """ + Test serialization/deserialization for PolicyCollection + """ + + # Construct dict forms of any model objects needed in order to build this model. + + subject_attribute_model = {} # SubjectAttribute + subject_attribute_model['name'] = 'testString' + subject_attribute_model['value'] = 'testString' + + policy_subject_model = {} # PolicySubject + policy_subject_model['attributes'] = [subject_attribute_model] + + policy_role_model = {} # PolicyRole + policy_role_model['role_id'] = 'testString' + + resource_attribute_model = {} # ResourceAttribute + resource_attribute_model['name'] = 'testString' + resource_attribute_model['value'] = 'testString' + resource_attribute_model['operator'] = 'testString' + + resource_tag_model = {} # ResourceTag + resource_tag_model['name'] = 'testString' + resource_tag_model['value'] = 'testString' + resource_tag_model['operator'] = 'testString' + + policy_resource_model = {} # PolicyResource + policy_resource_model['attributes'] = [resource_attribute_model] + policy_resource_model['tags'] = [resource_tag_model] + + template_metadata_model = {} # TemplateMetadata + template_metadata_model['crn'] = 'testString' + template_metadata_model['version'] = 'testString' + + policy_model = {} # Policy + policy_model['type'] = 'testString' + policy_model['description'] = 'testString' + policy_model['subjects'] = [policy_subject_model] + policy_model['roles'] = [policy_role_model] + policy_model['resources'] = [policy_resource_model] + policy_model['state'] = 'active' + policy_model['template'] = template_metadata_model + + # Construct a json representation of a PolicyCollection model + policy_collection_model_json = {} + policy_collection_model_json['policies'] = [policy_model] + + # Construct a model instance of PolicyCollection by calling from_dict on the json representation + policy_collection_model = PolicyCollection.from_dict(policy_collection_model_json) + assert policy_collection_model != False + + # Construct a model instance of PolicyCollection by calling from_dict on the json representation + policy_collection_model_dict = PolicyCollection.from_dict(policy_collection_model_json).__dict__ + policy_collection_model2 = PolicyCollection(**policy_collection_model_dict) + + # Verify the model instances are equivalent + assert policy_collection_model == policy_collection_model2 + + # Convert model instance back to dict and verify no loss of data + policy_collection_model_json2 = policy_collection_model.to_dict() + assert policy_collection_model_json2 == policy_collection_model_json + + +class TestModel_PolicyResource: + """ + Test Class for PolicyResource + """ + + def test_policy_resource_serialization(self): + """ + Test serialization/deserialization for PolicyResource + """ + # Construct dict forms of any model objects needed in order to build this model. - role_action_model = {} # RoleAction - role_action_model['id'] = 'testString' - role_action_model['display_name'] = 'testString' - role_action_model['description'] = 'testString' + resource_attribute_model = {} # ResourceAttribute + resource_attribute_model['name'] = 'testString' + resource_attribute_model['value'] = 'testString' + resource_attribute_model['operator'] = 'testString' - enriched_roles_model = {} # EnrichedRoles - enriched_roles_model['role_id'] = 'testString' - enriched_roles_model['actions'] = [role_action_model] + resource_tag_model = {} # ResourceTag + resource_tag_model['name'] = 'testString' + resource_tag_model['value'] = 'testString' + resource_tag_model['operator'] = 'testString' - # Construct a json representation of a GrantWithEnrichedRoles model - grant_with_enriched_roles_model_json = {} - grant_with_enriched_roles_model_json['roles'] = [enriched_roles_model] + # Construct a json representation of a PolicyResource model + policy_resource_model_json = {} + policy_resource_model_json['attributes'] = [resource_attribute_model] + policy_resource_model_json['tags'] = [resource_tag_model] - # Construct a model instance of GrantWithEnrichedRoles by calling from_dict on the json representation - grant_with_enriched_roles_model = GrantWithEnrichedRoles.from_dict(grant_with_enriched_roles_model_json) - assert grant_with_enriched_roles_model != False + # Construct a model instance of PolicyResource by calling from_dict on the json representation + policy_resource_model = PolicyResource.from_dict(policy_resource_model_json) + assert policy_resource_model != False - # Construct a model instance of GrantWithEnrichedRoles by calling from_dict on the json representation - grant_with_enriched_roles_model_dict = GrantWithEnrichedRoles.from_dict( - grant_with_enriched_roles_model_json - ).__dict__ - grant_with_enriched_roles_model2 = GrantWithEnrichedRoles(**grant_with_enriched_roles_model_dict) + # Construct a model instance of PolicyResource by calling from_dict on the json representation + policy_resource_model_dict = PolicyResource.from_dict(policy_resource_model_json).__dict__ + policy_resource_model2 = PolicyResource(**policy_resource_model_dict) # Verify the model instances are equivalent - assert grant_with_enriched_roles_model == grant_with_enriched_roles_model2 + assert policy_resource_model == policy_resource_model2 # Convert model instance back to dict and verify no loss of data - grant_with_enriched_roles_model_json2 = grant_with_enriched_roles_model.to_dict() - assert grant_with_enriched_roles_model_json2 == grant_with_enriched_roles_model_json + policy_resource_model_json2 = policy_resource_model.to_dict() + assert policy_resource_model_json2 == policy_resource_model_json class TestModel_PolicyRole: @@ -2293,119 +4793,289 @@ def test_policy_role_serialization(self): assert policy_role_model_json2 == policy_role_model_json -class TestModel_RoleAction: +class TestModel_PolicySubject: """ - Test Class for RoleAction + Test Class for PolicySubject """ - def test_role_action_serialization(self): + def test_policy_subject_serialization(self): """ - Test serialization/deserialization for RoleAction + Test serialization/deserialization for PolicySubject """ - # Construct a json representation of a RoleAction model - role_action_model_json = {} - role_action_model_json['id'] = 'testString' - role_action_model_json['display_name'] = 'testString' - role_action_model_json['description'] = 'testString' + # Construct dict forms of any model objects needed in order to build this model. - # Construct a model instance of RoleAction by calling from_dict on the json representation - role_action_model = RoleAction.from_dict(role_action_model_json) - assert role_action_model != False + subject_attribute_model = {} # SubjectAttribute + subject_attribute_model['name'] = 'testString' + subject_attribute_model['value'] = 'testString' - # Construct a model instance of RoleAction by calling from_dict on the json representation - role_action_model_dict = RoleAction.from_dict(role_action_model_json).__dict__ - role_action_model2 = RoleAction(**role_action_model_dict) + # Construct a json representation of a PolicySubject model + policy_subject_model_json = {} + policy_subject_model_json['attributes'] = [subject_attribute_model] + + # Construct a model instance of PolicySubject by calling from_dict on the json representation + policy_subject_model = PolicySubject.from_dict(policy_subject_model_json) + assert policy_subject_model != False + + # Construct a model instance of PolicySubject by calling from_dict on the json representation + policy_subject_model_dict = PolicySubject.from_dict(policy_subject_model_json).__dict__ + policy_subject_model2 = PolicySubject(**policy_subject_model_dict) # Verify the model instances are equivalent - assert role_action_model == role_action_model2 + assert policy_subject_model == policy_subject_model2 # Convert model instance back to dict and verify no loss of data - role_action_model_json2 = role_action_model.to_dict() - assert role_action_model_json2 == role_action_model_json + policy_subject_model_json2 = policy_subject_model.to_dict() + assert policy_subject_model_json2 == policy_subject_model_json -class TestModel_Roles: +class TestModel_PolicyTemplate: """ - Test Class for Roles + Test Class for PolicyTemplate """ - def test_roles_serialization(self): + def test_policy_template_serialization(self): """ - Test serialization/deserialization for Roles + Test serialization/deserialization for PolicyTemplate """ - # Construct a json representation of a Roles model - roles_model_json = {} - roles_model_json['role_id'] = 'testString' + # Construct dict forms of any model objects needed in order to build this model. - # Construct a model instance of Roles by calling from_dict on the json representation - roles_model = Roles.from_dict(roles_model_json) - assert roles_model != False + v2_policy_resource_attribute_model = {} # V2PolicyResourceAttribute + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' - # Construct a model instance of Roles by calling from_dict on the json representation - roles_model_dict = Roles.from_dict(roles_model_json).__dict__ - roles_model2 = Roles(**roles_model_dict) + v2_policy_resource_tag_model = {} # V2PolicyResourceTag + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + v2_policy_resource_model = {} # V2PolicyResource + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + + v2_policy_rule_model = {} # V2PolicyRuleRuleAttribute + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' + + roles_model = {} # Roles + roles_model['role_id'] = 'testString' + + grant_model = {} # Grant + grant_model['roles'] = [roles_model] + + control_model = {} # Control + control_model['grant'] = grant_model + + template_policy_model = {} # TemplatePolicy + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + # Construct a json representation of a PolicyTemplate model + policy_template_model_json = {} + policy_template_model_json['name'] = 'testString' + policy_template_model_json['description'] = 'testString' + policy_template_model_json['account_id'] = 'testString' + policy_template_model_json['version'] = 'testString' + policy_template_model_json['committed'] = True + policy_template_model_json['policy'] = template_policy_model + + # Construct a model instance of PolicyTemplate by calling from_dict on the json representation + policy_template_model = PolicyTemplate.from_dict(policy_template_model_json) + assert policy_template_model != False + + # Construct a model instance of PolicyTemplate by calling from_dict on the json representation + policy_template_model_dict = PolicyTemplate.from_dict(policy_template_model_json).__dict__ + policy_template_model2 = PolicyTemplate(**policy_template_model_dict) # Verify the model instances are equivalent - assert roles_model == roles_model2 + assert policy_template_model == policy_template_model2 # Convert model instance back to dict and verify no loss of data - roles_model_json2 = roles_model.to_dict() - assert roles_model_json2 == roles_model_json + policy_template_model_json2 = policy_template_model.to_dict() + assert policy_template_model_json2 == policy_template_model_json -class TestModel_RuleAttribute: +class TestModel_PolicyTemplateAssignmentCollection: """ - Test Class for RuleAttribute + Test Class for PolicyTemplateAssignmentCollection """ - def test_rule_attribute_serialization(self): + def test_policy_template_assignment_collection_serialization(self): """ - Test serialization/deserialization for RuleAttribute + Test serialization/deserialization for PolicyTemplateAssignmentCollection """ - # Construct a json representation of a RuleAttribute model - rule_attribute_model_json = {} - rule_attribute_model_json['key'] = 'testString' - rule_attribute_model_json['operator'] = 'timeLessThan' - rule_attribute_model_json['value'] = 'testString' + # Construct dict forms of any model objects needed in order to build this model. - # Construct a model instance of RuleAttribute by calling from_dict on the json representation - rule_attribute_model = RuleAttribute.from_dict(rule_attribute_model_json) - assert rule_attribute_model != False + policy_assignment_request_options_item_model = {} # PolicyAssignmentRequestOptionsItem + policy_assignment_request_options_item_model['subject_type'] = 'iam_id' + policy_assignment_request_options_item_model['subject_id'] = 'testString' + policy_assignment_request_options_item_model['root_requester_id'] = 'testString' + policy_assignment_request_options_item_model['root_template_id'] = 'testString' + policy_assignment_request_options_item_model['root_template_version'] = 'testString' + + assignment_resource_created_model = {} # AssignmentResourceCreated + assignment_resource_created_model['id'] = 'testString' + + conflicts_with_model = {} # ConflictsWith + conflicts_with_model['etag'] = 'testString' + conflicts_with_model['role'] = 'testString' + conflicts_with_model['policy'] = 'testString' + + error_details_model = {} # ErrorDetails + error_details_model['conflicts_with'] = conflicts_with_model + + error_object_model = {} # ErrorObject + error_object_model['code'] = 'insufficent_permissions' + error_object_model['message'] = 'testString' + error_object_model['details'] = error_details_model + error_object_model['more_info'] = 'testString' + + error_response_model = {} # ErrorResponse + error_response_model['trace'] = 'testString' + error_response_model['errors'] = [error_object_model] + error_response_model['status_code'] = 38 + + policy_assignment_resources_policy_model = {} # PolicyAssignmentResourcesPolicy + policy_assignment_resources_policy_model['resource_created'] = assignment_resource_created_model + policy_assignment_resources_policy_model['error_message'] = error_response_model + + policy_assignment_resources_model = {} # PolicyAssignmentResources + policy_assignment_resources_model['target'] = 'testString' + policy_assignment_resources_model['policy'] = policy_assignment_resources_policy_model + + policy_assignment_model = {} # PolicyAssignment + policy_assignment_model['template_id'] = 'testString' + policy_assignment_model['template_version'] = 'testString' + policy_assignment_model['assignment_id'] = 'testString' + policy_assignment_model['target_type'] = 'Account' + policy_assignment_model['target'] = 'testString' + policy_assignment_model['options'] = [policy_assignment_request_options_item_model] + policy_assignment_model['resources'] = [policy_assignment_resources_model] + policy_assignment_model['status'] = 'in_progress' + + # Construct a json representation of a PolicyTemplateAssignmentCollection model + policy_template_assignment_collection_model_json = {} + policy_template_assignment_collection_model_json['assignments'] = [policy_assignment_model] + + # Construct a model instance of PolicyTemplateAssignmentCollection by calling from_dict on the json representation + policy_template_assignment_collection_model = PolicyTemplateAssignmentCollection.from_dict( + policy_template_assignment_collection_model_json + ) + assert policy_template_assignment_collection_model != False - # Construct a model instance of RuleAttribute by calling from_dict on the json representation - rule_attribute_model_dict = RuleAttribute.from_dict(rule_attribute_model_json).__dict__ - rule_attribute_model2 = RuleAttribute(**rule_attribute_model_dict) + # Construct a model instance of PolicyTemplateAssignmentCollection by calling from_dict on the json representation + policy_template_assignment_collection_model_dict = PolicyTemplateAssignmentCollection.from_dict( + policy_template_assignment_collection_model_json + ).__dict__ + policy_template_assignment_collection_model2 = PolicyTemplateAssignmentCollection( + **policy_template_assignment_collection_model_dict + ) # Verify the model instances are equivalent - assert rule_attribute_model == rule_attribute_model2 + assert policy_template_assignment_collection_model == policy_template_assignment_collection_model2 # Convert model instance back to dict and verify no loss of data - rule_attribute_model_json2 = rule_attribute_model.to_dict() - assert rule_attribute_model_json2 == rule_attribute_model_json + policy_template_assignment_collection_model_json2 = policy_template_assignment_collection_model.to_dict() + assert policy_template_assignment_collection_model_json2 == policy_template_assignment_collection_model_json -class TestModel_V2Policy: +class TestModel_PolicyTemplateCollection: """ - Test Class for V2Policy + Test Class for PolicyTemplateCollection """ - def test_v2_policy_serialization(self): + def test_policy_template_collection_serialization(self): """ - Test serialization/deserialization for V2Policy + Test serialization/deserialization for PolicyTemplateCollection """ # Construct dict forms of any model objects needed in order to build this model. - v2_policy_subject_attribute_model = {} # V2PolicySubjectAttribute - v2_policy_subject_attribute_model['key'] = 'testString' - v2_policy_subject_attribute_model['operator'] = 'stringEquals' - v2_policy_subject_attribute_model['value'] = 'testString' + v2_policy_resource_attribute_model = {} # V2PolicyResourceAttribute + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' - v2_policy_subject_model = {} # V2PolicySubject - v2_policy_subject_model['attributes'] = [v2_policy_subject_attribute_model] + v2_policy_resource_tag_model = {} # V2PolicyResourceTag + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + v2_policy_resource_model = {} # V2PolicyResource + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + + v2_policy_rule_model = {} # V2PolicyRuleRuleAttribute + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' + + roles_model = {} # Roles + roles_model['role_id'] = 'testString' + + grant_model = {} # Grant + grant_model['roles'] = [roles_model] + + control_model = {} # Control + control_model['grant'] = grant_model + + template_policy_model = {} # TemplatePolicy + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + policy_template_model = {} # PolicyTemplate + policy_template_model['name'] = 'testString' + policy_template_model['description'] = 'testString' + policy_template_model['account_id'] = 'testString' + policy_template_model['version'] = 'testString' + policy_template_model['committed'] = True + policy_template_model['policy'] = template_policy_model + + # Construct a json representation of a PolicyTemplateCollection model + policy_template_collection_model_json = {} + policy_template_collection_model_json['policy_templates'] = [policy_template_model] + + # Construct a model instance of PolicyTemplateCollection by calling from_dict on the json representation + policy_template_collection_model = PolicyTemplateCollection.from_dict(policy_template_collection_model_json) + assert policy_template_collection_model != False + + # Construct a model instance of PolicyTemplateCollection by calling from_dict on the json representation + policy_template_collection_model_dict = PolicyTemplateCollection.from_dict( + policy_template_collection_model_json + ).__dict__ + policy_template_collection_model2 = PolicyTemplateCollection(**policy_template_collection_model_dict) + + # Verify the model instances are equivalent + assert policy_template_collection_model == policy_template_collection_model2 + + # Convert model instance back to dict and verify no loss of data + policy_template_collection_model_json2 = policy_template_collection_model.to_dict() + assert policy_template_collection_model_json2 == policy_template_collection_model_json + + +class TestModel_PolicyTemplateVersionsCollection: + """ + Test Class for PolicyTemplateVersionsCollection + """ + + def test_policy_template_versions_collection_serialization(self): + """ + Test serialization/deserialization for PolicyTemplateVersionsCollection + """ + + # Construct dict forms of any model objects needed in order to build this model. v2_policy_resource_attribute_model = {} # V2PolicyResourceAttribute v2_policy_resource_attribute_model['key'] = 'testString' @@ -2432,711 +5102,762 @@ def test_v2_policy_serialization(self): grant_model = {} # Grant grant_model['roles'] = [roles_model] - control_response_model = {} # ControlResponseControl - control_response_model['grant'] = grant_model + control_model = {} # Control + control_model['grant'] = grant_model - # Construct a json representation of a V2Policy model - v2_policy_model_json = {} - v2_policy_model_json['type'] = 'access' - v2_policy_model_json['description'] = 'testString' - v2_policy_model_json['subject'] = v2_policy_subject_model - v2_policy_model_json['resource'] = v2_policy_resource_model - v2_policy_model_json['pattern'] = 'testString' - v2_policy_model_json['rule'] = v2_policy_rule_model - v2_policy_model_json['control'] = control_response_model - v2_policy_model_json['state'] = 'active' - v2_policy_model_json['last_permit_at'] = 'testString' - v2_policy_model_json['last_permit_frequency'] = 38 + template_policy_model = {} # TemplatePolicy + template_policy_model['type'] = 'access' + template_policy_model['description'] = 'testString' + template_policy_model['resource'] = v2_policy_resource_model + template_policy_model['pattern'] = 'testString' + template_policy_model['rule'] = v2_policy_rule_model + template_policy_model['control'] = control_model + + policy_template_model = {} # PolicyTemplate + policy_template_model['name'] = 'testString' + policy_template_model['description'] = 'testString' + policy_template_model['account_id'] = 'testString' + policy_template_model['version'] = 'testString' + policy_template_model['committed'] = True + policy_template_model['policy'] = template_policy_model + + # Construct a json representation of a PolicyTemplateVersionsCollection model + policy_template_versions_collection_model_json = {} + policy_template_versions_collection_model_json['versions'] = [policy_template_model] + + # Construct a model instance of PolicyTemplateVersionsCollection by calling from_dict on the json representation + policy_template_versions_collection_model = PolicyTemplateVersionsCollection.from_dict( + policy_template_versions_collection_model_json + ) + assert policy_template_versions_collection_model != False - # Construct a model instance of V2Policy by calling from_dict on the json representation - v2_policy_model = V2Policy.from_dict(v2_policy_model_json) - assert v2_policy_model != False + # Construct a model instance of PolicyTemplateVersionsCollection by calling from_dict on the json representation + policy_template_versions_collection_model_dict = PolicyTemplateVersionsCollection.from_dict( + policy_template_versions_collection_model_json + ).__dict__ + policy_template_versions_collection_model2 = PolicyTemplateVersionsCollection( + **policy_template_versions_collection_model_dict + ) - # Construct a model instance of V2Policy by calling from_dict on the json representation - v2_policy_model_dict = V2Policy.from_dict(v2_policy_model_json).__dict__ - v2_policy_model2 = V2Policy(**v2_policy_model_dict) + # Verify the model instances are equivalent + assert policy_template_versions_collection_model == policy_template_versions_collection_model2 + + # Convert model instance back to dict and verify no loss of data + policy_template_versions_collection_model_json2 = policy_template_versions_collection_model.to_dict() + assert policy_template_versions_collection_model_json2 == policy_template_versions_collection_model_json + + +class TestModel_ResourceAttribute: + """ + Test Class for ResourceAttribute + """ + + def test_resource_attribute_serialization(self): + """ + Test serialization/deserialization for ResourceAttribute + """ + + # Construct a json representation of a ResourceAttribute model + resource_attribute_model_json = {} + resource_attribute_model_json['name'] = 'testString' + resource_attribute_model_json['value'] = 'testString' + resource_attribute_model_json['operator'] = 'testString' + + # Construct a model instance of ResourceAttribute by calling from_dict on the json representation + resource_attribute_model = ResourceAttribute.from_dict(resource_attribute_model_json) + assert resource_attribute_model != False + + # Construct a model instance of ResourceAttribute by calling from_dict on the json representation + resource_attribute_model_dict = ResourceAttribute.from_dict(resource_attribute_model_json).__dict__ + resource_attribute_model2 = ResourceAttribute(**resource_attribute_model_dict) # Verify the model instances are equivalent - assert v2_policy_model == v2_policy_model2 + assert resource_attribute_model == resource_attribute_model2 # Convert model instance back to dict and verify no loss of data - v2_policy_model_json2 = v2_policy_model.to_dict() - assert v2_policy_model_json2 == v2_policy_model_json + resource_attribute_model_json2 = resource_attribute_model.to_dict() + assert resource_attribute_model_json2 == resource_attribute_model_json -class TestModel_V2PolicyCollection: +class TestModel_ResourceTag: """ - Test Class for V2PolicyCollection + Test Class for ResourceTag """ - def test_v2_policy_collection_serialization(self): + def test_resource_tag_serialization(self): """ - Test serialization/deserialization for V2PolicyCollection + Test serialization/deserialization for ResourceTag """ - # Construct dict forms of any model objects needed in order to build this model. - - v2_policy_subject_attribute_model = {} # V2PolicySubjectAttribute - v2_policy_subject_attribute_model['key'] = 'testString' - v2_policy_subject_attribute_model['operator'] = 'stringEquals' - v2_policy_subject_attribute_model['value'] = 'testString' - - v2_policy_subject_model = {} # V2PolicySubject - v2_policy_subject_model['attributes'] = [v2_policy_subject_attribute_model] - - v2_policy_resource_attribute_model = {} # V2PolicyResourceAttribute - v2_policy_resource_attribute_model['key'] = 'testString' - v2_policy_resource_attribute_model['operator'] = 'stringEquals' - v2_policy_resource_attribute_model['value'] = 'testString' + # Construct a json representation of a ResourceTag model + resource_tag_model_json = {} + resource_tag_model_json['name'] = 'testString' + resource_tag_model_json['value'] = 'testString' + resource_tag_model_json['operator'] = 'testString' - v2_policy_resource_tag_model = {} # V2PolicyResourceTag - v2_policy_resource_tag_model['key'] = 'testString' - v2_policy_resource_tag_model['value'] = 'testString' - v2_policy_resource_tag_model['operator'] = 'stringEquals' + # Construct a model instance of ResourceTag by calling from_dict on the json representation + resource_tag_model = ResourceTag.from_dict(resource_tag_model_json) + assert resource_tag_model != False - v2_policy_resource_model = {} # V2PolicyResource - v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] - v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + # Construct a model instance of ResourceTag by calling from_dict on the json representation + resource_tag_model_dict = ResourceTag.from_dict(resource_tag_model_json).__dict__ + resource_tag_model2 = ResourceTag(**resource_tag_model_dict) - v2_policy_rule_model = {} # V2PolicyRuleRuleAttribute - v2_policy_rule_model['key'] = 'testString' - v2_policy_rule_model['operator'] = 'timeLessThan' - v2_policy_rule_model['value'] = 'testString' + # Verify the model instances are equivalent + assert resource_tag_model == resource_tag_model2 - roles_model = {} # Roles - roles_model['role_id'] = 'testString' + # Convert model instance back to dict and verify no loss of data + resource_tag_model_json2 = resource_tag_model.to_dict() + assert resource_tag_model_json2 == resource_tag_model_json - grant_model = {} # Grant - grant_model['roles'] = [roles_model] - control_response_model = {} # ControlResponseControl - control_response_model['grant'] = grant_model +class TestModel_Role: + """ + Test Class for Role + """ - v2_policy_model = {} # V2Policy - v2_policy_model['type'] = 'access' - v2_policy_model['description'] = 'testString' - v2_policy_model['subject'] = v2_policy_subject_model - v2_policy_model['resource'] = v2_policy_resource_model - v2_policy_model['pattern'] = 'testString' - v2_policy_model['rule'] = v2_policy_rule_model - v2_policy_model['control'] = control_response_model - v2_policy_model['state'] = 'active' - v2_policy_model['last_permit_at'] = 'testString' - v2_policy_model['last_permit_frequency'] = 38 + def test_role_serialization(self): + """ + Test serialization/deserialization for Role + """ - # Construct a json representation of a V2PolicyCollection model - v2_policy_collection_model_json = {} - v2_policy_collection_model_json['policies'] = [v2_policy_model] + # Construct a json representation of a Role model + role_model_json = {} + role_model_json['display_name'] = 'testString' + role_model_json['description'] = 'testString' + role_model_json['actions'] = ['testString'] - # Construct a model instance of V2PolicyCollection by calling from_dict on the json representation - v2_policy_collection_model = V2PolicyCollection.from_dict(v2_policy_collection_model_json) - assert v2_policy_collection_model != False + # Construct a model instance of Role by calling from_dict on the json representation + role_model = Role.from_dict(role_model_json) + assert role_model != False - # Construct a model instance of V2PolicyCollection by calling from_dict on the json representation - v2_policy_collection_model_dict = V2PolicyCollection.from_dict(v2_policy_collection_model_json).__dict__ - v2_policy_collection_model2 = V2PolicyCollection(**v2_policy_collection_model_dict) + # Construct a model instance of Role by calling from_dict on the json representation + role_model_dict = Role.from_dict(role_model_json).__dict__ + role_model2 = Role(**role_model_dict) # Verify the model instances are equivalent - assert v2_policy_collection_model == v2_policy_collection_model2 + assert role_model == role_model2 # Convert model instance back to dict and verify no loss of data - v2_policy_collection_model_json2 = v2_policy_collection_model.to_dict() - assert v2_policy_collection_model_json2 == v2_policy_collection_model_json + role_model_json2 = role_model.to_dict() + assert role_model_json2 == role_model_json -class TestModel_V2PolicyResource: +class TestModel_RoleAction: """ - Test Class for V2PolicyResource + Test Class for RoleAction """ - def test_v2_policy_resource_serialization(self): + def test_role_action_serialization(self): """ - Test serialization/deserialization for V2PolicyResource + Test serialization/deserialization for RoleAction """ - # Construct dict forms of any model objects needed in order to build this model. - - v2_policy_resource_attribute_model = {} # V2PolicyResourceAttribute - v2_policy_resource_attribute_model['key'] = 'testString' - v2_policy_resource_attribute_model['operator'] = 'stringEquals' - v2_policy_resource_attribute_model['value'] = 'testString' - - v2_policy_resource_tag_model = {} # V2PolicyResourceTag - v2_policy_resource_tag_model['key'] = 'testString' - v2_policy_resource_tag_model['value'] = 'testString' - v2_policy_resource_tag_model['operator'] = 'stringEquals' - - # Construct a json representation of a V2PolicyResource model - v2_policy_resource_model_json = {} - v2_policy_resource_model_json['attributes'] = [v2_policy_resource_attribute_model] - v2_policy_resource_model_json['tags'] = [v2_policy_resource_tag_model] + # Construct a json representation of a RoleAction model + role_action_model_json = {} + role_action_model_json['id'] = 'testString' + role_action_model_json['display_name'] = 'testString' + role_action_model_json['description'] = 'testString' - # Construct a model instance of V2PolicyResource by calling from_dict on the json representation - v2_policy_resource_model = V2PolicyResource.from_dict(v2_policy_resource_model_json) - assert v2_policy_resource_model != False + # Construct a model instance of RoleAction by calling from_dict on the json representation + role_action_model = RoleAction.from_dict(role_action_model_json) + assert role_action_model != False - # Construct a model instance of V2PolicyResource by calling from_dict on the json representation - v2_policy_resource_model_dict = V2PolicyResource.from_dict(v2_policy_resource_model_json).__dict__ - v2_policy_resource_model2 = V2PolicyResource(**v2_policy_resource_model_dict) + # Construct a model instance of RoleAction by calling from_dict on the json representation + role_action_model_dict = RoleAction.from_dict(role_action_model_json).__dict__ + role_action_model2 = RoleAction(**role_action_model_dict) # Verify the model instances are equivalent - assert v2_policy_resource_model == v2_policy_resource_model2 + assert role_action_model == role_action_model2 # Convert model instance back to dict and verify no loss of data - v2_policy_resource_model_json2 = v2_policy_resource_model.to_dict() - assert v2_policy_resource_model_json2 == v2_policy_resource_model_json + role_action_model_json2 = role_action_model.to_dict() + assert role_action_model_json2 == role_action_model_json -class TestModel_V2PolicyResourceAttribute: +class TestModel_RoleCollection: """ - Test Class for V2PolicyResourceAttribute + Test Class for RoleCollection """ - def test_v2_policy_resource_attribute_serialization(self): + def test_role_collection_serialization(self): """ - Test serialization/deserialization for V2PolicyResourceAttribute + Test serialization/deserialization for RoleCollection """ - # Construct a json representation of a V2PolicyResourceAttribute model - v2_policy_resource_attribute_model_json = {} - v2_policy_resource_attribute_model_json['key'] = 'testString' - v2_policy_resource_attribute_model_json['operator'] = 'stringEquals' - v2_policy_resource_attribute_model_json['value'] = 'testString' + # Construct dict forms of any model objects needed in order to build this model. - # Construct a model instance of V2PolicyResourceAttribute by calling from_dict on the json representation - v2_policy_resource_attribute_model = V2PolicyResourceAttribute.from_dict( - v2_policy_resource_attribute_model_json - ) - assert v2_policy_resource_attribute_model != False + custom_role_model = {} # CustomRole + custom_role_model['display_name'] = 'testString' + custom_role_model['description'] = 'testString' + custom_role_model['actions'] = ['testString'] + custom_role_model['name'] = 'Developer' + custom_role_model['account_id'] = 'testString' + custom_role_model['service_name'] = 'iam-groups' - # Construct a model instance of V2PolicyResourceAttribute by calling from_dict on the json representation - v2_policy_resource_attribute_model_dict = V2PolicyResourceAttribute.from_dict( - v2_policy_resource_attribute_model_json - ).__dict__ - v2_policy_resource_attribute_model2 = V2PolicyResourceAttribute(**v2_policy_resource_attribute_model_dict) + role_model = {} # Role + role_model['display_name'] = 'testString' + role_model['description'] = 'testString' + role_model['actions'] = ['testString'] + + # Construct a json representation of a RoleCollection model + role_collection_model_json = {} + role_collection_model_json['custom_roles'] = [custom_role_model] + role_collection_model_json['service_roles'] = [role_model] + role_collection_model_json['system_roles'] = [role_model] + + # Construct a model instance of RoleCollection by calling from_dict on the json representation + role_collection_model = RoleCollection.from_dict(role_collection_model_json) + assert role_collection_model != False + + # Construct a model instance of RoleCollection by calling from_dict on the json representation + role_collection_model_dict = RoleCollection.from_dict(role_collection_model_json).__dict__ + role_collection_model2 = RoleCollection(**role_collection_model_dict) # Verify the model instances are equivalent - assert v2_policy_resource_attribute_model == v2_policy_resource_attribute_model2 + assert role_collection_model == role_collection_model2 # Convert model instance back to dict and verify no loss of data - v2_policy_resource_attribute_model_json2 = v2_policy_resource_attribute_model.to_dict() - assert v2_policy_resource_attribute_model_json2 == v2_policy_resource_attribute_model_json + role_collection_model_json2 = role_collection_model.to_dict() + assert role_collection_model_json2 == role_collection_model_json -class TestModel_V2PolicyResourceTag: +class TestModel_Roles: """ - Test Class for V2PolicyResourceTag + Test Class for Roles """ - def test_v2_policy_resource_tag_serialization(self): + def test_roles_serialization(self): """ - Test serialization/deserialization for V2PolicyResourceTag + Test serialization/deserialization for Roles """ - # Construct a json representation of a V2PolicyResourceTag model - v2_policy_resource_tag_model_json = {} - v2_policy_resource_tag_model_json['key'] = 'testString' - v2_policy_resource_tag_model_json['value'] = 'testString' - v2_policy_resource_tag_model_json['operator'] = 'stringEquals' + # Construct a json representation of a Roles model + roles_model_json = {} + roles_model_json['role_id'] = 'testString' - # Construct a model instance of V2PolicyResourceTag by calling from_dict on the json representation - v2_policy_resource_tag_model = V2PolicyResourceTag.from_dict(v2_policy_resource_tag_model_json) - assert v2_policy_resource_tag_model != False + # Construct a model instance of Roles by calling from_dict on the json representation + roles_model = Roles.from_dict(roles_model_json) + assert roles_model != False - # Construct a model instance of V2PolicyResourceTag by calling from_dict on the json representation - v2_policy_resource_tag_model_dict = V2PolicyResourceTag.from_dict(v2_policy_resource_tag_model_json).__dict__ - v2_policy_resource_tag_model2 = V2PolicyResourceTag(**v2_policy_resource_tag_model_dict) + # Construct a model instance of Roles by calling from_dict on the json representation + roles_model_dict = Roles.from_dict(roles_model_json).__dict__ + roles_model2 = Roles(**roles_model_dict) # Verify the model instances are equivalent - assert v2_policy_resource_tag_model == v2_policy_resource_tag_model2 + assert roles_model == roles_model2 # Convert model instance back to dict and verify no loss of data - v2_policy_resource_tag_model_json2 = v2_policy_resource_tag_model.to_dict() - assert v2_policy_resource_tag_model_json2 == v2_policy_resource_tag_model_json + roles_model_json2 = roles_model.to_dict() + assert roles_model_json2 == roles_model_json -class TestModel_V2PolicySubject: +class TestModel_RuleAttribute: """ - Test Class for V2PolicySubject + Test Class for RuleAttribute """ - def test_v2_policy_subject_serialization(self): + def test_rule_attribute_serialization(self): """ - Test serialization/deserialization for V2PolicySubject + Test serialization/deserialization for RuleAttribute """ - # Construct dict forms of any model objects needed in order to build this model. - - v2_policy_subject_attribute_model = {} # V2PolicySubjectAttribute - v2_policy_subject_attribute_model['key'] = 'testString' - v2_policy_subject_attribute_model['operator'] = 'stringEquals' - v2_policy_subject_attribute_model['value'] = 'testString' - - # Construct a json representation of a V2PolicySubject model - v2_policy_subject_model_json = {} - v2_policy_subject_model_json['attributes'] = [v2_policy_subject_attribute_model] + # Construct a json representation of a RuleAttribute model + rule_attribute_model_json = {} + rule_attribute_model_json['key'] = 'testString' + rule_attribute_model_json['operator'] = 'timeLessThan' + rule_attribute_model_json['value'] = 'testString' - # Construct a model instance of V2PolicySubject by calling from_dict on the json representation - v2_policy_subject_model = V2PolicySubject.from_dict(v2_policy_subject_model_json) - assert v2_policy_subject_model != False + # Construct a model instance of RuleAttribute by calling from_dict on the json representation + rule_attribute_model = RuleAttribute.from_dict(rule_attribute_model_json) + assert rule_attribute_model != False - # Construct a model instance of V2PolicySubject by calling from_dict on the json representation - v2_policy_subject_model_dict = V2PolicySubject.from_dict(v2_policy_subject_model_json).__dict__ - v2_policy_subject_model2 = V2PolicySubject(**v2_policy_subject_model_dict) + # Construct a model instance of RuleAttribute by calling from_dict on the json representation + rule_attribute_model_dict = RuleAttribute.from_dict(rule_attribute_model_json).__dict__ + rule_attribute_model2 = RuleAttribute(**rule_attribute_model_dict) # Verify the model instances are equivalent - assert v2_policy_subject_model == v2_policy_subject_model2 + assert rule_attribute_model == rule_attribute_model2 # Convert model instance back to dict and verify no loss of data - v2_policy_subject_model_json2 = v2_policy_subject_model.to_dict() - assert v2_policy_subject_model_json2 == v2_policy_subject_model_json + rule_attribute_model_json2 = rule_attribute_model.to_dict() + assert rule_attribute_model_json2 == rule_attribute_model_json -class TestModel_V2PolicySubjectAttribute: +class TestModel_SubjectAttribute: """ - Test Class for V2PolicySubjectAttribute + Test Class for SubjectAttribute """ - def test_v2_policy_subject_attribute_serialization(self): + def test_subject_attribute_serialization(self): """ - Test serialization/deserialization for V2PolicySubjectAttribute + Test serialization/deserialization for SubjectAttribute """ - # Construct a json representation of a V2PolicySubjectAttribute model - v2_policy_subject_attribute_model_json = {} - v2_policy_subject_attribute_model_json['key'] = 'testString' - v2_policy_subject_attribute_model_json['operator'] = 'stringEquals' - v2_policy_subject_attribute_model_json['value'] = 'testString' + # Construct a json representation of a SubjectAttribute model + subject_attribute_model_json = {} + subject_attribute_model_json['name'] = 'testString' + subject_attribute_model_json['value'] = 'testString' - # Construct a model instance of V2PolicySubjectAttribute by calling from_dict on the json representation - v2_policy_subject_attribute_model = V2PolicySubjectAttribute.from_dict(v2_policy_subject_attribute_model_json) - assert v2_policy_subject_attribute_model != False + # Construct a model instance of SubjectAttribute by calling from_dict on the json representation + subject_attribute_model = SubjectAttribute.from_dict(subject_attribute_model_json) + assert subject_attribute_model != False - # Construct a model instance of V2PolicySubjectAttribute by calling from_dict on the json representation - v2_policy_subject_attribute_model_dict = V2PolicySubjectAttribute.from_dict( - v2_policy_subject_attribute_model_json - ).__dict__ - v2_policy_subject_attribute_model2 = V2PolicySubjectAttribute(**v2_policy_subject_attribute_model_dict) + # Construct a model instance of SubjectAttribute by calling from_dict on the json representation + subject_attribute_model_dict = SubjectAttribute.from_dict(subject_attribute_model_json).__dict__ + subject_attribute_model2 = SubjectAttribute(**subject_attribute_model_dict) # Verify the model instances are equivalent - assert v2_policy_subject_attribute_model == v2_policy_subject_attribute_model2 + assert subject_attribute_model == subject_attribute_model2 # Convert model instance back to dict and verify no loss of data - v2_policy_subject_attribute_model_json2 = v2_policy_subject_attribute_model.to_dict() - assert v2_policy_subject_attribute_model_json2 == v2_policy_subject_attribute_model_json + subject_attribute_model_json2 = subject_attribute_model.to_dict() + assert subject_attribute_model_json2 == subject_attribute_model_json -class TestModel_CustomRole: +class TestModel_TemplateMetadata: """ - Test Class for CustomRole + Test Class for TemplateMetadata """ - def test_custom_role_serialization(self): + def test_template_metadata_serialization(self): """ - Test serialization/deserialization for CustomRole + Test serialization/deserialization for TemplateMetadata """ - # Construct a json representation of a CustomRole model - custom_role_model_json = {} - custom_role_model_json['display_name'] = 'testString' - custom_role_model_json['description'] = 'testString' - custom_role_model_json['actions'] = ['testString'] - custom_role_model_json['name'] = 'Developer' - custom_role_model_json['account_id'] = 'testString' - custom_role_model_json['service_name'] = 'iam-groups' + # Construct a json representation of a TemplateMetadata model + template_metadata_model_json = {} + template_metadata_model_json['crn'] = 'testString' + template_metadata_model_json['version'] = 'testString' - # Construct a model instance of CustomRole by calling from_dict on the json representation - custom_role_model = CustomRole.from_dict(custom_role_model_json) - assert custom_role_model != False + # Construct a model instance of TemplateMetadata by calling from_dict on the json representation + template_metadata_model = TemplateMetadata.from_dict(template_metadata_model_json) + assert template_metadata_model != False - # Construct a model instance of CustomRole by calling from_dict on the json representation - custom_role_model_dict = CustomRole.from_dict(custom_role_model_json).__dict__ - custom_role_model2 = CustomRole(**custom_role_model_dict) + # Construct a model instance of TemplateMetadata by calling from_dict on the json representation + template_metadata_model_dict = TemplateMetadata.from_dict(template_metadata_model_json).__dict__ + template_metadata_model2 = TemplateMetadata(**template_metadata_model_dict) # Verify the model instances are equivalent - assert custom_role_model == custom_role_model2 + assert template_metadata_model == template_metadata_model2 # Convert model instance back to dict and verify no loss of data - custom_role_model_json2 = custom_role_model.to_dict() - assert custom_role_model_json2 == custom_role_model_json + template_metadata_model_json2 = template_metadata_model.to_dict() + assert template_metadata_model_json2 == template_metadata_model_json -class TestModel_Policy: +class TestModel_TemplatePolicy: """ - Test Class for Policy + Test Class for TemplatePolicy """ - def test_policy_serialization(self): + def test_template_policy_serialization(self): """ - Test serialization/deserialization for Policy + Test serialization/deserialization for TemplatePolicy """ # Construct dict forms of any model objects needed in order to build this model. - subject_attribute_model = {} # SubjectAttribute - subject_attribute_model['name'] = 'testString' - subject_attribute_model['value'] = 'testString' + v2_policy_resource_attribute_model = {} # V2PolicyResourceAttribute + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' - policy_subject_model = {} # PolicySubject - policy_subject_model['attributes'] = [subject_attribute_model] + v2_policy_resource_tag_model = {} # V2PolicyResourceTag + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' - policy_role_model = {} # PolicyRole - policy_role_model['role_id'] = 'testString' + v2_policy_resource_model = {} # V2PolicyResource + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] - resource_attribute_model = {} # ResourceAttribute - resource_attribute_model['name'] = 'testString' - resource_attribute_model['value'] = 'testString' - resource_attribute_model['operator'] = 'testString' + v2_policy_rule_model = {} # V2PolicyRuleRuleAttribute + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' - resource_tag_model = {} # ResourceTag - resource_tag_model['name'] = 'testString' - resource_tag_model['value'] = 'testString' - resource_tag_model['operator'] = 'testString' + roles_model = {} # Roles + roles_model['role_id'] = 'testString' - policy_resource_model = {} # PolicyResource - policy_resource_model['attributes'] = [resource_attribute_model] - policy_resource_model['tags'] = [resource_tag_model] + grant_model = {} # Grant + grant_model['roles'] = [roles_model] - # Construct a json representation of a Policy model - policy_model_json = {} - policy_model_json['type'] = 'testString' - policy_model_json['description'] = 'testString' - policy_model_json['subjects'] = [policy_subject_model] - policy_model_json['roles'] = [policy_role_model] - policy_model_json['resources'] = [policy_resource_model] - policy_model_json['state'] = 'active' + control_model = {} # Control + control_model['grant'] = grant_model - # Construct a model instance of Policy by calling from_dict on the json representation - policy_model = Policy.from_dict(policy_model_json) - assert policy_model != False + # Construct a json representation of a TemplatePolicy model + template_policy_model_json = {} + template_policy_model_json['type'] = 'access' + template_policy_model_json['description'] = 'testString' + template_policy_model_json['resource'] = v2_policy_resource_model + template_policy_model_json['pattern'] = 'testString' + template_policy_model_json['rule'] = v2_policy_rule_model + template_policy_model_json['control'] = control_model - # Construct a model instance of Policy by calling from_dict on the json representation - policy_model_dict = Policy.from_dict(policy_model_json).__dict__ - policy_model2 = Policy(**policy_model_dict) + # Construct a model instance of TemplatePolicy by calling from_dict on the json representation + template_policy_model = TemplatePolicy.from_dict(template_policy_model_json) + assert template_policy_model != False + + # Construct a model instance of TemplatePolicy by calling from_dict on the json representation + template_policy_model_dict = TemplatePolicy.from_dict(template_policy_model_json).__dict__ + template_policy_model2 = TemplatePolicy(**template_policy_model_dict) # Verify the model instances are equivalent - assert policy_model == policy_model2 + assert template_policy_model == template_policy_model2 # Convert model instance back to dict and verify no loss of data - policy_model_json2 = policy_model.to_dict() - assert policy_model_json2 == policy_model_json + template_policy_model_json2 = template_policy_model.to_dict() + assert template_policy_model_json2 == template_policy_model_json -class TestModel_PolicyList: +class TestModel_V2Policy: """ - Test Class for PolicyList + Test Class for V2Policy """ - def test_policy_list_serialization(self): + def test_v2_policy_serialization(self): """ - Test serialization/deserialization for PolicyList + Test serialization/deserialization for V2Policy """ # Construct dict forms of any model objects needed in order to build this model. - subject_attribute_model = {} # SubjectAttribute - subject_attribute_model['name'] = 'testString' - subject_attribute_model['value'] = 'testString' + v2_policy_subject_attribute_model = {} # V2PolicySubjectAttribute + v2_policy_subject_attribute_model['key'] = 'testString' + v2_policy_subject_attribute_model['operator'] = 'stringEquals' + v2_policy_subject_attribute_model['value'] = 'testString' - policy_subject_model = {} # PolicySubject - policy_subject_model['attributes'] = [subject_attribute_model] + v2_policy_subject_model = {} # V2PolicySubject + v2_policy_subject_model['attributes'] = [v2_policy_subject_attribute_model] - policy_role_model = {} # PolicyRole - policy_role_model['role_id'] = 'testString' + v2_policy_resource_attribute_model = {} # V2PolicyResourceAttribute + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' - resource_attribute_model = {} # ResourceAttribute - resource_attribute_model['name'] = 'testString' - resource_attribute_model['value'] = 'testString' - resource_attribute_model['operator'] = 'testString' + v2_policy_resource_tag_model = {} # V2PolicyResourceTag + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' - resource_tag_model = {} # ResourceTag - resource_tag_model['name'] = 'testString' - resource_tag_model['value'] = 'testString' - resource_tag_model['operator'] = 'testString' + v2_policy_resource_model = {} # V2PolicyResource + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] - policy_resource_model = {} # PolicyResource - policy_resource_model['attributes'] = [resource_attribute_model] - policy_resource_model['tags'] = [resource_tag_model] + v2_policy_rule_model = {} # V2PolicyRuleRuleAttribute + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' - policy_model = {} # Policy - policy_model['type'] = 'testString' - policy_model['description'] = 'testString' - policy_model['subjects'] = [policy_subject_model] - policy_model['roles'] = [policy_role_model] - policy_model['resources'] = [policy_resource_model] - policy_model['state'] = 'active' + roles_model = {} # Roles + roles_model['role_id'] = 'testString' - # Construct a json representation of a PolicyList model - policy_list_model_json = {} - policy_list_model_json['policies'] = [policy_model] + grant_model = {} # Grant + grant_model['roles'] = [roles_model] + + control_response_model = {} # ControlResponseControl + control_response_model['grant'] = grant_model + + template_metadata_model = {} # TemplateMetadata + template_metadata_model['crn'] = 'testString' + template_metadata_model['version'] = 'testString' + + # Construct a json representation of a V2Policy model + v2_policy_model_json = {} + v2_policy_model_json['type'] = 'access' + v2_policy_model_json['description'] = 'testString' + v2_policy_model_json['subject'] = v2_policy_subject_model + v2_policy_model_json['resource'] = v2_policy_resource_model + v2_policy_model_json['pattern'] = 'testString' + v2_policy_model_json['rule'] = v2_policy_rule_model + v2_policy_model_json['control'] = control_response_model + v2_policy_model_json['state'] = 'active' + v2_policy_model_json['last_permit_at'] = 'testString' + v2_policy_model_json['last_permit_frequency'] = 38 + v2_policy_model_json['template'] = template_metadata_model - # Construct a model instance of PolicyList by calling from_dict on the json representation - policy_list_model = PolicyList.from_dict(policy_list_model_json) - assert policy_list_model != False + # Construct a model instance of V2Policy by calling from_dict on the json representation + v2_policy_model = V2Policy.from_dict(v2_policy_model_json) + assert v2_policy_model != False - # Construct a model instance of PolicyList by calling from_dict on the json representation - policy_list_model_dict = PolicyList.from_dict(policy_list_model_json).__dict__ - policy_list_model2 = PolicyList(**policy_list_model_dict) + # Construct a model instance of V2Policy by calling from_dict on the json representation + v2_policy_model_dict = V2Policy.from_dict(v2_policy_model_json).__dict__ + v2_policy_model2 = V2Policy(**v2_policy_model_dict) # Verify the model instances are equivalent - assert policy_list_model == policy_list_model2 + assert v2_policy_model == v2_policy_model2 # Convert model instance back to dict and verify no loss of data - policy_list_model_json2 = policy_list_model.to_dict() - assert policy_list_model_json2 == policy_list_model_json + v2_policy_model_json2 = v2_policy_model.to_dict() + assert v2_policy_model_json2 == v2_policy_model_json -class TestModel_PolicyResource: +class TestModel_V2PolicyCollection: """ - Test Class for PolicyResource + Test Class for V2PolicyCollection """ - def test_policy_resource_serialization(self): + def test_v2_policy_collection_serialization(self): """ - Test serialization/deserialization for PolicyResource + Test serialization/deserialization for V2PolicyCollection """ # Construct dict forms of any model objects needed in order to build this model. - resource_attribute_model = {} # ResourceAttribute - resource_attribute_model['name'] = 'testString' - resource_attribute_model['value'] = 'testString' - resource_attribute_model['operator'] = 'testString' - - resource_tag_model = {} # ResourceTag - resource_tag_model['name'] = 'testString' - resource_tag_model['value'] = 'testString' - resource_tag_model['operator'] = 'testString' - - # Construct a json representation of a PolicyResource model - policy_resource_model_json = {} - policy_resource_model_json['attributes'] = [resource_attribute_model] - policy_resource_model_json['tags'] = [resource_tag_model] + v2_policy_subject_attribute_model = {} # V2PolicySubjectAttribute + v2_policy_subject_attribute_model['key'] = 'testString' + v2_policy_subject_attribute_model['operator'] = 'stringEquals' + v2_policy_subject_attribute_model['value'] = 'testString' - # Construct a model instance of PolicyResource by calling from_dict on the json representation - policy_resource_model = PolicyResource.from_dict(policy_resource_model_json) - assert policy_resource_model != False + v2_policy_subject_model = {} # V2PolicySubject + v2_policy_subject_model['attributes'] = [v2_policy_subject_attribute_model] - # Construct a model instance of PolicyResource by calling from_dict on the json representation - policy_resource_model_dict = PolicyResource.from_dict(policy_resource_model_json).__dict__ - policy_resource_model2 = PolicyResource(**policy_resource_model_dict) + v2_policy_resource_attribute_model = {} # V2PolicyResourceAttribute + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' - # Verify the model instances are equivalent - assert policy_resource_model == policy_resource_model2 + v2_policy_resource_tag_model = {} # V2PolicyResourceTag + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' - # Convert model instance back to dict and verify no loss of data - policy_resource_model_json2 = policy_resource_model.to_dict() - assert policy_resource_model_json2 == policy_resource_model_json + v2_policy_resource_model = {} # V2PolicyResource + v2_policy_resource_model['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model['tags'] = [v2_policy_resource_tag_model] + v2_policy_rule_model = {} # V2PolicyRuleRuleAttribute + v2_policy_rule_model['key'] = 'testString' + v2_policy_rule_model['operator'] = 'timeLessThan' + v2_policy_rule_model['value'] = 'testString' -class TestModel_PolicySubject: - """ - Test Class for PolicySubject - """ + roles_model = {} # Roles + roles_model['role_id'] = 'testString' - def test_policy_subject_serialization(self): - """ - Test serialization/deserialization for PolicySubject - """ + grant_model = {} # Grant + grant_model['roles'] = [roles_model] - # Construct dict forms of any model objects needed in order to build this model. + control_response_model = {} # ControlResponseControl + control_response_model['grant'] = grant_model - subject_attribute_model = {} # SubjectAttribute - subject_attribute_model['name'] = 'testString' - subject_attribute_model['value'] = 'testString' + template_metadata_model = {} # TemplateMetadata + template_metadata_model['crn'] = 'testString' + template_metadata_model['version'] = 'testString' - # Construct a json representation of a PolicySubject model - policy_subject_model_json = {} - policy_subject_model_json['attributes'] = [subject_attribute_model] + v2_policy_model = {} # V2Policy + v2_policy_model['type'] = 'access' + v2_policy_model['description'] = 'testString' + v2_policy_model['subject'] = v2_policy_subject_model + v2_policy_model['resource'] = v2_policy_resource_model + v2_policy_model['pattern'] = 'testString' + v2_policy_model['rule'] = v2_policy_rule_model + v2_policy_model['control'] = control_response_model + v2_policy_model['state'] = 'active' + v2_policy_model['last_permit_at'] = 'testString' + v2_policy_model['last_permit_frequency'] = 38 + v2_policy_model['template'] = template_metadata_model - # Construct a model instance of PolicySubject by calling from_dict on the json representation - policy_subject_model = PolicySubject.from_dict(policy_subject_model_json) - assert policy_subject_model != False + # Construct a json representation of a V2PolicyCollection model + v2_policy_collection_model_json = {} + v2_policy_collection_model_json['policies'] = [v2_policy_model] - # Construct a model instance of PolicySubject by calling from_dict on the json representation - policy_subject_model_dict = PolicySubject.from_dict(policy_subject_model_json).__dict__ - policy_subject_model2 = PolicySubject(**policy_subject_model_dict) + # Construct a model instance of V2PolicyCollection by calling from_dict on the json representation + v2_policy_collection_model = V2PolicyCollection.from_dict(v2_policy_collection_model_json) + assert v2_policy_collection_model != False + + # Construct a model instance of V2PolicyCollection by calling from_dict on the json representation + v2_policy_collection_model_dict = V2PolicyCollection.from_dict(v2_policy_collection_model_json).__dict__ + v2_policy_collection_model2 = V2PolicyCollection(**v2_policy_collection_model_dict) # Verify the model instances are equivalent - assert policy_subject_model == policy_subject_model2 + assert v2_policy_collection_model == v2_policy_collection_model2 # Convert model instance back to dict and verify no loss of data - policy_subject_model_json2 = policy_subject_model.to_dict() - assert policy_subject_model_json2 == policy_subject_model_json + v2_policy_collection_model_json2 = v2_policy_collection_model.to_dict() + assert v2_policy_collection_model_json2 == v2_policy_collection_model_json -class TestModel_ResourceAttribute: +class TestModel_V2PolicyResource: """ - Test Class for ResourceAttribute + Test Class for V2PolicyResource """ - def test_resource_attribute_serialization(self): + def test_v2_policy_resource_serialization(self): """ - Test serialization/deserialization for ResourceAttribute + Test serialization/deserialization for V2PolicyResource """ - # Construct a json representation of a ResourceAttribute model - resource_attribute_model_json = {} - resource_attribute_model_json['name'] = 'testString' - resource_attribute_model_json['value'] = 'testString' - resource_attribute_model_json['operator'] = 'testString' + # Construct dict forms of any model objects needed in order to build this model. - # Construct a model instance of ResourceAttribute by calling from_dict on the json representation - resource_attribute_model = ResourceAttribute.from_dict(resource_attribute_model_json) - assert resource_attribute_model != False + v2_policy_resource_attribute_model = {} # V2PolicyResourceAttribute + v2_policy_resource_attribute_model['key'] = 'testString' + v2_policy_resource_attribute_model['operator'] = 'stringEquals' + v2_policy_resource_attribute_model['value'] = 'testString' - # Construct a model instance of ResourceAttribute by calling from_dict on the json representation - resource_attribute_model_dict = ResourceAttribute.from_dict(resource_attribute_model_json).__dict__ - resource_attribute_model2 = ResourceAttribute(**resource_attribute_model_dict) + v2_policy_resource_tag_model = {} # V2PolicyResourceTag + v2_policy_resource_tag_model['key'] = 'testString' + v2_policy_resource_tag_model['value'] = 'testString' + v2_policy_resource_tag_model['operator'] = 'stringEquals' + + # Construct a json representation of a V2PolicyResource model + v2_policy_resource_model_json = {} + v2_policy_resource_model_json['attributes'] = [v2_policy_resource_attribute_model] + v2_policy_resource_model_json['tags'] = [v2_policy_resource_tag_model] + + # Construct a model instance of V2PolicyResource by calling from_dict on the json representation + v2_policy_resource_model = V2PolicyResource.from_dict(v2_policy_resource_model_json) + assert v2_policy_resource_model != False + + # Construct a model instance of V2PolicyResource by calling from_dict on the json representation + v2_policy_resource_model_dict = V2PolicyResource.from_dict(v2_policy_resource_model_json).__dict__ + v2_policy_resource_model2 = V2PolicyResource(**v2_policy_resource_model_dict) # Verify the model instances are equivalent - assert resource_attribute_model == resource_attribute_model2 + assert v2_policy_resource_model == v2_policy_resource_model2 # Convert model instance back to dict and verify no loss of data - resource_attribute_model_json2 = resource_attribute_model.to_dict() - assert resource_attribute_model_json2 == resource_attribute_model_json + v2_policy_resource_model_json2 = v2_policy_resource_model.to_dict() + assert v2_policy_resource_model_json2 == v2_policy_resource_model_json -class TestModel_ResourceTag: +class TestModel_V2PolicyResourceAttribute: """ - Test Class for ResourceTag + Test Class for V2PolicyResourceAttribute """ - def test_resource_tag_serialization(self): + def test_v2_policy_resource_attribute_serialization(self): """ - Test serialization/deserialization for ResourceTag + Test serialization/deserialization for V2PolicyResourceAttribute """ - # Construct a json representation of a ResourceTag model - resource_tag_model_json = {} - resource_tag_model_json['name'] = 'testString' - resource_tag_model_json['value'] = 'testString' - resource_tag_model_json['operator'] = 'testString' + # Construct a json representation of a V2PolicyResourceAttribute model + v2_policy_resource_attribute_model_json = {} + v2_policy_resource_attribute_model_json['key'] = 'testString' + v2_policy_resource_attribute_model_json['operator'] = 'stringEquals' + v2_policy_resource_attribute_model_json['value'] = 'testString' - # Construct a model instance of ResourceTag by calling from_dict on the json representation - resource_tag_model = ResourceTag.from_dict(resource_tag_model_json) - assert resource_tag_model != False + # Construct a model instance of V2PolicyResourceAttribute by calling from_dict on the json representation + v2_policy_resource_attribute_model = V2PolicyResourceAttribute.from_dict( + v2_policy_resource_attribute_model_json + ) + assert v2_policy_resource_attribute_model != False - # Construct a model instance of ResourceTag by calling from_dict on the json representation - resource_tag_model_dict = ResourceTag.from_dict(resource_tag_model_json).__dict__ - resource_tag_model2 = ResourceTag(**resource_tag_model_dict) + # Construct a model instance of V2PolicyResourceAttribute by calling from_dict on the json representation + v2_policy_resource_attribute_model_dict = V2PolicyResourceAttribute.from_dict( + v2_policy_resource_attribute_model_json + ).__dict__ + v2_policy_resource_attribute_model2 = V2PolicyResourceAttribute(**v2_policy_resource_attribute_model_dict) # Verify the model instances are equivalent - assert resource_tag_model == resource_tag_model2 + assert v2_policy_resource_attribute_model == v2_policy_resource_attribute_model2 # Convert model instance back to dict and verify no loss of data - resource_tag_model_json2 = resource_tag_model.to_dict() - assert resource_tag_model_json2 == resource_tag_model_json + v2_policy_resource_attribute_model_json2 = v2_policy_resource_attribute_model.to_dict() + assert v2_policy_resource_attribute_model_json2 == v2_policy_resource_attribute_model_json -class TestModel_Role: +class TestModel_V2PolicyResourceTag: """ - Test Class for Role + Test Class for V2PolicyResourceTag """ - def test_role_serialization(self): + def test_v2_policy_resource_tag_serialization(self): """ - Test serialization/deserialization for Role + Test serialization/deserialization for V2PolicyResourceTag """ - # Construct a json representation of a Role model - role_model_json = {} - role_model_json['display_name'] = 'testString' - role_model_json['description'] = 'testString' - role_model_json['actions'] = ['testString'] + # Construct a json representation of a V2PolicyResourceTag model + v2_policy_resource_tag_model_json = {} + v2_policy_resource_tag_model_json['key'] = 'testString' + v2_policy_resource_tag_model_json['value'] = 'testString' + v2_policy_resource_tag_model_json['operator'] = 'stringEquals' - # Construct a model instance of Role by calling from_dict on the json representation - role_model = Role.from_dict(role_model_json) - assert role_model != False + # Construct a model instance of V2PolicyResourceTag by calling from_dict on the json representation + v2_policy_resource_tag_model = V2PolicyResourceTag.from_dict(v2_policy_resource_tag_model_json) + assert v2_policy_resource_tag_model != False - # Construct a model instance of Role by calling from_dict on the json representation - role_model_dict = Role.from_dict(role_model_json).__dict__ - role_model2 = Role(**role_model_dict) + # Construct a model instance of V2PolicyResourceTag by calling from_dict on the json representation + v2_policy_resource_tag_model_dict = V2PolicyResourceTag.from_dict(v2_policy_resource_tag_model_json).__dict__ + v2_policy_resource_tag_model2 = V2PolicyResourceTag(**v2_policy_resource_tag_model_dict) # Verify the model instances are equivalent - assert role_model == role_model2 + assert v2_policy_resource_tag_model == v2_policy_resource_tag_model2 # Convert model instance back to dict and verify no loss of data - role_model_json2 = role_model.to_dict() - assert role_model_json2 == role_model_json + v2_policy_resource_tag_model_json2 = v2_policy_resource_tag_model.to_dict() + assert v2_policy_resource_tag_model_json2 == v2_policy_resource_tag_model_json -class TestModel_RoleList: +class TestModel_V2PolicySubject: """ - Test Class for RoleList + Test Class for V2PolicySubject """ - def test_role_list_serialization(self): + def test_v2_policy_subject_serialization(self): """ - Test serialization/deserialization for RoleList + Test serialization/deserialization for V2PolicySubject """ # Construct dict forms of any model objects needed in order to build this model. - custom_role_model = {} # CustomRole - custom_role_model['display_name'] = 'testString' - custom_role_model['description'] = 'testString' - custom_role_model['actions'] = ['testString'] - custom_role_model['name'] = 'Developer' - custom_role_model['account_id'] = 'testString' - custom_role_model['service_name'] = 'iam-groups' - - role_model = {} # Role - role_model['display_name'] = 'testString' - role_model['description'] = 'testString' - role_model['actions'] = ['testString'] + v2_policy_subject_attribute_model = {} # V2PolicySubjectAttribute + v2_policy_subject_attribute_model['key'] = 'testString' + v2_policy_subject_attribute_model['operator'] = 'stringEquals' + v2_policy_subject_attribute_model['value'] = 'testString' - # Construct a json representation of a RoleList model - role_list_model_json = {} - role_list_model_json['custom_roles'] = [custom_role_model] - role_list_model_json['service_roles'] = [role_model] - role_list_model_json['system_roles'] = [role_model] + # Construct a json representation of a V2PolicySubject model + v2_policy_subject_model_json = {} + v2_policy_subject_model_json['attributes'] = [v2_policy_subject_attribute_model] - # Construct a model instance of RoleList by calling from_dict on the json representation - role_list_model = RoleList.from_dict(role_list_model_json) - assert role_list_model != False + # Construct a model instance of V2PolicySubject by calling from_dict on the json representation + v2_policy_subject_model = V2PolicySubject.from_dict(v2_policy_subject_model_json) + assert v2_policy_subject_model != False - # Construct a model instance of RoleList by calling from_dict on the json representation - role_list_model_dict = RoleList.from_dict(role_list_model_json).__dict__ - role_list_model2 = RoleList(**role_list_model_dict) + # Construct a model instance of V2PolicySubject by calling from_dict on the json representation + v2_policy_subject_model_dict = V2PolicySubject.from_dict(v2_policy_subject_model_json).__dict__ + v2_policy_subject_model2 = V2PolicySubject(**v2_policy_subject_model_dict) # Verify the model instances are equivalent - assert role_list_model == role_list_model2 + assert v2_policy_subject_model == v2_policy_subject_model2 # Convert model instance back to dict and verify no loss of data - role_list_model_json2 = role_list_model.to_dict() - assert role_list_model_json2 == role_list_model_json + v2_policy_subject_model_json2 = v2_policy_subject_model.to_dict() + assert v2_policy_subject_model_json2 == v2_policy_subject_model_json -class TestModel_SubjectAttribute: +class TestModel_V2PolicySubjectAttribute: """ - Test Class for SubjectAttribute + Test Class for V2PolicySubjectAttribute """ - def test_subject_attribute_serialization(self): + def test_v2_policy_subject_attribute_serialization(self): """ - Test serialization/deserialization for SubjectAttribute + Test serialization/deserialization for V2PolicySubjectAttribute """ - # Construct a json representation of a SubjectAttribute model - subject_attribute_model_json = {} - subject_attribute_model_json['name'] = 'testString' - subject_attribute_model_json['value'] = 'testString' + # Construct a json representation of a V2PolicySubjectAttribute model + v2_policy_subject_attribute_model_json = {} + v2_policy_subject_attribute_model_json['key'] = 'testString' + v2_policy_subject_attribute_model_json['operator'] = 'stringEquals' + v2_policy_subject_attribute_model_json['value'] = 'testString' - # Construct a model instance of SubjectAttribute by calling from_dict on the json representation - subject_attribute_model = SubjectAttribute.from_dict(subject_attribute_model_json) - assert subject_attribute_model != False + # Construct a model instance of V2PolicySubjectAttribute by calling from_dict on the json representation + v2_policy_subject_attribute_model = V2PolicySubjectAttribute.from_dict(v2_policy_subject_attribute_model_json) + assert v2_policy_subject_attribute_model != False - # Construct a model instance of SubjectAttribute by calling from_dict on the json representation - subject_attribute_model_dict = SubjectAttribute.from_dict(subject_attribute_model_json).__dict__ - subject_attribute_model2 = SubjectAttribute(**subject_attribute_model_dict) + # Construct a model instance of V2PolicySubjectAttribute by calling from_dict on the json representation + v2_policy_subject_attribute_model_dict = V2PolicySubjectAttribute.from_dict( + v2_policy_subject_attribute_model_json + ).__dict__ + v2_policy_subject_attribute_model2 = V2PolicySubjectAttribute(**v2_policy_subject_attribute_model_dict) # Verify the model instances are equivalent - assert subject_attribute_model == subject_attribute_model2 + assert v2_policy_subject_attribute_model == v2_policy_subject_attribute_model2 # Convert model instance back to dict and verify no loss of data - subject_attribute_model_json2 = subject_attribute_model.to_dict() - assert subject_attribute_model_json2 == subject_attribute_model_json + v2_policy_subject_attribute_model_json2 = v2_policy_subject_attribute_model.to_dict() + assert v2_policy_subject_attribute_model_json2 == v2_policy_subject_attribute_model_json class TestModel_ControlResponseControl: