IdentityStore: implement create_group (#5935)
This commit is contained in:
		
							parent
							
								
									b241c16726
								
							
						
					
					
						commit
						1c8511656e
					
				| @ -167,6 +167,7 @@ mock_xray = lazy_load(".xray", "mock_xray") | |||||||
| mock_xray_client = lazy_load(".xray", "mock_xray_client") | mock_xray_client = lazy_load(".xray", "mock_xray_client") | ||||||
| mock_wafv2 = lazy_load(".wafv2", "mock_wafv2") | mock_wafv2 = lazy_load(".wafv2", "mock_wafv2") | ||||||
| mock_textract = lazy_load(".textract", "mock_textract") | mock_textract = lazy_load(".textract", "mock_textract") | ||||||
|  | mock_identitystore = lazy_load(".identitystore", "mock_identitystore") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class MockAll(ContextDecorator): | class MockAll(ContextDecorator): | ||||||
|  | |||||||
| @ -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 | import re | ||||||
| 
 | 
 | ||||||
| backend_url_patterns = [ | backend_url_patterns = [ | ||||||
| @ -79,10 +79,13 @@ backend_url_patterns = [ | |||||||
|     ("greengrass", re.compile("https?://greengrass\\.(.+)\\.amazonaws.com")), |     ("greengrass", re.compile("https?://greengrass\\.(.+)\\.amazonaws.com")), | ||||||
|     ("guardduty", re.compile("https?://guardduty\\.(.+)\\.amazonaws\\.com")), |     ("guardduty", re.compile("https?://guardduty\\.(.+)\\.amazonaws\\.com")), | ||||||
|     ("iam", re.compile("https?://iam\\.(.*\\.)?amazonaws\\.com")), |     ("iam", re.compile("https?://iam\\.(.*\\.)?amazonaws\\.com")), | ||||||
|  |     ("identitystore", re.compile("https?://identitystore\\.(.+)\\.amazonaws\\.com")), | ||||||
|     ("iot", re.compile("https?://iot\\.(.+)\\.amazonaws\\.com")), |     ("iot", re.compile("https?://iot\\.(.+)\\.amazonaws\\.com")), | ||||||
|     ("iot-data", re.compile("https?://data\\.iot\\.(.+)\\.amazonaws.com")), |     ("iot-data", re.compile("https?://data\\.iot\\.(.+)\\.amazonaws.com")), | ||||||
|     ("iot-data", re.compile("https?://data-ats\\.iot\\.(.+)\\.amazonaws.com")), |     ("iot-data", re.compile("https?://data-ats\\.iot\\.(.+)\\.amazonaws.com")), | ||||||
|     ("kinesis", re.compile("https?://kinesis\\.(.+)\\.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")), |     ("kinesisvideo", re.compile("https?://kinesisvideo\\.(.+)\\.amazonaws.com")), | ||||||
|     ( |     ( | ||||||
|         "kinesis-video-archived-media", |         "kinesis-video-archived-media", | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								moto/identitystore/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								moto/identitystore/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @ -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
									
								
								moto/identitystore/exceptions.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								moto/identitystore/exceptions.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | """Exceptions raised by the identitystore service.""" | ||||||
							
								
								
									
										28
									
								
								moto/identitystore/models.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								moto/identitystore/models.py
									
									
									
									
									
										Normal file
									
								
							| @ -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
									
								
								moto/identitystore/responses.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								moto/identitystore/responses.py
									
									
									
									
									
										Normal file
									
								
							| @ -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
									
								
								moto/identitystore/urls.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								moto/identitystore/urls.py
									
									
									
									
									
										Normal file
									
								
							| @ -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, | ||||||
|  | } | ||||||
							
								
								
									
										0
									
								
								tests/test_identitystore/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/test_identitystore/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										24
									
								
								tests/test_identitystore/test_identitystore.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								tests/test_identitystore/test_identitystore.py
									
									
									
									
									
										Normal file
									
								
							| @ -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"]) | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user