Skip to content

Commit

Permalink
feat: add state files
Browse files Browse the repository at this point in the history
  • Loading branch information
genaumann committed Jan 20, 2024
1 parent 9a2ed23 commit c454c40
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
40 changes: 40 additions & 0 deletions acme_sh/cert.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% from 'acme_sh/map.jinja' import acme_sh with context %}
{%- for user, config in acme_sh.items() %}
{%- if config.get('certs') is mapping %}
{%- for domain, cert_config in config['certs'].items() %}
acme_sh_cert_{{ user }}_{{ domain }}:
acme_sh.cert:
- name: {{ domain }}
- acme_mode: {{ cert_config['acme_mode'] }}
{%- if cert_config.get('aliases') %}
- aliases: {{ cert_config['aliases'] }}
{%- endif %}
- server: {{ cert_config.get('server', 'letsencrypt') }}
- keysize: {{ cert_config.get('keysize', '4096') }}
{%- if cert_config.get('dns_plugin') %}
- dns_plugin: {{ cert_config['dns_plugin'] }}
{%- endif %}
{%- if cert_config.get('webroot') %}
- webroot: {{ cert_config['webroot'] }}
{%- endif %}
{%- if cert_config.get('http_port') %}
- http_port: {{ cert_config['http_port'] }}
{%- endif %}
- user: {{ user }}
{%- if cert_config.get('cert_path') %}
- cert_path: {{ cert_config['cert_path'] }}
{%- endif %}
{%- if cert_config.get('dns_credentials') %}
- dns_credentials: {{ cert_config['dns_credentials'] }}
{%- endif %}
- force: {{ cert_config.get('force', False) }}
{%- if cert_config.get('valid_to') %}
- valid_to: {{ cert_config['valid_to'] }}
{%- endif %}
{%- if cert_config.get('valid_from') %}
- valid_from: {{ cert_config['valid_from'] }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endfor %}
3 changes: 3 additions & 0 deletions acme_sh/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include:
- acme_sh.install
- acme_sh.cert
14 changes: 14 additions & 0 deletions acme_sh/install.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{%- from 'acme_sh/map.jinja' import acme_sh with context %}
{%- for user, config in acme_sh.items() %}
acme_sh_install_{{ user }}:
acme_sh.installed:
- email: {{ config['email'] }}
- user: {{ user }}
{%- if config.get('upgrade') %}
- upgrade: {{ config['upgrade'] }}
{%- endif %}
{%- if config.get('force') %}
- force: {{ config['force'] }}
{%- endif %}
{%- endfor %}
15 changes: 15 additions & 0 deletions acme_sh/map.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% set acme_sh = salt['pillar.get']('acme_sh', {}) %}

{# get credentials from env #}
{%- set envs = salt['environ.items']() %}
{%- for key, value in envs.items() %}
{%- if key.startswith('ACMESH_') %}
{%- set parts = key.split('_') %}
{%- set user = parts[1] %}
{%- set domain = parts[2] | regex_replace('(?<!^)(?=[A-Z])', '.') | lower %}
{%- set var = '_'.join(parts[3:]) %}
{#- if acme_sh.get(user) and acme_sh[user].get(domain) and acme_sh[user][domain].get(acme_mode) == 'dns' #}
{%- set acme_sh = acme_sh | update_dict_key_value(user ~ ':certs:' ~ domain ~ ':dns_credentials', {var:value}) %}
{#- endif #}
{%- endif %}
{%- endfor %}

0 comments on commit c454c40

Please sign in to comment.