aboutsummaryrefslogtreecommitdiff
path: root/sections/acm.py
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2025-06-20 13:55:54 -0500
committerChristian Cleberg <hello@cleberg.net>2025-06-20 13:55:54 -0500
commit785f42901f34aaf356f316c691e3f56138c8608d (patch)
tree5b8f7a6e33a6af410e511137fdd51b6fa60d0f83 /sections/acm.py
downloadaws-summary-report-785f42901f34aaf356f316c691e3f56138c8608d.tar.gz
aws-summary-report-785f42901f34aaf356f316c691e3f56138c8608d.tar.bz2
aws-summary-report-785f42901f34aaf356f316c691e3f56138c8608d.zip
initial commit
Diffstat (limited to 'sections/acm.py')
-rw-r--r--sections/acm.py41
1 files changed, 41 insertions, 0 deletions
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)