Added support for SSM get_parameters_by_path. (#1299)

* Added support for SSM get_parameters_by_path.

Signed-off-by: Kai Xia <xiaket@gmail.com>

* add logic to handle trailing '/'.

Also, fix pep8.

Signed-off-by: Kai Xia <kai.xia@sportsbet.com.au>

* add tests for parameter value in response.

Signed-off-by: Kai Xia <kai.xia@sportsbet.com.au>
This commit is contained in:
Kai Xia(夏恺) 2017-11-06 20:44:54 +11:00 committed by Jack Danger
commit 70e7f08d8f
3 changed files with 79 additions and 0 deletions

View file

@ -75,6 +75,21 @@ class SimpleSystemManagerBackend(BaseBackend):
result.append(self._parameters[name])
return result
def get_parameters_by_path(self, path, with_decryption, recursive):
"""Implement the get-parameters-by-path-API in the backend."""
result = []
# path could be with or without a trailing /. we handle this
# difference here.
path = path.rstrip('/') + '/'
for param in self._parameters:
if not param.startswith(path):
continue
if '/' in param[len(path) + 1:] and not recursive:
continue
result.append(self._parameters[param])
return result
def get_parameter(self, name, with_decryption):
if name in self._parameters:
return self._parameters[name]

View file

@ -81,6 +81,25 @@ class SimpleSystemManagerResponse(BaseResponse):
response['InvalidParameters'].append(name)
return json.dumps(response)
def get_parameters_by_path(self):
path = self._get_param('Path')
with_decryption = self._get_param('WithDecryption')
recursive = self._get_param('Recursive', False)
result = self.ssm_backend.get_parameters_by_path(
path, with_decryption, recursive
)
response = {
'Parameters': [],
}
for parameter in result:
param_data = parameter.response_object(with_decryption)
response['Parameters'].append(param_data)
return json.dumps(response)
def describe_parameters(self):
page_size = 10
filters = self._get_param('Filters')