Skip to content

Commit a38d7b6

Browse files
author
Anurag Sharma
committed
Fixed update_access_policy API
1 parent 5ad77fb commit a38d7b6

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [3.18.2] - 2024-10-30
6+
### Fixed
7+
- Fixed implementation of `update_access_policy()` API
8+
59
## [3.18.1] - 2024-10-29
610
### Fixed
711
- Updated `AccessPolicy` model for Admin Organization

docs/clients/admin/admin_client.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,15 @@ __Returns__
390390
<h2 id="spotinst_sdk2.clients.admin.AdminClient.update_access_policy">update_access_policy</h2>
391391

392392
```python
393-
AdminClient.update_access_policy(policy_id: str, policy_name: str)
393+
AdminClient.update_access_policy(policy_id: str, policy: AccessPolicy)
394394
```
395395

396396
Updates an access policy settings.
397397

398398
__Arguments__
399399

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

403403
__Returns__
404404

spotinst_sdk2/clients/admin/__init__.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,26 +556,37 @@ def create_access_policy(self, policy: admin_org.AccessPolicy):
556556

557557
return ret_val
558558

559-
def update_access_policy(self, policy_id: str, policy_name: str):
559+
def update_access_policy(self, policy_id: str, policy: admin_org.AccessPolicy):
560560
"""
561561
Updates an access policy settings.
562562
563563
# Arguments
564564
policy_id (String): Policy ID
565-
policy_name (String): Name to be set for the policy
565+
policy (AccessPolicy): AccessPolicy Object
566566
567567
# Returns
568568
(Object): Spotinst API response
569569
"""
570-
response = self.send_put(
571-
url=self.__base_setup_url + "/access/policy/" + policy_id,
572-
body=json.dumps(dict(policy=dict(name=policy_name))),
573-
entity_name="policy")
570+
request = admin_org.AccessPolicyUpdationRequest(policy)
571+
572+
excluded_policy_dict = self.exclude_missing(
573+
json.loads(request.toJSON()))
574+
575+
formatted_policy_dict = self.convert_json(
576+
excluded_policy_dict, self.underscore_to_camel)
577+
578+
body_json = json.dumps(formatted_policy_dict)
579+
580+
policy_response = self.send_put(
581+
body=body_json,
582+
url=self.__base_setup_url + "/access/policy/" + policy_id, entity_name="policy")
574583

575584
formatted_response = self.convert_json(
576-
response, self.camel_to_underscore)
585+
policy_response, self.camel_to_underscore)
577586

578-
return formatted_response["response"]["status"]
587+
ret_val = formatted_response["response"]["items"][0]
588+
589+
return ret_val
579590

580591
def delete_access_policy(self, policy_id: str):
581592
"""

spotinst_sdk2/models/admin/organization.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ def toJSON(self):
109109
sort_keys=True, indent=4)
110110

111111

112+
class AccessPolicyUpdationRequest:
113+
def __init__(self, policy: AccessPolicy):
114+
self.policy = policy
115+
116+
def toJSON(self):
117+
return json.dumps(self, default=lambda o: o.__dict__,
118+
sort_keys=True, indent=4)
119+
120+
112121
class UserGroupCreationRequest:
113122
def __init__(self, group: UserGroup):
114123
self.description = group.description

spotinst_sdk2/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.18.1'
1+
__version__ = '3.18.2'

0 commit comments

Comments
 (0)