Skip to content

Commit

Permalink
Require a version when installing from GitHub
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smortex committed Jul 18, 2023
1 parent 1933a2b commit 20d97f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ The following parameters are available in the `caddy` class:

##### <a name="-caddy--version"></a>`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`

##### <a name="-caddy--install_method"></a>`install_method`

Expand Down
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}"

Expand Down

0 comments on commit 20d97f1

Please sign in to comment.