Skip to content

Commit

Permalink
IdentityStore: implement create_group (#5935)
Browse files Browse the repository at this point in the history
  • Loading branch information
dana-orca authored Feb 18, 2023
1 parent b241c16 commit 1c85116
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 1 deletion.
1 change: 1 addition & 0 deletions moto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def f(*args, **kwargs):
mock_xray_client = lazy_load(".xray", "mock_xray_client")
mock_wafv2 = lazy_load(".wafv2", "mock_wafv2")
mock_textract = lazy_load(".textract", "mock_textract")
mock_identitystore = lazy_load(".identitystore", "mock_identitystore")


class MockAll(ContextDecorator):
Expand Down
5 changes: 4 additions & 1 deletion moto/backend_index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# autogenerated by scripts/update_backend_index.py
# autogenerated by /Users/danaronson/GitHub/forks/moto/scripts/update_backend_index.py
import re

backend_url_patterns = [
Expand Down Expand Up @@ -79,10 +79,13 @@
("greengrass", re.compile("https?://greengrass\\.(.+)\\.amazonaws.com")),
("guardduty", re.compile("https?://guardduty\\.(.+)\\.amazonaws\\.com")),
("iam", re.compile("https?://iam\\.(.*\\.)?amazonaws\\.com")),
("identitystore", re.compile("https?://identitystore\\.(.+)\\.amazonaws\\.com")),
("iot", re.compile("https?://iot\\.(.+)\\.amazonaws\\.com")),
("iot-data", re.compile("https?://data\\.iot\\.(.+)\\.amazonaws.com")),
("iot-data", re.compile("https?://data-ats\\.iot\\.(.+)\\.amazonaws.com")),
("kinesis", re.compile("https?://kinesis\\.(.+)\\.amazonaws\\.com")),
("kinesis", re.compile("https?://(.+)\\.control-kinesis\\.(.+)\\.amazonaws\\.com")),
("kinesis", re.compile("https?://(.+)\\.data-kinesis\\.(.+)\\.amazonaws\\.com")),
("kinesisvideo", re.compile("https?://kinesisvideo\\.(.+)\\.amazonaws.com")),
(
"kinesis-video-archived-media",
Expand Down
5 changes: 5 additions & 0 deletions moto/identitystore/__init__.py
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)
1 change: 1 addition & 0 deletions moto/identitystore/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Exceptions raised by the identitystore service."""
28 changes: 28 additions & 0 deletions moto/identitystore/models.py
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")
34 changes: 34 additions & 0 deletions moto/identitystore/responses.py
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)
10 changes: 10 additions & 0 deletions moto/identitystore/urls.py
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.
24 changes: 24 additions & 0 deletions tests/test_identitystore/test_identitystore.py
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"])

0 comments on commit 1c85116

Please sign in to comment.