Make putparameter behave more like the real endpoint does, respond with Version or ParameterAlreadyExists (#1464)
This commit is contained in:
parent
5d51329c34
commit
508b392697
@ -126,6 +126,7 @@ class SimpleSystemManagerBackend(BaseBackend):
|
||||
last_modified_date = time.time()
|
||||
self._parameters[name] = Parameter(
|
||||
name, value, type, description, keyid, last_modified_date, version)
|
||||
return version
|
||||
|
||||
def add_tags_to_resource(self, resource_type, resource_id, tags):
|
||||
for key, value in tags.items():
|
||||
|
@ -162,9 +162,18 @@ class SimpleSystemManagerResponse(BaseResponse):
|
||||
keyid = self._get_param('KeyId')
|
||||
overwrite = self._get_param('Overwrite', False)
|
||||
|
||||
self.ssm_backend.put_parameter(
|
||||
result = self.ssm_backend.put_parameter(
|
||||
name, description, value, type_, keyid, overwrite)
|
||||
return json.dumps({})
|
||||
|
||||
if result is None:
|
||||
error = {
|
||||
'__type': 'ParameterAlreadyExists',
|
||||
'message': 'Parameter {0} already exists.'.format(name)
|
||||
}
|
||||
return json.dumps(error), dict(status=400)
|
||||
|
||||
response = {'Version': result}
|
||||
return json.dumps(response)
|
||||
|
||||
def add_tags_to_resource(self):
|
||||
resource_id = self._get_param('ResourceId')
|
||||
|
@ -97,12 +97,14 @@ def test_get_parameters_by_path():
|
||||
def test_put_parameter():
|
||||
client = boto3.client('ssm', region_name='us-east-1')
|
||||
|
||||
client.put_parameter(
|
||||
response = client.put_parameter(
|
||||
Name='test',
|
||||
Description='A test parameter',
|
||||
Value='value',
|
||||
Type='String')
|
||||
|
||||
response['Version'].should.equal(1)
|
||||
|
||||
response = client.get_parameters(
|
||||
Names=[
|
||||
'test'
|
||||
@ -115,11 +117,16 @@ def test_put_parameter():
|
||||
response['Parameters'][0]['Type'].should.equal('String')
|
||||
response['Parameters'][0]['Version'].should.equal(1)
|
||||
|
||||
client.put_parameter(
|
||||
Name='test',
|
||||
Description='desc 2',
|
||||
Value='value 2',
|
||||
Type='String')
|
||||
try:
|
||||
client.put_parameter(
|
||||
Name='test',
|
||||
Description='desc 2',
|
||||
Value='value 2',
|
||||
Type='String')
|
||||
raise RuntimeError('Should fail')
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal('PutParameter')
|
||||
err.response['Error']['Message'].should.equal('Parameter test already exists.')
|
||||
|
||||
response = client.get_parameters(
|
||||
Names=[
|
||||
@ -134,13 +141,15 @@ def test_put_parameter():
|
||||
response['Parameters'][0]['Type'].should.equal('String')
|
||||
response['Parameters'][0]['Version'].should.equal(1)
|
||||
|
||||
client.put_parameter(
|
||||
response = client.put_parameter(
|
||||
Name='test',
|
||||
Description='desc 3',
|
||||
Value='value 3',
|
||||
Type='String',
|
||||
Overwrite=True)
|
||||
|
||||
response['Version'].should.equal(2)
|
||||
|
||||
response = client.get_parameters(
|
||||
Names=[
|
||||
'test'
|
||||
|
Loading…
Reference in New Issue
Block a user