Adding support for querying the AWS Config resource for S3.
- Need to add support still for batch requests and batch aggregation requests in a future PR
This commit is contained in:
parent
e71c06738c
commit
2a2c3e80f0
9 changed files with 746 additions and 23 deletions
|
|
@ -254,3 +254,25 @@ class TooManyResourceIds(JsonRESTError):
|
|||
def __init__(self):
|
||||
super(TooManyResourceIds, self).__init__('ValidationException', "The specified list had more than 20 resource ID's. "
|
||||
"It must have '20' or less items")
|
||||
|
||||
|
||||
class ResourceNotDiscoveredException(JsonRESTError):
|
||||
code = 400
|
||||
|
||||
def __init__(self, type, resource):
|
||||
super(ResourceNotDiscoveredException, self).__init__('ResourceNotDiscoveredException',
|
||||
'Resource {resource} of resourceType:{type} is unknown or has not been '
|
||||
'discovered'.format(resource=resource, type=type))
|
||||
|
||||
|
||||
class TooManyResourceKeys(JsonRESTError):
|
||||
code = 400
|
||||
|
||||
def __init__(self, bad_list):
|
||||
message = '1 validation error detected: Value \'{bad_list}\' at ' \
|
||||
'\'resourceKeys\' failed to satisfy constraint: ' \
|
||||
'Member must have length less than or equal to 100'.format(bad_list=bad_list)
|
||||
# For PY2:
|
||||
message = str(message)
|
||||
|
||||
super(TooManyResourceKeys, self).__init__("ValidationException", message)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ from moto.config.exceptions import InvalidResourceTypeException, InvalidDelivery
|
|||
InvalidSNSTopicARNException, MaxNumberOfDeliveryChannelsExceededException, NoAvailableDeliveryChannelException, \
|
||||
NoSuchDeliveryChannelException, LastDeliveryChannelDeleteFailedException, TagKeyTooBig, \
|
||||
TooManyTags, TagValueTooBig, TooManyAccountSources, InvalidParameterValueException, InvalidNextTokenException, \
|
||||
NoSuchConfigurationAggregatorException, InvalidTagCharacters, DuplicateTags, InvalidLimit, InvalidResourceParameters, TooManyResourceIds
|
||||
NoSuchConfigurationAggregatorException, InvalidTagCharacters, DuplicateTags, InvalidLimit, InvalidResourceParameters, \
|
||||
TooManyResourceIds, ResourceNotDiscoveredException
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.s3.config import s3_config_query
|
||||
|
|
@ -790,6 +791,39 @@ class ConfigBackend(BaseBackend):
|
|||
|
||||
return result
|
||||
|
||||
def get_resource_config_history(self, type, id, backend_region):
|
||||
"""Returns the configuration of an item in the AWS Config format of the resource for the current regional backend.
|
||||
|
||||
NOTE: This is --NOT-- returning history as it is not supported in moto at this time. (PR's welcome!)
|
||||
As such, the later_time, earlier_time, limit, and next_token are ignored as this will only
|
||||
return 1 item. (If no items, it raises an exception)
|
||||
"""
|
||||
# If the type isn't implemented then we won't find the item:
|
||||
if type not in RESOURCE_MAP:
|
||||
raise ResourceNotDiscoveredException(type, id)
|
||||
|
||||
# Is the resource type global?
|
||||
if RESOURCE_MAP[type].backends.get('global'):
|
||||
backend_region = 'global'
|
||||
|
||||
# If the backend region isn't implemented then we won't find the item:
|
||||
if not RESOURCE_MAP[type].backends.get(backend_region):
|
||||
raise ResourceNotDiscoveredException(type, id)
|
||||
|
||||
# Get the item:
|
||||
item = RESOURCE_MAP[type].get_config_resource(id, backend_region=backend_region)
|
||||
if not item:
|
||||
raise ResourceNotDiscoveredException(type, id)
|
||||
|
||||
item['accountId'] = DEFAULT_ACCOUNT_ID
|
||||
|
||||
return {'configurationItems': [item]}
|
||||
|
||||
def batch_get_resource_config(self, resource_keys, backend_region):
|
||||
"""Returns the configuration of an item in the AWS Config format of the resource for the current regional backend."""
|
||||
# Can't have more than 100 items
|
||||
pass
|
||||
|
||||
|
||||
config_backends = {}
|
||||
boto3_session = Session()
|
||||
|
|
|
|||
|
|
@ -102,6 +102,12 @@ class ConfigResponse(BaseResponse):
|
|||
self._get_param('NextToken'))
|
||||
return json.dumps(schema)
|
||||
|
||||
def get_resource_config_history(self):
|
||||
schema = self.config_backend.get_resource_config_history(self._get_param('resourceType'),
|
||||
self._get_param('resourceId'),
|
||||
self.region)
|
||||
return json.dumps(schema)
|
||||
|
||||
"""
|
||||
def batch_get_resource_config(self):
|
||||
# TODO implement me!
|
||||
|
|
@ -110,8 +116,4 @@ class ConfigResponse(BaseResponse):
|
|||
def batch_get_aggregate_resource_config(self):
|
||||
# TODO implement me!
|
||||
return ""
|
||||
|
||||
def get_resource_config_history(self):
|
||||
# TODO implement me!
|
||||
return ""
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue