Fixed bug in new Config recorder logic (#6434)

This commit is contained in:
Mike Grima 2023-06-23 06:23:52 -04:00 committed by GitHub
parent 9a247d5943
commit 10106d76d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -1226,7 +1226,10 @@ class ConfigBackend(BaseBackend):
if rgroup.get("allSupported", False):
if (
rgroup.get("resourceTypes", [])
or rgroup.get("exclusionByResourceTypes", {})
or (
rgroup.get("exclusionByResourceTypes", {"resourceTypes": []})
!= {"resourceTypes": []}
)
or recording_strategy not in {None, "ALL_SUPPORTED_RESOURCE_TYPES"}
):
raise InvalidRecordingGroupException()
@ -1245,7 +1248,10 @@ class ConfigBackend(BaseBackend):
elif rgroup.get("resourceTypes", []):
if (
rgroup.get("includeGlobalResourceTypes", False)
or rgroup.get("exclusionByResourceTypes", {})
or (
rgroup.get("exclusionByResourceTypes", {"resourceTypes": []})
!= {"resourceTypes": []}
)
or recording_strategy not in {None, "INCLUSION_BY_RESOURCE_TYPES"}
):
raise InvalidRecordingGroupException()

View File

@ -95,6 +95,10 @@ def test_put_configuration_recorder():
"exclusionByResourceTypes": {"resourceTypes": []},
"recordingStrategy": {"useOnly": "EXCLUSION_BY_RESOURCE_TYPES"},
},
{
"resourceTypes": ["AWS::S3::Bucket"],
"exclusionByResourceTypes": {"resourceTypes": ["AWS::S3::Bucket"]},
},
{"includeGlobalResourceTypes": False, "resourceTypes": []},
{"includeGlobalResourceTypes": True},
{"resourceTypes": []},
@ -199,6 +203,7 @@ def test_put_configuration_recorder():
"allSupported": False,
"includeGlobalResourceTypes": False,
"resourceTypes": ["AWS::EC2::Volume", "AWS::EC2::VPC"],
"exclusionByResourceTypes": {"resourceTypes": []},
},
}
)
@ -256,6 +261,24 @@ def test_put_configuration_recorder():
"recordingGroup"
]["allSupported"]
# Try this again, but this time, supply all the excess fields as empty:
client.put_configuration_recorder(
ConfigurationRecorder={
"name": "testrecorder",
"roleARN": "somearn",
"recordingGroup": {
"allSupported": True,
"includeGlobalResourceTypes": True,
"resourceTypes": [],
"exclusionByResourceTypes": {"resourceTypes": []},
"recordingStrategy": {"useOnly": "ALL_SUPPORTED_RESOURCE_TYPES"},
},
}
)
assert client.describe_configuration_recorders()["ConfigurationRecorders"][0][
"recordingGroup"
]["allSupported"]
# Update again for exclusions:
client.put_configuration_recorder(
ConfigurationRecorder={