diff --git a/CHANGELOG.md b/CHANGELOG.md index b12a0b7..b47761f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [3.18.2] - 2024-10-30 +### Fixed +- Fixed implementation of `update_access_policy()` API + ## [3.18.1] - 2024-10-29 ### Fixed - Updated `AccessPolicy` model for Admin Organization diff --git a/docs/clients/admin/admin_client.md b/docs/clients/admin/admin_client.md index d4dc9e1..7879db6 100644 --- a/docs/clients/admin/admin_client.md +++ b/docs/clients/admin/admin_client.md @@ -390,7 +390,7 @@ __Returns__

update_access_policy

```python -AdminClient.update_access_policy(policy_id: str, policy_name: str) +AdminClient.update_access_policy(policy_id: str, policy: AccessPolicy) ``` Updates an access policy settings. @@ -398,7 +398,7 @@ Updates an access policy settings. __Arguments__ - __policy_id (String)__: Policy ID -- __policy_name (String)__: Name to be set for the policy +- __policy (AccessPolicy)__: AccessPolicy Object __Returns__ diff --git a/spotinst_sdk2/clients/admin/__init__.py b/spotinst_sdk2/clients/admin/__init__.py index 70c28c6..5608b8d 100644 --- a/spotinst_sdk2/clients/admin/__init__.py +++ b/spotinst_sdk2/clients/admin/__init__.py @@ -556,24 +556,33 @@ def create_access_policy(self, policy: admin_org.AccessPolicy): return ret_val - def update_access_policy(self, policy_id: str, policy_name: str): + def update_access_policy(self, policy_id: str, policy: admin_org.AccessPolicy): """ Updates an access policy settings. # Arguments policy_id (String): Policy ID - policy_name (String): Name to be set for the policy + policy (AccessPolicy): AccessPolicy Object # Returns (Object): Spotinst API response """ - response = self.send_put( - url=self.__base_setup_url + "/access/policy/" + policy_id, - body=json.dumps(dict(policy=dict(name=policy_name))), - entity_name="policy") + request = admin_org.AccessPolicyUpdationRequest(policy) + + excluded_policy_dict = self.exclude_missing( + json.loads(request.toJSON())) + + formatted_policy_dict = self.convert_json( + excluded_policy_dict, self.underscore_to_camel) + + body_json = json.dumps(formatted_policy_dict) + + policy_response = self.send_put( + body=body_json, + url=self.__base_setup_url + "/access/policy/" + policy_id, entity_name="policy") formatted_response = self.convert_json( - response, self.camel_to_underscore) + policy_response, self.camel_to_underscore) return formatted_response["response"]["status"] diff --git a/spotinst_sdk2/models/admin/organization.py b/spotinst_sdk2/models/admin/organization.py index 3fabd3e..b4a099a 100644 --- a/spotinst_sdk2/models/admin/organization.py +++ b/spotinst_sdk2/models/admin/organization.py @@ -109,6 +109,15 @@ def toJSON(self): sort_keys=True, indent=4) +class AccessPolicyUpdationRequest: + def __init__(self, policy: AccessPolicy): + self.policy = policy + + def toJSON(self): + return json.dumps(self, default=lambda o: o.__dict__, + sort_keys=True, indent=4) + + class UserGroupCreationRequest: def __init__(self, group: UserGroup): self.description = group.description diff --git a/spotinst_sdk2/version.py b/spotinst_sdk2/version.py index 12879d5..5f22db9 100644 --- a/spotinst_sdk2/version.py +++ b/spotinst_sdk2/version.py @@ -1 +1,2 @@ -__version__ = '3.18.1' +__version__ = '3.18.2' +