From 5b28b1c382ecb239c1beb34d9e637da3673381a9 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sat, 30 Jan 2021 13:06:11 +0100 Subject: [PATCH] updated acme state --- states/acme/pkic.py.j2 | 24 +++++++++++++----------- states/acme/pkic.sls | 3 ++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/states/acme/pkic.py.j2 b/states/acme/pkic.py.j2 index bce4dcb..cbde926 100644 --- a/states/acme/pkic.py.j2 +++ b/states/acme/pkic.py.j2 @@ -4,25 +4,27 @@ import os import requests -URL=os.environ("URL") -DOMAINS=os.environ("DOMAINS") -FULLCERTFILE=os.environ("FULLCERTFILE") -KEYFILE=os.environ("KEYFILE") -USERNAME=os.environ("USERNAME") -PASSWORD=os.environ("PASSWORD") +URL=os.environ.get("URL") +DOMAINS=os.environ.get("DOMAINS") +FULLCERTFILE=os.environ.get("FULLCERTFILE") +KEYFILE=os.environ.get("KEYFILE") +USERNAME=os.environ.get("USERNAME") +PASSWORD=os.environ.get("PASSWORD") def main(): res = requests.request(method="GET", url=f"{URL}/domain/{DOMAINS}", auth=(USERNAME, PASSWORD)) resj = res.json() try: - with open(FULLCERTFILE) as fcf: - os.write(ffcf, resj["certificate"]) + if "certificate" in resj.keys(): + with open(FULLCERTFILE, "w") as fcf: + fcf.write(resj["certificate"]) - with open(KEYFILE) as fkf: - os.write(fkf, resj["privatekey"]) + if "privatekey" in resj.keys(): + with open(KEYFILE, "w") as fkf: + fkf.write(resj["privatekey"]) except Exception as e: - return e + print(e) return diff --git a/states/acme/pkic.sls b/states/acme/pkic.sls index 8f9b4dc..31b4b96 100644 --- a/states/acme/pkic.sls +++ b/states/acme/pkic.sls @@ -13,9 +13,10 @@ pkic-run: - name: /etc/acme/pkic.py - env: - URL: '{{ acme.provider.pki.url }}' + - DOMAINS: '{{ acme.domains|join(',') }}' - FULLCERTFILE: '{{ acme.fullcertfile }}' - KEYFILE: '{{ acme.keyfile }}' - USERNAME: '{{ acme.provider.pki.username }}' - PASSWORD: '{{ acme.provider.pki.password }}' - require: - - cmd: pkic-install + - file: pkic-install