updated acme state

This commit is contained in:
Paul 2021-07-18 10:02:15 +02:00
parent 63f22fca41
commit 947e373d18
3 changed files with 21 additions and 15 deletions

View File

@ -6,11 +6,11 @@ import requests
def write_file_content(content=None, def write_file_content(content=None,
file=None): filename=None):
ret = None ret = None
try: try:
with open(file, "w") as f: with open(filename, "w") as f:
ret = f.write(content) ret = f.write(content)
except Exception as err: except Exception as err:
pass pass

View File

@ -1,5 +1,8 @@
#!/usr/bin/python3 #!/usr/bin/python3
from salt.utils.stringutils import get_diff
def fetched(name=None, def fetched(name=None,
url="http://pki", url="http://pki",
username=None, username=None,
@ -12,12 +15,12 @@ def fetched(name=None,
'name': name, 'name': name,
'changes': {}, 'changes': {},
'result': False, 'result': False,
'comment': 'Config is up to date' 'comment': 'Config is not up to date'
} }
currentcert = None currentcert = None
currentkey = None currentkey = None
domain_concat = domains.join(',') domain_concat = ",".join(domains)
currentcert = __salt__['pki.get_file_content'](checkfile=certfile) currentcert = __salt__['pki.get_file_content'](checkfile=certfile)
currentkey = __salt__['pki.get_file_content'](checkfile=keyfile) currentkey = __salt__['pki.get_file_content'](checkfile=keyfile)
@ -31,11 +34,14 @@ def fetched(name=None,
wcert = __salt__['pki.write_file_content'](newcert, certfile) wcert = __salt__['pki.write_file_content'](newcert, certfile)
wkey = __salt__['pki.write_file_content'](newkey, keyfile) wkey = __salt__['pki.write_file_content'](newkey, keyfile)
ret["changes"]["old"] = [currentcert,currentkey].join("\n") ret["changes"]["old"] = "\n".join([currentcert, currentkey])
ret["changes"]["new"] = [newcert,newkey].join("\n") ret["changes"]["new"] = "\n".join([newcert, newkey])
ret["changes"]["diff"] = salt.utils.stringutils.get_diff([currentcert,currentkey].join("\n"), ret["changes"]["diff"] = get_diff(ret["changes"]["old"],
[newcert,newkey].join("\n")) ret["changes"]["new"])
ret["comment"] = "Updated certificates and keys" ret["comment"] = "Updated certificates and keys"
ret["result"] = all([wcert, wkey]) ret["result"] = all([wcert, wkey])
else:
ret["comment"] = "Config is good and not changed"
ret["result"] = True
return ret return ret

View File

@ -3,10 +3,10 @@
--- ---
pki-fetched: pki-fetched:
pki.fetched: pki.fetched:
- name: /etc/acme/pkic.py - name: pkg-fetched
- url: '{{ acme.provider.pki.url }}' - url: {{ acme.provider.pki.url }}
- username: '{{ acme.provider.pki.username }}' - username: {{ acme.provider.pki.username }}
- password: '{{ acme.provider.pki.password }}' - password: {{ acme.provider.pki.password }}
- domains: '{{ acme.domains }}' - domains: {{ acme.domains }}
- certfile: '{{ acme.certfile }}' - certfile: {{ acme.certfile }}
- keyfile: '{{ acme.keyfile }}' - keyfile: {{ acme.keyfile }}