Skip to content

Commit

Permalink
(maint) Update optional parameters
Browse files Browse the repository at this point in the history
As part of 404df9d all parameters in this module were assigned a data
type. However, some required parameters were mistakenly classed as
Optional and vice-versa.

Puppet's documentation states "If a class parameter lacks a default
value, the parameter is considered required."[1]

This commit updates all parameters with default values to Optional (and
whatever other relevant data type) and all parameters without default
value as required. The REFERENCE.md has been updated to reflect these
changes.

Additionally, this commit updates all Optional parameters be set as
undef, as suggested by the optional_default puppet-lint check.

[1] https://www.puppet.com/docs/puppet/7/lang_classes#class-parameters-and-variables
  • Loading branch information
mhashizume committed Sep 24, 2023
1 parent ffc0575 commit 4415e16
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 25 deletions.
29 changes: 15 additions & 14 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,15 @@ The following parameters are available in the `puppet_agent::install` class:

##### <a name="-puppet_agent--install--package_version"></a>`package_version`

Data type: `String`
Data type: `Optional[String]`

The puppet-agent version to install.

Default value: `'present'`
Default value: `undef`

##### <a name="-puppet_agent--install--install_dir"></a>`install_dir`

Data type: `Optional`
Data type: `Optional[[Stdlib::Absolutepath]]`

The directory the puppet agent should be installed to. This is only applicable for
windows operating systems.
Expand All @@ -405,7 +405,7 @@ Default value: `undef`

##### <a name="-puppet_agent--install--install_options"></a>`install_options`

Data type: `Array`
Data type: `Optional[Array]`

An array of additional options to pass when installing puppet-agent. Each option in
the array can either be a string or a hash. Each option will automatically be quoted
Expand All @@ -415,7 +415,7 @@ the installation command, forward slashes won't be automatically converted like
are in `file` resources.) Note also that backslashes in double-quoted strings _must_
be escaped and backslashes in single-quoted strings _can_ be escaped.

Default value: `[]`
Default value: `undef`

### <a name="puppet_agent--install--darwin"></a>`puppet_agent::install::darwin`

Expand All @@ -430,13 +430,13 @@ The following parameters are available in the `puppet_agent::install::darwin` cl

##### <a name="-puppet_agent--install--darwin--package_version"></a>`package_version`

Data type: `Optional`
Data type: `String`

The puppet-agent version to install.

##### <a name="-puppet_agent--install--darwin--install_options"></a>`install_options`

Data type: `Array`
Data type: `Optional[Array]`

An array of additional options to pass when installing puppet-agent. Each option in
the array can either be a string or a hash. Each option will automatically be quoted
Expand All @@ -446,7 +446,7 @@ the installation command, forward slashes won't be automatically converted like
are in `file` resources.) Note also that backslashes in double-quoted strings _must_
be escaped and backslashes in single-quoted strings _can_ be escaped.

Default value: `[]`
Default value: `undef`

### <a name="puppet_agent--install--solaris"></a>`puppet_agent::install::solaris`

Expand Down Expand Up @@ -492,13 +492,13 @@ The following parameters are available in the `puppet_agent::install::suse` clas

##### <a name="-puppet_agent--install--suse--package_version"></a>`package_version`

Data type: `Optional`
Data type: `String`

The puppet-agent version to install.

##### <a name="-puppet_agent--install--suse--install_options"></a>`install_options`

Data type: `Array`
Data type: `Optional[Array]`

An array of additional options to pass when installing puppet-agent.
Each option in the array can either be a string or a hash.
Expand All @@ -509,7 +509,7 @@ command, forward slashes won't be automatically converted like they are in
`file` resources.) Note also that backslashes in double-quoted strings
_must_ be escaped and backslashes in single-quoted strings _can_ be escaped.

Default value: `[]`
Default value: `undef`

### <a name="puppet_agent--install--windows"></a>`puppet_agent::install::windows`

Expand Down Expand Up @@ -608,9 +608,10 @@ The following parameters are available in the `puppet_agent::prepare::package` c

##### <a name="-puppet_agent--prepare--package--source"></a>`source`

Data type: `Optional`

Data type: `Variant[String, Array]`

The source file for the puppet-agent package. Can use any of the data types
and protocols that the File resource's source attribute can.

### <a name="puppet_agent--prepare--puppet_config"></a>`puppet_agent::prepare::puppet_config`

Expand All @@ -624,7 +625,7 @@ The following parameters are available in the `puppet_agent::prepare::puppet_con

##### <a name="-puppet_agent--prepare--puppet_config--package_version"></a>`package_version`

Data type: `Optional`
Data type: `String`

The puppet-agent version to install.

Expand Down
6 changes: 3 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# are in `file` resources.) Note also that backslashes in double-quoted strings _must_
# be escaped and backslashes in single-quoted strings _can_ be escaped.
class puppet_agent::install (
String $package_version = 'present',
Optional $install_dir = undef,
Array $install_options = [],
Optional[String] $package_version = undef,
Optional[[Stdlib::Absolutepath]] $install_dir = undef,
Optional[Array] $install_options = undef,
) {
assert_private()

Expand Down
4 changes: 2 additions & 2 deletions manifests/install/darwin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# are in `file` resources.) Note also that backslashes in double-quoted strings _must_
# be escaped and backslashes in single-quoted strings _can_ be escaped.
class puppet_agent::install::darwin (
Optional $package_version,
Array $install_options = [],
String $package_version,
Optional[Array] $install_options = undef,
) {
assert_private()
$install_script = 'osx_install.sh.erb'
Expand Down
4 changes: 2 additions & 2 deletions manifests/install/solaris.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# are in `file` resources.) Note also that backslashes in double-quoted strings _must_
# be escaped and backslashes in single-quoted strings _can_ be escaped.
class puppet_agent::install::solaris (
Optional $package_version,
Array $install_options = [],
String $package_version,
Optional[Array] $install_options = undef,
) {
assert_private()
if $facts['os']['release']['major'] == '10' {
Expand Down
4 changes: 2 additions & 2 deletions manifests/install/suse.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# `file` resources.) Note also that backslashes in double-quoted strings
# _must_ be escaped and backslashes in single-quoted strings _can_ be escaped.
class puppet_agent::install::suse (
Optional $package_version,
Array $install_options = [],
String $package_version,
Optional[Array] $install_options = undef,
) {
assert_private()

Expand Down
4 changes: 3 additions & 1 deletion manifests/prepare/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# working with a remote https repository.
#
# @param source
# The source file for the puppet-agent package. Can use any of the data types
# and protocols that the File resource's source attribute can.
class puppet_agent::prepare::package (
Optional $source,
Variant[String, Array] $source,
) {
assert_private()

Expand Down
2 changes: 1 addition & 1 deletion manifests/prepare/puppet_config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @param package_version
# The puppet-agent version to install.
class puppet_agent::prepare::puppet_config (
Optional $package_version,
String $package_version,
) {
assert_private()
$puppetconf = $puppet_agent::params::config
Expand Down

0 comments on commit 4415e16

Please sign in to comment.