Skip to content

Commit

Permalink
refactor(module): add function to generate cert return
Browse files Browse the repository at this point in the history
  • Loading branch information
genaumann committed Jan 17, 2024
1 parent d930904 commit c143a76
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions _modules/acme_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def _upgrade(home_dir, user):

return ret

def _generate_crt_ret(name, cert_path):

return {
"certificate": f"{cert_path}/{name}/{name}.cer",
"private_key": f"{cert_path}/{name}/{name}.key",
"fullchain": f"{cert_path}/{name}/fullchain.cer",
"ca": f"{cert_path}/{name}/ca.cer"
}

def install(
email,
user='root',
Expand Down Expand Up @@ -298,10 +307,7 @@ def issue(
issue = __salt__["cmd.run_all"](" ".join(cmd), python_shell=False, runas=user)

if issue["retcode"] == 0:
ret = {
"certificate": f"{cert_path}/{name}/{name}.cer",
"private_key": f"{cert_path}/{name}/{name}.key"
}
ret = _generate_crt_ret(name, cert_path)
else:
if issue["stdout"].find("Next renewal time is") != -1:
ret = f"Certificate in {cert_path}/{name} is valid, re run with `force=True`"
Expand Down Expand Up @@ -458,10 +464,7 @@ def renew(
renew = __salt__["cmd.run_all"](" ".join(cmd), python_shell=False, runas=user)

if renew["retcode"] == 0:
ret = {
"certificate": f"{cert_path}/{name}/{name}.cer",
"private_key": f"{cert_path}/{name}/{name}.key"
}
ret = _generate_crt_ret(name, cert_path)
else:
next_renew = re.search(r"Next renewal time is: (.*)", renew["stdout"])
if next_renew:
Expand Down

0 comments on commit c143a76

Please sign in to comment.