Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add create_resources and rename environment parameter #1

Closed
wants to merge 8 commits into from
12 changes: 6 additions & 6 deletions manifests/certonly.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# [*additional_args*]
# An array of additional command line arguments to pass to the
# `letsencrypt-auto` command.
# [*environment*]
# [*venv_vars*]
# An optional array of environment variables (in addition to VENV_PATH).
# [*manage_cron*]
# Boolean indicating whether or not to schedule cron job for renewal.
Expand All @@ -36,7 +36,7 @@
$webroot_paths = undef,
$letsencrypt_command = $letsencrypt::command,
$additional_args = undef,
$environment = [],
$venv_vars = [],
$manage_cron = false,
$suppress_cron_output = false,
$cron_before_command = undef,
Expand All @@ -53,7 +53,7 @@
if $additional_args {
validate_array($additional_args)
}
validate_array($environment)
validate_array($venv_vars)
validate_bool($manage_cron)
validate_bool($suppress_cron_output)

Expand All @@ -70,9 +70,9 @@
exec { "letsencrypt certonly ${title}":
command => $command,
path => $::path,
environment => concat([ $venv_path_var ], $environment),
environment => concat([ $venv_path_var ], $venv_vars),
creates => $live_path,
require => Class['letsencrypt'],
require => Exec['initialize letsencrypt'],
}

if $manage_cron {
Expand Down Expand Up @@ -103,7 +103,7 @@
}
cron { "letsencrypt renew cron ${title}":
command => "${::letsencrypt::cron_scripts_path}/renew-${title}.sh",
environment => concat([ $venv_path_var ], $environment),
environment => concat([ $venv_path_var ], $venv_vars),
user => root,
hour => $cron_hour,
minute => $cron_minute,
Expand Down
14 changes: 10 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# precedence over an 'email' setting defined in $config.
# [*path*]
# The path to the letsencrypt installation.
# [*environment*]
# [*venv_vars*]
# An optional array of environment variables (in addition to VENV_PATH)
# [*repo*]
# A Git URL to install the Let's encrypt client from.
Expand Down Expand Up @@ -48,12 +48,14 @@
# A flag to allow using the 'register-unsafely-without-email' flag.
# [*cron_scripts_path*]
# The path to put the script we'll call with cron. Defaults to $puppet_vardir/letsencrypt.
# [*certs*]
# A hash of letsencrypt::certonly certs to be created via create_resources
#
class letsencrypt (
$email = undef,
$path = $letsencrypt::params::path,
$venv_path = $letsencrypt::params::venv_path,
$environment = [],
$venv_vars = [],
$repo = $letsencrypt::params::repo,
$version = $letsencrypt::params::version,
$package_name = $letsencrypt::params::package_name,
Expand All @@ -69,12 +71,13 @@
$install_method = $letsencrypt::params::install_method,
$agree_tos = $letsencrypt::params::agree_tos,
$unsafe_registration = $letsencrypt::params::unsafe_registration,
$certs = {},
) inherits letsencrypt::params {
validate_string($path, $repo, $version, $config_file, $package_name, $package_command, $cron_scripts_path)
if $email {
validate_string($email)
}
validate_array($environment)
validate_array($venv_vars)
validate_bool($manage_config, $manage_install, $manage_dependencies, $configure_epel, $agree_tos, $unsafe_registration)
validate_hash($config)
validate_re($install_method, ['^package$', '^vcs$'])
Expand Down Expand Up @@ -103,7 +106,10 @@
exec { 'initialize letsencrypt':
command => "${command_init} -h",
path => $::path,
environment => concat([ "VENV_PATH=${venv_path}" ], $environment),
environment => concat([ "VENV_PATH=${venv_path}" ], $venv_vars),
refreshonly => true,
}

create_resources(::letsencrypt::certonly, $certs)

}
2 changes: 1 addition & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# method.
# [*package_name*]
# Name of package to use when installing the client with the `package`
# method.
# method.
#
class letsencrypt::install (
$manage_install = $letsencrypt::manage_install,
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/letsencrypt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
end

describe 'with custom environment variables' do
let(:additional_params) { { environment: ['FOO=bar', 'FIZZ=buzz'] } }
let(:additional_params) { { venv_vars: ['FOO=bar', 'FIZZ=buzz'] } }

it { is_expected.to contain_exec('initialize letsencrypt').with_environment(['VENV_PATH=/opt/letsencrypt/.venv', 'FOO=bar', 'FIZZ=buzz']) }
end
Expand Down
4 changes: 2 additions & 2 deletions spec/defines/letsencrypt_certonly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@

describe 'when specifying custom environment variables' do
let(:title) { 'foo.example.com' }
let(:params) { { environment: ['FOO=bar', 'FIZZ=buzz'] } }
let(:params) { { venv_vars: ['FOO=bar', 'FIZZ=buzz'] } }

it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_environment(['VENV_PATH=/opt/letsencrypt/.venv', 'FOO=bar', 'FIZZ=buzz']) }
end

context 'with custom environment variables and manage cron' do
let(:title) { 'foo.example.com' }
let(:params) { { environment: ['FOO=bar', 'FIZZ=buzz'], manage_cron: true } }
let(:params) { { venv_vars: ['FOO=bar', 'FIZZ=buzz'], manage_cron: true } }

it { is_expected.to contain_cron('letsencrypt renew cron foo.example.com').with_environment(['VENV_PATH=/opt/letsencrypt/.venv', 'FOO=bar', 'FIZZ=buzz']) }
end
Expand Down