Skip to content

Commit

Permalink
change cloud alias api (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanag13 committed Apr 21, 2020
1 parent 40f981a commit 1a161f4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.

## 1.0.0 - 2020-04-21

## Changed

- `sdk.detectionlists` methods:
- `add_cloud_aliases()` > `add_cloud_alias()`
- `remove_cloud_aliases()` > `remove_cloud_alias`.

The above methods no longer support lists for their `alias` parameter.

## 0.9.0 - 2020-04-17

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/py42/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# py42

__version__ = "0.9.0"
__version__ = "1.0.0"
22 changes: 7 additions & 15 deletions src/py42/_internal/clients/detection_list_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,46 +151,38 @@ def remove_risk_tags(self, user_id, tags):
uri = self._make_uri(u"/removeriskfactors")
return self._session.post(uri, data=json.dumps(data))

def add_cloud_aliases(self, user_id, aliases):
"""Add one or more cloud alias.
def add_cloud_alias(self, user_id, alias):
"""Add a cloud alias.
Args:
user_id (str or int): The user_id whose alias(es) need to be updated.
aliases (str or list of str ): A single alias or multiple aliases in a list to be added.
e.g u"x" or ["email@id", "y"], for python version 2.X, pass u"str" instead of "str"
alias (str): An alias to be added.
Returns:
:class:`py42.response.Py42Response`
"""
if type(aliases) is str:
aliases = [aliases]

data = {
u"tenantId": self._user_context.get_current_tenant_id(),
u"userId": user_id,
u"cloudUsernames": aliases,
u"cloudUsernames": [alias],
}
uri = self._make_uri(u"/addcloudusernames")
return self._session.post(uri, data=json.dumps(data))

def remove_cloud_aliases(self, user_id, aliases):
def remove_cloud_alias(self, user_id, alias):
"""Remove one or more cloud alias.
Args:
user_id (str or int): The user_id whose alias(es) need to be removed.
aliases (str or list of str ): A single alias or multiple aliases in a list to be removed.
e.g u"x" or ["email@id", "y"], for python version 2.X, pass u"str" instead of "str"
alias (str): An alias to be removed.
Returns:
:class:`py42.response.Py42Response`
"""
if type(aliases) is str:
aliases = [aliases]

data = {
u"tenantId": self._user_context.get_current_tenant_id(),
u"userId": user_id,
u"cloudUsernames": aliases,
u"cloudUsernames": [alias],
}
uri = self._make_uri(u"/removecloudusernames")
return self._session.post(uri, data=json.dumps(data))
4 changes: 2 additions & 2 deletions tests/_internal/clients/test_detection_list_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_add_cloud_alias_posts_expected_data(
detection_list_user_client = DetectionListUserClient(
mock_session, user_context, mock_user_client
)
detection_list_user_client.add_cloud_aliases("942897397520289999", u"Test")
detection_list_user_client.add_cloud_alias("942897397520289999", u"Test")

posted_data = json.loads(mock_session.post.call_args[1]["data"])
assert mock_session.post.call_count == 1
Expand All @@ -144,7 +144,7 @@ def test_remove_cloud_alias_posts_expected_data(
detection_list_user_client = DetectionListUserClient(
mock_session, user_context, mock_user_client
)
detection_list_user_client.remove_cloud_aliases("942897397520289999", u"Test")
detection_list_user_client.remove_cloud_alias("942897397520289999", u"Test")

posted_data = json.loads(mock_session.post.call_args[1]["data"])
assert mock_session.post.call_count == 1
Expand Down

0 comments on commit 1a161f4

Please sign in to comment.