diff --git a/moto/ssm/models.py b/moto/ssm/models.py index bbb84ad91..a0e4a2155 100644 --- a/moto/ssm/models.py +++ b/moto/ssm/models.py @@ -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 diff --git a/moto/ssm/responses.py b/moto/ssm/responses.py index 7c31a6dd9..a2673f7e9 100644 --- a/moto/ssm/responses.py +++ b/moto/ssm/responses.py @@ -42,6 +42,25 @@ 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: + return '', 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') diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py index 7a783299b..859ec7a81 100644 --- a/tests/test_ssm/test_ssm_boto3.py +++ b/tests/test_ssm/test_ssm_boto3.py @@ -66,6 +66,25 @@ 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_describe_parameters(): client = boto3.client('ssm', region_name='us-east-1')