Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
tekumara committed Nov 25, 2024
1 parent a34c7cc commit 8e4ab34
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/aec/command/ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,30 @@ def patch_summary(config: Config) -> Iterator[dict[str, Any]]:
}


def compliance_summary(config: Config) -> list[dict[str, Any]]:
def compliance_summary(config: Config) -> Iterator[dict[str, Any]]:
"""Compliance summary for instances that have run the patch baseline."""
instances_names = describe_instances_names(config)

kwargs: dict[str, Any] = {"Filters": [{"Key": "ComplianceType", "Values": ["Patch"], "Type": "EQUAL"}]}
client = boto3.client("ssm", region_name=config.get("region", None))

response = client.list_resource_compliance_summaries(
Filters=[{"Key": "ComplianceType", "Values": ["Patch"], "Type": "EQUAL"}]
)
while True:
response = client.list_resource_compliance_summaries(**kwargs)

return [
{
"InstanceId": i["ResourceId"],
"Name": instances_names.get(i["ResourceId"], None),
"Status": i["Status"],
"NonCompliantCount": i["NonCompliantSummary"]["NonCompliantCount"],
"Last operation time": i["ExecutionSummary"]["ExecutionTime"],
}
for i in response["ResourceComplianceSummaryItems"]
]
for i in response["ResourceComplianceSummaryItems"]:
yield {
"InstanceId": i["ResourceId"],
"Name": instances_names.get(i["ResourceId"], None),
"Status": i["Status"],
"NonCompliantCount": i["NonCompliantSummary"]["NonCompliantCount"],
"Last operation time": i["ExecutionSummary"]["ExecutionTime"],
}

next_token = response.get("NextToken", None)
if next_token:
kwargs["NextToken"] = next_token
else:
break


def patch(
Expand Down

0 comments on commit 8e4ab34

Please sign in to comment.