-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IdentityStore: implement create_group (#5935)
- Loading branch information
Showing
9 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""identitystore module initialization; sets value for base decorator.""" | ||
from .models import identitystore_backends | ||
from ..core.models import base_decorator | ||
|
||
mock_identitystore = base_decorator(identitystore_backends) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Exceptions raised by the identitystore service.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""IdentityStoreBackend class with methods for supported APIs.""" | ||
from moto.moto_api._internal import mock_random | ||
|
||
from moto.core import BaseBackend, BackendDict | ||
|
||
|
||
class IdentityStoreBackend(BaseBackend): | ||
"""Implementation of IdentityStore APIs.""" | ||
|
||
def __init__(self, region_name, account_id): | ||
super().__init__(region_name, account_id) | ||
self.groups = {} | ||
|
||
# add methods from here | ||
|
||
def create_group(self, identity_store_id, display_name, description): | ||
group_id = str(mock_random.uuid4()) | ||
group_dict = { | ||
"GroupId": group_id, | ||
"IdentityStoreId": identity_store_id, | ||
"DisplayName": display_name, | ||
"Description": description, | ||
} | ||
self.groups[group_id] = group_dict | ||
return group_id, identity_store_id | ||
|
||
|
||
identitystore_backends = BackendDict(IdentityStoreBackend, "identitystore") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Handles incoming identitystore requests, invokes methods, returns responses.""" | ||
import json | ||
|
||
from moto.core.responses import BaseResponse | ||
from .models import identitystore_backends | ||
|
||
|
||
class IdentityStoreResponse(BaseResponse): | ||
"""Handler for IdentityStore requests and responses.""" | ||
|
||
def __init__(self): | ||
super().__init__(service_name="identitystore") | ||
|
||
@property | ||
def identitystore_backend(self): | ||
"""Return backend instance specific for this region.""" | ||
return identitystore_backends[self.current_account][self.region] | ||
|
||
# add methods from here | ||
|
||
def create_group(self): | ||
params = self._get_params() | ||
identity_store_id = params.get("IdentityStoreId") | ||
display_name = params.get("DisplayName") | ||
description = params.get("Description") | ||
group_id, identity_store_id = self.identitystore_backend.create_group( | ||
identity_store_id=identity_store_id, | ||
display_name=display_name, | ||
description=description, | ||
) | ||
return json.dumps(dict(GroupId=group_id, IdentityStoreId=identity_store_id)) | ||
|
||
def _get_params(self): | ||
return json.loads(self.body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""identitystore base URL and path.""" | ||
from .responses import IdentityStoreResponse | ||
|
||
url_bases = [ | ||
r"https?://identitystore\.(.+)\.amazonaws\.com", | ||
] | ||
|
||
url_paths = { | ||
"{0}/$": IdentityStoreResponse.dispatch, | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Unit tests for identitystore-supported APIs.""" | ||
from uuid import UUID | ||
|
||
import boto3 | ||
import sure # noqa # pylint: disable=unused-import | ||
|
||
from moto import mock_identitystore | ||
|
||
|
||
# See our Development Tips on writing tests for hints on how to write good tests: | ||
# http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html | ||
|
||
|
||
@mock_identitystore | ||
def test_create_group(): | ||
client = boto3.client("identitystore", region_name="ap-southeast-1") | ||
identity_store_id = "d-9067028cf5" | ||
create_resp = client.create_group( | ||
IdentityStoreId=identity_store_id, | ||
DisplayName="test_group", | ||
Description="description", | ||
) | ||
assert create_resp["IdentityStoreId"] == identity_store_id | ||
assert UUID(create_resp["GroupId"]) |