Implement SSM Parameter Store filters support (GetParametersByPath API) (#1604)

* added tests for SSM Parameter Store filters (GetParametersByPath - ParameterStringFilter)

* implemented SSM Parameter Store filters support (only for get_parameters_by_path API)

* adding myself to authors file
This commit is contained in:
Alex Casalboni 2018-04-30 20:02:47 +02:00 committed by Jack Danger
commit cb364eedc6
4 changed files with 117 additions and 2 deletions

View file

@ -93,7 +93,7 @@ class SimpleSystemManagerBackend(BaseBackend):
result.append(self._parameters[name])
return result
def get_parameters_by_path(self, path, with_decryption, recursive):
def get_parameters_by_path(self, path, with_decryption, recursive, filters=None):
"""Implement the get-parameters-by-path-API in the backend."""
result = []
# path could be with or without a trailing /. we handle this
@ -104,10 +104,35 @@ class SimpleSystemManagerBackend(BaseBackend):
continue
if '/' in param[len(path) + 1:] and not recursive:
continue
if not self._match_filters(self._parameters[param], filters):
continue
result.append(self._parameters[param])
return result
@staticmethod
def _match_filters(parameter, filters=None):
"""Return True if the given parameter matches all the filters"""
for filter_obj in (filters or []):
key = filter_obj['Key']
option = filter_obj.get('Option', 'Equals')
values = filter_obj.get('Values', [])
what = None
if key == 'Type':
what = parameter.type
elif key == 'KeyId':
what = parameter.keyid
if option == 'Equals'\
and not any(what == value for value in values):
return False
elif option == 'BeginsWith'\
and not any(what.startswith(value) for value in values):
return False
# True if no false match (or no filters at all)
return True
def get_parameter(self, name, with_decryption):
if name in self._parameters:
return self._parameters[name]

View file

@ -85,9 +85,10 @@ class SimpleSystemManagerResponse(BaseResponse):
path = self._get_param('Path')
with_decryption = self._get_param('WithDecryption')
recursive = self._get_param('Recursive', False)
filters = self._get_param('ParameterFilters')
result = self.ssm_backend.get_parameters_by_path(
path, with_decryption, recursive
path, with_decryption, recursive, filters
)
response = {