Skip to content

Commit

Permalink
feat(config): add sane defaults
Browse files Browse the repository at this point in the history
Also specify `config` as a hash to make it easier to provide the config from
multiple pillar values.  Maintain backward compatibility (supplying `config` as
a string) so that the formula continues to work as expected if a `config`
string is already available.

BREAKING CHANGE: `config` can now be provided as a hash or a string; defaults
are modified and, while sane and desirable, do change the behavior of the
formula.
  • Loading branch information
javierbertoli committed Jul 23, 2020
1 parent b889678 commit d9afac9
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 16 deletions.
5 changes: 4 additions & 1 deletion letsencrypt/config.sls
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ letsencrypt-config-directory:
letsencrypt-config:
file.managed:
- name: {{ letsencrypt.config_dir.path }}/cli.ini
- template: jinja
- source: salt://letsencrypt/files/cli.ini.jinja
- user: {{ letsencrypt.config_dir.user }}
- group: {{ letsencrypt.config_dir.group }}
- makedirs: true
- contents_pillar: letsencrypt:config
- context:
config: {{ letsencrypt.config | json }}
5 changes: 5 additions & 0 deletions letsencrypt/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ letsencrypt:
user: root
group: root
mode: 755
config:
agree-tos: true
keep-until-expiring: true
expand: true
max-log-backups: 0
# The post_renew cmds are executed via renew_letsencrypt_cert.sh after every
# run. For more fine grain control, consider placing scripts in the pre,
# post, and/or deploy directories within /etc/letsencrypt/renewal-hooks/. For
Expand Down
11 changes: 11 additions & 0 deletions letsencrypt/files/cli.ini.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
########################################################################
# File managed by Salt at <{{ source }}>.
# Your changes will be overwritten.
########################################################################
{%- if config is string %}
{{ config }}
{%- else %}
{%- for k, v in config.items() %}
{{ k }} = {{ v }}
{%- endfor %}
{%- endif %}
29 changes: 21 additions & 8 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@ letsencrypt:
# have specific version of certbot you can enable it. The version value
# should match a certbot/certbot branch.
version: 0.30.x
config: |
server = https://acme-v01.api.letsencrypt.org/directory
email = webmaster@example.com
authenticator = webroot
webroot-path = /var/lib/www
agree-tos = True
keep-until-expiring = True
expand = True
# Any parameter from the cli can be specified in the config file
# check https://certbot.eff.org/docs/using.html#configuration-file
config:
server: https://acme-v01.api.letsencrypt.org/directory
email: webmaster@example.com
authenticator: webroot
webroot-path: /var/lib/www
agree-tos: True
keep-until-expiring: True
expand: True
# For backward compatibility, config can be passed as a string
# (although it's discouraged, as this format might be dropped in a future
# release)
# config: |
# server = https://acme-v01.api.letsencrypt.org/directory
# email = webmaster@example.com
# authenticator = webroot
# webroot-path = /var/lib/www
# agree-tos = True
# keep-until-expiring = True
# expand = True
config_dir:
path: /etc/letsencrypt
user: root
Expand Down
1 change: 1 addition & 0 deletions test/integration/deb/controls/letsencrypt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
should match 'server = https://acme-staging.api.letsencrypt.org/directory'
end
its('content') { should match 'authenticator = webroot' }
its('content') { should match 'File managed by Salt' }
end

describe file('/usr/bin/letsencrypt') do
Expand Down
1 change: 1 addition & 0 deletions test/integration/git/controls/letsencrypt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
should match 'server = https://acme-staging.api.letsencrypt.org/directory'
end
its('content') { should match 'authenticator = standalone' }
its('content') { should match 'File managed by Salt' }
end
1 change: 1 addition & 0 deletions test/integration/rpm/controls/letsencrypt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
should match 'server = https://acme-staging.api.letsencrypt.org/directory'
end
its('content') { should match 'authenticator = webroot' }
its('content') { should match 'File managed by Salt' }
end

describe file('/usr/bin/letsencrypt') do
Expand Down
14 changes: 7 additions & 7 deletions test/salt/pillar/rpm.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
---
letsencrypt:
use_package: true
config: |
server = https://acme-staging.api.letsencrypt.org/directory
email = saltstack-letsencrypt-formula@example.com
authenticator = webroot
webroot-path = /var/www/html
agree-tos = true
renew-by-default = true
config:
server: https://acme-staging.api.letsencrypt.org/directory
email: saltstack-letsencrypt-formula@example.com
authenticator: webroot
webroot-path: /var/www/html
agree-tos: true
renew-by-default: true
domainsets:
www:
- letsencrypt-formula.example.com

0 comments on commit d9afac9

Please sign in to comment.