SSM: missing type from param update response (#6436)

This commit is contained in:
rafcio19 2023-06-23 21:46:07 +01:00 committed by GitHub
parent dab6318f90
commit 7e2cd92320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 8 deletions

View File

@ -213,7 +213,7 @@ class Parameter(CloudFormationModel):
): ):
self.account_id = account_id self.account_id = account_id
self.name = name self.name = name
self.type = parameter_type self.parameter_type = parameter_type
self.description = description self.description = description
self.allowed_pattern = allowed_pattern self.allowed_pattern = allowed_pattern
self.keyid = keyid self.keyid = keyid
@ -224,7 +224,7 @@ class Parameter(CloudFormationModel):
self.labels = labels or [] self.labels = labels or []
self.source_result = source_result self.source_result = source_result
if self.type == "SecureString": if self.parameter_type == "SecureString":
if not self.keyid: if not self.keyid:
self.keyid = "alias/aws/ssm" self.keyid = "alias/aws/ssm"
@ -236,7 +236,7 @@ class Parameter(CloudFormationModel):
return f"kms:{self.keyid}:" + value return f"kms:{self.keyid}:" + value
def decrypt(self, value: str) -> Optional[str]: def decrypt(self, value: str) -> Optional[str]:
if self.type != "SecureString": if self.parameter_type != "SecureString":
return value return value
prefix = f"kms:{self.keyid or 'default'}:" prefix = f"kms:{self.keyid or 'default'}:"
@ -249,7 +249,7 @@ class Parameter(CloudFormationModel):
) -> Dict[str, Any]: ) -> Dict[str, Any]:
r: Dict[str, Any] = { r: Dict[str, Any] = {
"Name": self.name, "Name": self.name,
"Type": self.type, "Type": self.parameter_type,
"Value": self.decrypt(self.value) if decrypt else self.value, "Value": self.decrypt(self.value) if decrypt else self.value,
"Version": self.version, "Version": self.version,
"LastModifiedDate": round(self.last_modified_date, 3), "LastModifiedDate": round(self.last_modified_date, 3),
@ -1507,7 +1507,7 @@ class SimpleSystemManagerBackend(BaseBackend):
break break
elif _filter["Key"] == "Type": elif _filter["Key"] == "Type":
for v in _filter["Values"]: for v in _filter["Values"]:
if ssm_parameter.type == v: if ssm_parameter.parameter_type == v:
result.append(ssm_parameter) result.append(ssm_parameter)
break break
elif _filter["Key"] == "KeyId": elif _filter["Key"] == "KeyId":
@ -1793,7 +1793,7 @@ class SimpleSystemManagerBackend(BaseBackend):
what = "/" + parameter.name.lstrip("/") what = "/" + parameter.name.lstrip("/")
values = ["/" + value.strip("/") for value in values] values = ["/" + value.strip("/") for value in values]
elif key == "Type": elif key == "Type":
what = parameter.type what = parameter.parameter_type
elif key == "Label": elif key == "Label":
what = parameter.labels what = parameter.labels
# Label filter can only have option="Equals" (also valid implicitly) # Label filter can only have option="Equals" (also valid implicitly)
@ -1994,7 +1994,10 @@ class SimpleSystemManagerBackend(BaseBackend):
"formed as a mix of letters, numbers and the following 3 symbols .-_" "formed as a mix of letters, numbers and the following 3 symbols .-_"
) )
raise ValidationException(invalid_prefix_error) raise ValidationException(invalid_prefix_error)
if not parameter_type and not overwrite and not self._parameters[name]:
raise ValidationException(
"A parameter type is required when you create a parameter."
)
if ( if (
not _valid_parameter_type(parameter_type) not _valid_parameter_type(parameter_type)
and not overwrite and not overwrite
@ -2022,6 +2025,9 @@ class SimpleSystemManagerBackend(BaseBackend):
if not overwrite: if not overwrite:
return None return None
# overwriting a parameter, Type is not included in boto3 call
if not parameter_type and overwrite:
parameter_type = previous_parameter.parameter_type
if len(previous_parameter_versions) >= PARAMETER_VERSION_LIMIT: if len(previous_parameter_versions) >= PARAMETER_VERSION_LIMIT:
self._check_for_parameter_version_limit_exception(name) self._check_for_parameter_version_limit_exception(name)

View File

@ -431,16 +431,35 @@ def test_put_parameter_invalid_type():
) )
@mock_ssm
def test_put_parameter_no_type():
client = boto3.client("ssm", "us-east-1")
with pytest.raises(ClientError) as e:
client.put_parameter(
Name="test_name",
Value="some_value",
)
ex = e.value
assert ex.operation_name == "PutParameter"
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
assert ex.response["Error"]["Code"] == "ValidationException"
assert (
ex.response["Error"]["Message"]
== "A parameter type is required when you create a parameter."
)
@mock_ssm @mock_ssm
def test_update_parameter(): def test_update_parameter():
# Setup # Setup
client = boto3.client("ssm", "us-east-1") client = boto3.client("ssm", "us-east-1")
param_name = "test_param" param_name = "test_param"
param_type = "String"
updated_value = "UpdatedValue" updated_value = "UpdatedValue"
client.put_parameter( client.put_parameter(
Description="Description", Description="Description",
Name=param_name, Name=param_name,
Type="String", Type=param_type,
Value="Value", Value="Value",
) )
@ -454,6 +473,7 @@ def test_update_parameter():
# Verify # Verify
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
assert new_param["Parameter"]["Type"] == param_type
assert new_param["Parameter"]["Value"] == updated_value assert new_param["Parameter"]["Value"] == updated_value