Add get_parameter_history implementation and tests
This commit is contained in:
parent
b4fb4b3b5d
commit
aeb7974549
@ -527,7 +527,10 @@ class SimpleSystemManagerBackend(BaseBackend):
|
||||
|
||||
return result
|
||||
|
||||
return result
|
||||
def get_parameter_history(self, name, with_decryption):
|
||||
if name in self._parameters:
|
||||
return self._parameters[name]
|
||||
return None
|
||||
|
||||
def _match_filters(self, parameter, filters=None):
|
||||
"""Return True if the given parameter matches all the filters"""
|
||||
|
@ -139,6 +139,19 @@ class SimpleSystemManagerResponse(BaseResponse):
|
||||
response = {"Version": result}
|
||||
return json.dumps(response)
|
||||
|
||||
def get_parameter_history(self):
|
||||
name = self._get_param('Name')
|
||||
with_decryption = self._get_param("WithDecryption")
|
||||
|
||||
result = self.ssm_backend.get_parameter_history(name, with_decryption)
|
||||
|
||||
response = {"Parameters": []}
|
||||
for parameter_version in result:
|
||||
param_data = parameter_version.describe_response_object(decrypt=with_decryption)
|
||||
response['Parameters'].append(param_data)
|
||||
|
||||
return json.dumps(response)
|
||||
|
||||
def add_tags_to_resource(self):
|
||||
resource_id = self._get_param("ResourceId")
|
||||
resource_type = self._get_param("ResourceType")
|
||||
|
@ -813,6 +813,60 @@ def test_put_parameter_secure_custom_kms():
|
||||
response["Parameters"][0]["Value"].should.equal("value")
|
||||
response["Parameters"][0]["Type"].should.equal("SecureString")
|
||||
|
||||
@mock_ssm
|
||||
def test_get_parameter_history():
|
||||
client = boto3.client("ssm", region_name="us-east-1")
|
||||
|
||||
test_parameter_name = "test"
|
||||
|
||||
for i in range(3):
|
||||
client.put_parameter(
|
||||
Name=test_parameter_name, Description="A test parameter version %d" % i, Value="value-%d" % i, Type="String",
|
||||
Overwrite=True
|
||||
)
|
||||
|
||||
response = client.get_parameter_history(Name=test_parameter_name)
|
||||
parameters_response = response['Parameters']
|
||||
|
||||
for index, param in enumerate(parameters_response):
|
||||
param['Name'].should.equal(test_parameter_name)
|
||||
param['Type'].should.equal('String')
|
||||
param['Value'].should.equal('value-%d' % index)
|
||||
param['Version'].should.equal(index + 1)
|
||||
param['Description'].should.equal("A test parameter version %d" % index)
|
||||
|
||||
len(parameters_response).should.equal(3)
|
||||
|
||||
@mock_ssm
|
||||
def test_get_parameter_history_with_secure_string():
|
||||
client = boto3.client("ssm", region_name="us-east-1")
|
||||
|
||||
test_parameter_name = "test"
|
||||
|
||||
for i in range(3):
|
||||
client.put_parameter(
|
||||
Name=test_parameter_name, Description="A test parameter version %d" % i, Value="value-%d" % i, Type="SecureString",
|
||||
Overwrite=True
|
||||
)
|
||||
|
||||
for with_decryption in [True, False]:
|
||||
response = client.get_parameter_history(Name=test_parameter_name, WithDecryption=with_decryption)
|
||||
parameters_response = response['Parameters']
|
||||
|
||||
for index, param in enumerate(parameters_response):
|
||||
param['Name'].should.equal(test_parameter_name)
|
||||
param['Type'].should.equal('SecureString')
|
||||
expected_plaintext_value = 'value-%d' % index
|
||||
if with_decryption:
|
||||
param['Value'].should.equal(expected_plaintext_value)
|
||||
else:
|
||||
param['Value'].should.equal('kms:alias/aws/ssm:%s' % expected_plaintext_value)
|
||||
param['Version'].should.equal(index + 1)
|
||||
param['Description'].should.equal("A test parameter version %d" % index)
|
||||
|
||||
len(parameters_response).should.equal(3)
|
||||
|
||||
|
||||
|
||||
@mock_ssm
|
||||
def test_add_remove_list_tags_for_resource():
|
||||
|
Loading…
Reference in New Issue
Block a user