Skip to content

Commit

Permalink
Fixes typos, adds additional admin client functions (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
firke authored Jan 27, 2024
1 parent c43af7c commit a215cc3
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 29 deletions.
11 changes: 5 additions & 6 deletions docs/clients/admin/admin_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ __Returns__

`(Object)`: Spotinst API response

<h2 id="spotinst_sdk2.clients.admin.AdminClient.add_exsisting_user">add_exsisting_user</h2>
<h2 id="spotinst_sdk2.clients.admin.AdminClient.add_existing_user">add_existing_user</h2>

```python
AdminClient.add_exsisting_user(user_email, role)
AdminClient.add_existing_user(user_email, role)
```

Add exsisting user
Add existing user

__Arguments__

Expand All @@ -164,7 +164,7 @@ __Returns__
AdminClient.update_user_role(user_email, role)
```

Update exsisting user
Update existing user

__Arguments__

Expand All @@ -181,7 +181,7 @@ __Returns__
AdminClient.detach_user(user_email)
```

Delete exsisting user
Delete existing user

__Arguments__

Expand Down Expand Up @@ -222,4 +222,3 @@ __Arguments__
__Returns__

`(Object)`: Spotinst API response

5 changes: 2 additions & 3 deletions docs/clients/mrscaler/mrscaler_aws_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ __Returns__
MrScalerAwsClient.update_emr(emr_id, emr)
```

Update an exsisting EMR
Update an existing EMR

__Arguments__

Expand Down Expand Up @@ -60,7 +60,7 @@ __Returns__
MrScalerAwsClient.get_emr(emr_id)
```

Get an exsisting EMR json
Get an existing EMR json

__Arguments__

Expand Down Expand Up @@ -169,4 +169,3 @@ __Arguments__
__Returns__

`(Object)`: Elastigroup API response

3 changes: 1 addition & 2 deletions docs/clients/ocean/ocean_aws_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ __Returns__
OceanAwsClient.get_ocean_cluster(ocean_id: str)
```

Get an exsisting Ocean Cluster json
Get an existing Ocean Cluster json

__Arguments__

Expand Down Expand Up @@ -745,4 +745,3 @@ __Arguments__
__Returns__

`(Object)`: Ocean Delete Extended Resource Definition response

5 changes: 2 additions & 3 deletions docs/clients/subscription/subscription_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SubscriptionClient.update_event_subscription(subscription_id,
subscription)
```

Update an exsisting event subscription
Update an existing event subscription

__Arguments__

Expand Down Expand Up @@ -61,7 +61,7 @@ __Returns__
SubscriptionClient.get_event_subscription(subscription_id)
```

Get an exsisting event subscription json
Get an existing event subscription json

__Arguments__

Expand All @@ -86,4 +86,3 @@ __Arguments__
__Returns__

`(Object)`: subscription response

4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PyYaml==6.0.1
requests==2.31.0
pydoc-markdown==2.1.3
pydoc-markdown==2.1.3
mock==5.1.0
pytest==7.4.4
5 changes: 4 additions & 1 deletion spotinst_sdk2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ def client(self, service, print_output=True, log_level=None, user_agent=None, ti
log_level=log_level, user_agent=user_agent, timeout=timeout)
}

return switcher.get(service, "Invalid Service")
client = switcher.get(service)
if client is None:
raise ValueError(f"Invalid service selected: {service}")
return client
56 changes: 52 additions & 4 deletions spotinst_sdk2/clients/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ def create_user(self, first_name, last_name, email, password, role):

return formatted_response["response"]["items"][0]

def add_exsisting_user(self, user_email, role):
def add_existing_user(self, user_email, role):
"""
Add exsisting user
Add existing user
# Arguments
user_email (String): User email
Expand All @@ -215,7 +215,7 @@ def add_exsisting_user(self, user_email, role):

def update_user_role(self, user_email, role):
"""
Update exsisting user
Update existing user
# Arguments
user_email (String): User email
Expand All @@ -239,7 +239,7 @@ def update_user_role(self, user_email, role):

def detach_user(self, user_email):
"""
Delete exsisting user
Delete existing user
# Arguments
user_email (String): User email
Expand Down Expand Up @@ -311,3 +311,51 @@ def assign_user_to_account(self, mappings):
return formatted_response["response"]["status"]

# endregion
def get_users(self):
"""
Retrieves all users from an organization.
# Returns
(Object): Spotinst API response
"""
response = self.send_get(
url=self.__base_setup_url + "/organization/user", entity_name="user"
)

formatted_response = self.convert_json(response, self.camel_to_underscore)

return formatted_response["response"]["items"]

def get_user_details(self, user_id):
"""
Retrieves an individual user details.
# Arguments
user_id (String): User ID
# Returns
(Object): Spotinst API response
"""
response = self.send_get(
url=self.__base_setup_url + "/user/" + user_id, entity_name="user"
)

formatted_response = self.convert_json(response, self.camel_to_underscore)

return formatted_response["response"]["items"][0]

def delete_user(self, user_id):
"""
Deletes a user from an organization.
# Arguments
user_id (String): User ID
# Returns
(Object): Spotinst API response
"""
response = self.send_delete(
url=self.__base_setup_url + "/user/" + user_id, entity_name="user"
)

return response
4 changes: 2 additions & 2 deletions spotinst_sdk2/clients/mrscaler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_emr(self, emr):

def update_emr(self, emr_id, emr):
"""
Update an exsisting EMR
Update an existing EMR
# Arguments
emr_id (String): EMR id
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_all_emr(self):

def get_emr(self, emr_id):
"""
Get an exsisting EMR json
Get an existing EMR json
# Arguments
emr_id (String): EMR id
Expand Down
2 changes: 1 addition & 1 deletion spotinst_sdk2/clients/ocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def fetch_rightsizing_recommendations(self, ocean_id: str, filter: aws_ocean.Rig

def get_ocean_cluster(self, ocean_id: str):
"""
Get an exsisting Ocean Cluster json
Get an existing Ocean Cluster json
# Arguments
ocean_id (String): ID of the Ocean Cluster
Expand Down
4 changes: 2 additions & 2 deletions spotinst_sdk2/clients/subscription/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_event_subscription(self, subscription):

def update_event_subscription(self, subscription_id, subscription):
"""
Update an exsisting event subscription
Update an existing event subscription
# Arguments
subscription_id (String): Subscription id
Expand Down Expand Up @@ -97,7 +97,7 @@ def get_all_event_subscription(self):

def get_event_subscription(self, subscription_id):
"""
Get an exsisting event subscription json
Get an existing event subscription json
# Arguments
subscription_id (String): Subscription id
Expand Down
6 changes: 2 additions & 4 deletions spotinst_sdk2/test/admin/test_admin_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ def testCreateUser(self, mock):
self.assertEqual(len(response), len(mock_create_user_res["response"]["items"][0]))

@patch('requests.post')
def testAddExsistingUser(self, mock):
def testAddExistingUser(self, mock):
self.mock_api_call.content = SimpleNamespace(**self.mock_api_call.content)
self.mock_api_call.content.decode = lambda code: json.dumps(self.mock_ok_res)

mock.return_value = self.mock_api_call

response = self.client.add_exsisting_user(user_email="test", role="test")
response = self.client.add_existing_user(user_email="test", role="test")

self.assertEqual(len(response), len(self.mock_ok_res["response"]["status"]))

Expand Down Expand Up @@ -187,5 +187,3 @@ def testAssignUserToAccounts(self, mock):
response = self.client.assign_user_to_account(mappings=[])

self.assertEqual(len(response), len(self.mock_ok_res["response"]["status"]))


0 comments on commit a215cc3

Please sign in to comment.