From 69918c4ee73576ab154bdff2f3cd3b089c53f07f Mon Sep 17 00:00:00 2001 From: oxmox Date: Mon, 16 Dec 2024 19:07:29 +0100 Subject: [PATCH] add scripts/traefik-cert-exporter.py --- scripts/traefik-cert-exporter.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 scripts/traefik-cert-exporter.py diff --git a/scripts/traefik-cert-exporter.py b/scripts/traefik-cert-exporter.py new file mode 100755 index 0000000..8df48e8 --- /dev/null +++ b/scripts/traefik-cert-exporter.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import json +import base64 +import os + +resolver_name = "myresolver" +domain_name = "oxmox.dev + +# Read Traefik ACME JSON +with open("acme.json") as acme_file: + acme = json.load(acme_file) + # Select certificates from a specific resolver + certificates = acme[resolver_name]["Certificates"] + # Find the specific certificate we are looking for + certificate = [certificate for certificate in certificates if domain_name in certificate["domain"].get("main", [])][0] + # Extract X.509 certificate data + certificate_data = base64.b64decode(certificate["certificate"]) + key_data = base64.b64decode(certificate["key"]) + # Export certificate and key to file + with open("certificate.pem", "wb") as certfile: + certfile.write(certificate_data) + with open("key.pem", "wb") as keyfile: + keyfile.write(key_data) + + os.chmod("certificate.pem", 0o600) + os.chmod("key.pem", 0o600)