Skip to content

Commit

Permalink
Fixed update_access_policy API (#190)
Browse files Browse the repository at this point in the history
* Added missing field in AccessPolicy model

* Fixed update_access_policy API

* changed "response"
  • Loading branch information
anuragsharma-123 authored Oct 30, 2024
1 parent 192f29c commit 38b4b8c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/clients/admin/admin_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,15 @@ __Returns__
<h2 id="spotinst_sdk2.clients.admin.AdminClient.update_access_policy">update_access_policy</h2>

```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.

__Arguments__

- __policy_id (String)__: Policy ID
- __policy_name (String)__: Name to be set for the policy
- __policy (AccessPolicy)__: AccessPolicy Object

__Returns__

Expand Down
23 changes: 16 additions & 7 deletions spotinst_sdk2/clients/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
9 changes: 9 additions & 0 deletions spotinst_sdk2/models/admin/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spotinst_sdk2/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__version__ = '3.18.1'
__version__ = '3.18.2'

0 comments on commit 38b4b8c

Please sign in to comment.