From 947e373d18e6f478d41c08148e7c4a419a3d4565 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sun, 18 Jul 2021 10:02:15 +0200 Subject: [PATCH] updated acme state --- states/_modules/pki.py | 4 ++-- states/_states/pki.py | 18 ++++++++++++------ states/acme/pkic.sls | 14 +++++++------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/states/_modules/pki.py b/states/_modules/pki.py index 7e55d63..2f40b65 100644 --- a/states/_modules/pki.py +++ b/states/_modules/pki.py @@ -6,11 +6,11 @@ import requests def write_file_content(content=None, - file=None): + filename=None): ret = None try: - with open(file, "w") as f: + with open(filename, "w") as f: ret = f.write(content) except Exception as err: pass diff --git a/states/_states/pki.py b/states/_states/pki.py index 4cabd80..fa938c9 100644 --- a/states/_states/pki.py +++ b/states/_states/pki.py @@ -1,5 +1,8 @@ #!/usr/bin/python3 +from salt.utils.stringutils import get_diff + + def fetched(name=None, url="http://pki", username=None, @@ -12,12 +15,12 @@ def fetched(name=None, 'name': name, 'changes': {}, 'result': False, - 'comment': 'Config is up to date' + 'comment': 'Config is not up to date' } currentcert = None currentkey = None - domain_concat = domains.join(',') + domain_concat = ",".join(domains) currentcert = __salt__['pki.get_file_content'](checkfile=certfile) currentkey = __salt__['pki.get_file_content'](checkfile=keyfile) @@ -31,11 +34,14 @@ def fetched(name=None, wcert = __salt__['pki.write_file_content'](newcert, certfile) wkey = __salt__['pki.write_file_content'](newkey, keyfile) - ret["changes"]["old"] = [currentcert,currentkey].join("\n") - ret["changes"]["new"] = [newcert,newkey].join("\n") - ret["changes"]["diff"] = salt.utils.stringutils.get_diff([currentcert,currentkey].join("\n"), - [newcert,newkey].join("\n")) + ret["changes"]["old"] = "\n".join([currentcert, currentkey]) + ret["changes"]["new"] = "\n".join([newcert, newkey]) + ret["changes"]["diff"] = get_diff(ret["changes"]["old"], + ret["changes"]["new"]) ret["comment"] = "Updated certificates and keys" ret["result"] = all([wcert, wkey]) + else: + ret["comment"] = "Config is good and not changed" + ret["result"] = True return ret diff --git a/states/acme/pkic.sls b/states/acme/pkic.sls index 3abb7b4..19f6aca 100644 --- a/states/acme/pkic.sls +++ b/states/acme/pkic.sls @@ -3,10 +3,10 @@ --- pki-fetched: pki.fetched: - - name: /etc/acme/pkic.py - - url: '{{ acme.provider.pki.url }}' - - username: '{{ acme.provider.pki.username }}' - - password: '{{ acme.provider.pki.password }}' - - domains: '{{ acme.domains }}' - - certfile: '{{ acme.certfile }}' - - keyfile: '{{ acme.keyfile }}' + - name: pkg-fetched + - url: {{ acme.provider.pki.url }} + - username: {{ acme.provider.pki.username }} + - password: {{ acme.provider.pki.password }} + - domains: {{ acme.domains }} + - certfile: {{ acme.certfile }} + - keyfile: {{ acme.keyfile }}