Merge pull request #1156 from terrycain/master
Added SSM GetParameter support
This commit is contained in:
commit
066382fabc
@ -75,6 +75,11 @@ class SimpleSystemManagerBackend(BaseBackend):
|
||||
result.append(self._parameters[name])
|
||||
return result
|
||||
|
||||
def get_parameter(self, name, with_decryption):
|
||||
if name in self._parameters:
|
||||
return self._parameters[name]
|
||||
return None
|
||||
|
||||
def put_parameter(self, name, description, value, type, keyid, overwrite):
|
||||
if not overwrite and name in self._parameters:
|
||||
return
|
||||
|
@ -42,6 +42,29 @@ class SimpleSystemManagerResponse(BaseResponse):
|
||||
response['InvalidParameters'].append(name)
|
||||
return json.dumps(response)
|
||||
|
||||
def get_parameter(self):
|
||||
name = self._get_param('Name')
|
||||
with_decryption = self._get_param('WithDecryption')
|
||||
|
||||
result = self.ssm_backend.get_parameter(name, with_decryption)
|
||||
|
||||
if result is None:
|
||||
error = {
|
||||
'__type': 'ParameterNotFound',
|
||||
'message': 'Parameter {0} not found.'.format(name)
|
||||
}
|
||||
return json.dumps(error), dict(status=400)
|
||||
|
||||
response = {
|
||||
'Parameter': {
|
||||
'Name': name,
|
||||
'Type': result.type,
|
||||
'Value': result.value
|
||||
}
|
||||
}
|
||||
|
||||
return json.dumps(response)
|
||||
|
||||
def get_parameters(self):
|
||||
names = self._get_param('Names')
|
||||
with_decryption = self._get_param('WithDecryption')
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import boto3
|
||||
import botocore.exceptions
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_ssm
|
||||
@ -24,6 +25,7 @@ def test_delete_parameter():
|
||||
response = client.get_parameters(Names=['test'])
|
||||
len(response['Parameters']).should.equal(0)
|
||||
|
||||
|
||||
@mock_ssm
|
||||
def test_delete_parameters():
|
||||
client = boto3.client('ssm', region_name='us-east-1')
|
||||
@ -44,6 +46,7 @@ def test_delete_parameters():
|
||||
response = client.get_parameters(Names=['test'])
|
||||
len(response['Parameters']).should.equal(0)
|
||||
|
||||
|
||||
@mock_ssm
|
||||
def test_put_parameter():
|
||||
client = boto3.client('ssm', region_name='us-east-1')
|
||||
@ -66,6 +69,39 @@ def test_put_parameter():
|
||||
response['Parameters'][0]['Type'].should.equal('String')
|
||||
|
||||
|
||||
@mock_ssm
|
||||
def test_get_parameter():
|
||||
client = boto3.client('ssm', region_name='us-east-1')
|
||||
|
||||
client.put_parameter(
|
||||
Name='test',
|
||||
Description='A test parameter',
|
||||
Value='value',
|
||||
Type='String')
|
||||
|
||||
response = client.get_parameter(
|
||||
Name='test',
|
||||
WithDecryption=False)
|
||||
|
||||
response['Parameter']['Name'].should.equal('test')
|
||||
response['Parameter']['Value'].should.equal('value')
|
||||
response['Parameter']['Type'].should.equal('String')
|
||||
|
||||
|
||||
@mock_ssm
|
||||
def test_get_nonexistant_parameter():
|
||||
client = boto3.client('ssm', region_name='us-east-1')
|
||||
|
||||
try:
|
||||
client.get_parameter(
|
||||
Name='test_noexist',
|
||||
WithDecryption=False)
|
||||
raise RuntimeError('Should of failed')
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.operation_name.should.equal('GetParameter')
|
||||
err.response['Error']['Message'].should.equal('Parameter test_noexist not found.')
|
||||
|
||||
|
||||
@mock_ssm
|
||||
def test_describe_parameters():
|
||||
client = boto3.client('ssm', region_name='us-east-1')
|
||||
@ -279,6 +315,7 @@ 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_add_remove_list_tags_for_resource():
|
||||
client = boto3.client('ssm', region_name='us-east-1')
|
||||
|
Loading…
Reference in New Issue
Block a user