Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSM: missing type from param update response #6436

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions moto/ssm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def __init__(
):
self.account_id = account_id
self.name = name
self.type = parameter_type
self.parameter_type = parameter_type
self.description = description
self.allowed_pattern = allowed_pattern
self.keyid = keyid
Expand All @@ -224,7 +224,7 @@ def __init__(
self.labels = labels or []
self.source_result = source_result

if self.type == "SecureString":
if self.parameter_type == "SecureString":
if not self.keyid:
self.keyid = "alias/aws/ssm"

Expand All @@ -236,7 +236,7 @@ def encrypt(self, value: str) -> str:
return f"kms:{self.keyid}:" + value

def decrypt(self, value: str) -> Optional[str]:
if self.type != "SecureString":
if self.parameter_type != "SecureString":
return value

prefix = f"kms:{self.keyid or 'default'}:"
Expand All @@ -249,7 +249,7 @@ def response_object(
) -> Dict[str, Any]:
r: Dict[str, Any] = {
"Name": self.name,
"Type": self.type,
"Type": self.parameter_type,
"Value": self.decrypt(self.value) if decrypt else self.value,
"Version": self.version,
"LastModifiedDate": round(self.last_modified_date, 3),
Expand Down Expand Up @@ -1507,7 +1507,7 @@ def describe_parameters(
break
elif _filter["Key"] == "Type":
for v in _filter["Values"]:
if ssm_parameter.type == v:
if ssm_parameter.parameter_type == v:
result.append(ssm_parameter)
break
elif _filter["Key"] == "KeyId":
Expand Down Expand Up @@ -1793,7 +1793,7 @@ def _match_filters(
what = "/" + parameter.name.lstrip("/")
values = ["/" + value.strip("/") for value in values]
elif key == "Type":
what = parameter.type
what = parameter.parameter_type
elif key == "Label":
what = parameter.labels
# Label filter can only have option="Equals" (also valid implicitly)
Expand Down Expand Up @@ -1994,7 +1994,10 @@ def put_parameter(
"formed as a mix of letters, numbers and the following 3 symbols .-_"
)
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 (
not _valid_parameter_type(parameter_type)
and not overwrite
Expand Down Expand Up @@ -2022,6 +2025,9 @@ def put_parameter(

if not overwrite:
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:
self._check_for_parameter_version_limit_exception(name)
Expand Down
22 changes: 21 additions & 1 deletion tests/test_ssm/test_ssm_boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
def test_update_parameter():
# Setup
client = boto3.client("ssm", "us-east-1")
param_name = "test_param"
param_type = "String"
updated_value = "UpdatedValue"
client.put_parameter(
Description="Description",
Name=param_name,
Type="String",
Type=param_type,
Value="Value",
)

Expand All @@ -454,6 +473,7 @@ def test_update_parameter():

# Verify
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
assert new_param["Parameter"]["Type"] == param_type
assert new_param["Parameter"]["Value"] == updated_value


Expand Down