Merge pull request #2611 from Sytten/fix/ssm-parameter

Add missing information in SSM parameters
This commit is contained in:
Mike Grima 2019-12-16 11:59:42 -08:00 committed by GitHub
commit 65b17e740d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 5 deletions

View file

@ -13,6 +13,7 @@ import time
import uuid
import itertools
from .utils import parameter_arn
from .exceptions import (
ValidationException,
InvalidFilterValue,
@ -60,19 +61,23 @@ class Parameter(BaseModel):
if value.startswith(prefix):
return value[len(prefix) :]
def response_object(self, decrypt=False):
def response_object(self, decrypt=False, region=None):
r = {
"Name": self.name,
"Type": self.type,
"Value": self.decrypt(self.value) if decrypt else self.value,
"Version": self.version,
"LastModifiedDate": round(self.last_modified_date, 3),
}
if region:
r["ARN"] = parameter_arn(region, self.name)
return r
def describe_response_object(self, decrypt=False):
r = self.response_object(decrypt)
r["LastModifiedDate"] = int(self.last_modified_date)
r["LastModifiedDate"] = round(self.last_modified_date, 3)
r["LastModifiedUser"] = "N/A"
if self.description:

View file

@ -51,7 +51,7 @@ class SimpleSystemManagerResponse(BaseResponse):
}
return json.dumps(error), dict(status=400)
response = {"Parameter": result.response_object(with_decryption)}
response = {"Parameter": result.response_object(with_decryption, self.region)}
return json.dumps(response)
def get_parameters(self):
@ -63,7 +63,7 @@ class SimpleSystemManagerResponse(BaseResponse):
response = {"Parameters": [], "InvalidParameters": []}
for parameter in result:
param_data = parameter.response_object(with_decryption)
param_data = parameter.response_object(with_decryption, self.region)
response["Parameters"].append(param_data)
param_names = [param.name for param in result]
@ -92,7 +92,7 @@ class SimpleSystemManagerResponse(BaseResponse):
response = {"Parameters": [], "NextToken": next_token}
for parameter in result:
param_data = parameter.response_object(with_decryption)
param_data = parameter.response_object(with_decryption, self.region)
response["Parameters"].append(param_data)
return json.dumps(response)

9
moto/ssm/utils.py Normal file
View file

@ -0,0 +1,9 @@
ACCOUNT_ID = "1234567890"
def parameter_arn(region, parameter_name):
if parameter_name[0] == "/":
parameter_name = parameter_name[1:]
return "arn:aws:ssm:{0}:{1}:parameter/{2}".format(
region, ACCOUNT_ID, parameter_name
)