From 20d97f126b099602b9ac3fecfaefff67449e6276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 18 Jul 2023 09:15:15 -1000 Subject: [PATCH] Require a version when installing from GitHub The `caddy::version` parameter is only used when `caddy::install_method` is "github", but no error was previously raised if the user set a specific version that was ignored, and the resulting configuration was not what the user expected. In order to avoid confusion, do not default to an outdated version of caddy when installing from GitHub (requiring the user to explicily tell which version they want) and raise an error if a version is set but is ignored. This should make the module more user-friendly for new users. --- REFERENCE.md | 6 +++--- manifests/init.pp | 4 ++-- manifests/install.pp | 8 ++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index ce9b2f7..b19d818 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -78,11 +78,11 @@ The following parameters are available in the `caddy` class: ##### `version` -Data type: `String[1]` +Data type: `Optional[String[1]]` -Which version is used. +Which version of caddy to install when install_method is github. -Default value: `'2.0.0'` +Default value: `undef` ##### `install_method` diff --git a/manifests/init.pp b/manifests/init.pp index 0089bb5..b7b46d2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -16,7 +16,7 @@ # } # # @param version -# Which version is used. +# Which version of caddy to install when install_method is github. # # @param install_method # Which source is used. @@ -76,7 +76,7 @@ # Whether the process and all its children can gain new privileges through execve(). # class caddy ( - String[1] $version = '2.0.0', + Optional[String[1]] $version = undef, Optional[Enum['github']] $install_method = undef, Stdlib::Absolutepath $install_path = '/opt/caddy', String[1] $caddy_user = 'caddy', diff --git a/manifests/install.pp b/manifests/install.pp index cfa14ba..4819059 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -9,6 +9,10 @@ $bin_file = "${caddy::install_path}/caddy" if $caddy::install_method == 'github' { + if !$caddy::version { + fail('caddy::version must be set when caddy::install_method is github') + } + $caddy_url = 'https://github.com/caddyserver/caddy/releases/download' $caddy_dl_url = "${caddy_url}/v${caddy::version}/caddy_${caddy::version}_linux_${caddy::arch}.tar.gz" $caddy_dl_dir = "/var/cache/caddy_${caddy::version}_linux_${$caddy::arch}.tar.gz" @@ -37,6 +41,10 @@ $caddy_source = "/var/cache/caddy-${caddy::version}/caddy" } else { + if $caddy::version { + fail('caddy::version can only be set when caddy::install_method is github') + } + $caddy_url = 'https://caddyserver.com/api/download' $caddy_dl_url = "${caddy_url}?os=linux&arch=${caddy::arch}&plugins=${caddy::caddy_features}&license=${caddy::caddy_license}&telemetry=${caddy::caddy_telemetry}"