updated acme state
This commit is contained in:
parent
afff59da88
commit
9c5eb47a4f
@ -8,6 +8,7 @@ def fetched(name=None,
|
|||||||
username=None,
|
username=None,
|
||||||
password=None,
|
password=None,
|
||||||
domains=None,
|
domains=None,
|
||||||
|
certfile=None,
|
||||||
fullcertfile=None,
|
fullcertfile=None,
|
||||||
keyfile=None):
|
keyfile=None):
|
||||||
|
|
||||||
@ -22,25 +23,30 @@ def fetched(name=None,
|
|||||||
currentkey = None
|
currentkey = None
|
||||||
domain_concat = ",".join(domains)
|
domain_concat = ",".join(domains)
|
||||||
|
|
||||||
currentcert = __salt__['pki.get_file_content'](checkfile=fullcertfile)
|
currentcert = __salt__['pki.get_file_content'](checkfile=certfile)
|
||||||
currentkey = __salt__['pki.get_file_content'](checkfile=keyfile)
|
currentkey = __salt__['pki.get_file_content'](checkfile=keyfile)
|
||||||
|
|
||||||
newcert, newkey = __salt__['pki.get_pki_cert'](url=url,
|
newcert, newkey = __salt__['pki.get_pki_cert'](url=url,
|
||||||
username=username,
|
username=username,
|
||||||
password=password,
|
password=password,
|
||||||
domains=domain_concat)
|
domains=domain_concat)
|
||||||
|
newfullcert = f"{newcert}\n\n{newkey}"
|
||||||
|
|
||||||
if all([newcert,newkey]):
|
if all([newcert,newkey]):
|
||||||
if currentcert != newcert or currentkey != newkey:
|
if currentcert != newcert or currentkey != newkey:
|
||||||
wcert = __salt__['pki.write_file_content'](newcert, fullcertfile)
|
wcert = __salt__['pki.write_file_content'](newcert, certfile)
|
||||||
wkey = __salt__['pki.write_file_content'](newkey, keyfile)
|
wkey = __salt__['pki.write_file_content'](newkey, keyfile)
|
||||||
|
wfullcert = __salt__['pki.write_file_content'](newfullcert, fullcertfile)
|
||||||
|
|
||||||
ret["changes"]["old"] = "\n".join([currentcert, currentkey])
|
if currentcert and currentkey:
|
||||||
|
ret["changes"]["old"] = "\n".join([currentcert, currentkey])
|
||||||
|
else:
|
||||||
|
ret["changes"]["old"] = ""
|
||||||
ret["changes"]["new"] = "\n".join([newcert, newkey])
|
ret["changes"]["new"] = "\n".join([newcert, newkey])
|
||||||
ret["changes"]["diff"] = get_diff(ret["changes"]["old"],
|
ret["changes"]["diff"] = get_diff(ret["changes"]["old"],
|
||||||
ret["changes"]["new"])
|
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, wfullcert])
|
||||||
else:
|
else:
|
||||||
ret["comment"] = "Config is good and not changed"
|
ret["comment"] = "Config is good and not changed"
|
||||||
ret["result"] = True
|
ret["result"] = True
|
||||||
|
@ -8,11 +8,7 @@ acme:
|
|||||||
dh:
|
dh:
|
||||||
path: "/etc/acme/dh/dh.pem"
|
path: "/etc/acme/dh/dh.pem"
|
||||||
keysize: 2048
|
keysize: 2048
|
||||||
keysize: 4096
|
certificates: {}
|
||||||
domains: []
|
|
||||||
dns: "dns_provider"
|
|
||||||
fullcertfile: "/etc/acme/certs/certificate.crt"
|
|
||||||
keyfile: "/etc/acme/keys/private.key"
|
|
||||||
provider:
|
provider:
|
||||||
api:
|
api:
|
||||||
application_key: "test"
|
application_key: "test"
|
||||||
|
@ -10,9 +10,12 @@ FULLCERTFILE=os.environ.get("FULLCERTFILE")
|
|||||||
KEYFILE=os.environ.get("KEYFILE")
|
KEYFILE=os.environ.get("KEYFILE")
|
||||||
USERNAME=os.environ.get("USERNAME")
|
USERNAME=os.environ.get("USERNAME")
|
||||||
PASSWORD=os.environ.get("PASSWORD")
|
PASSWORD=os.environ.get("PASSWORD")
|
||||||
|
MERGE=eval(os.environ.get("MERGE"))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
res = requests.request(method="GET", url=f"{URL}/domain/{DOMAINS}", auth=(USERNAME, PASSWORD))
|
res = requests.request(method="GET",
|
||||||
|
url=f"{URL}/domain/{DOMAINS}",
|
||||||
|
auth=(USERNAME, PASSWORD))
|
||||||
resj = res.json()
|
resj = res.json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
# vim:syntax=yaml
|
# vim:syntax=yaml
|
||||||
{%- from "acme/map.jinja" import acme with context %}
|
{%- from "acme/map.jinja" import acme with context %}
|
||||||
---
|
---
|
||||||
pki-fetched:
|
{% for k, v in acme.certificates.items() %}
|
||||||
|
pki-fetched-{{ k }}:
|
||||||
pki.fetched:
|
pki.fetched:
|
||||||
- name: pki-fetched
|
- name: pki-fetched-nginx
|
||||||
- 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: {{ v.domains }}
|
||||||
- fullcertfile: {{ acme.fullcertfile }}
|
- certfile: {{ v.certfile }}
|
||||||
- keyfile: {{ acme.keyfile }}
|
- fullcertfile: {{ v.fullcertfile }}
|
||||||
|
- keyfile: {{ v.keyfile }}
|
||||||
|
{% endfor %}
|
Loading…
Reference in New Issue
Block a user