From 785f42901f34aaf356f316c691e3f56138c8608d Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Fri, 20 Jun 2025 13:55:54 -0500 Subject: initial commit --- sections/acm.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 sections/acm.py (limited to 'sections/acm.py') diff --git a/sections/acm.py b/sections/acm.py new file mode 100644 index 0000000..3a62668 --- /dev/null +++ b/sections/acm.py @@ -0,0 +1,41 @@ +# acm.py +import boto3 +from datetime import datetime, timedelta, timezone +from tabulate import tabulate + + +def get_section(config): + profile = config["aws"].get("profile") + region = config["aws"]["region"] + session = boto3.Session( + profile_name=profile if profile else None, region_name=region + ) + client = session.client("acm") + + today = datetime.now(timezone.utc) + deadline = today + timedelta(days=30) + + certs = client.list_certificates(CertificateStatuses=["ISSUED"])[ + "CertificateSummaryList" + ] + rows = [] + + for cert in certs: + detail = client.describe_certificate(CertificateArn=cert["CertificateArn"])[ + "Certificate" + ] + not_after = detail.get("NotAfter") + if not_after and today <= not_after <= deadline: + rows.append([cert["DomainName"], not_after.strftime("%Y-%m-%d")]) + + if not rows: + return "Expiring TLS Certificates:\nNo certs expiring in the next 30 days." + + table = tabulate(rows, headers=["Domain", "Expires"], tablefmt="simple_grid") + lines = [ + "Expiring TLS Certificates (Next 30 Days):", + f"[https://{config['aws'].get('region')}.console.aws.amazon.com/acm/home#/certificates/list]", + table, + ] + + return "\n".join(lines) -- cgit v1.2.3-70-g09d2