From 4415e1612bc50371202629be35d0253bb2159107 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Sat, 23 Sep 2023 12:52:01 -0700 Subject: [PATCH] (maint) Update optional parameters 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 --- REFERENCE.md | 29 +++++++++++++++-------------- manifests/install.pp | 6 +++--- manifests/install/darwin.pp | 4 ++-- manifests/install/solaris.pp | 4 ++-- manifests/install/suse.pp | 4 ++-- manifests/prepare/package.pp | 4 +++- manifests/prepare/puppet_config.pp | 2 +- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index ad70e212..a89ecd59 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -388,15 +388,15 @@ The following parameters are available in the `puppet_agent::install` class: ##### `package_version` -Data type: `String` +Data type: `Optional[String]` The puppet-agent version to install. -Default value: `'present'` +Default value: `undef` ##### `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. @@ -405,7 +405,7 @@ Default value: `undef` ##### `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 @@ -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` ### `puppet_agent::install::darwin` @@ -430,13 +430,13 @@ The following parameters are available in the `puppet_agent::install::darwin` cl ##### `package_version` -Data type: `Optional` +Data type: `String` The puppet-agent version to install. ##### `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 @@ -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` ### `puppet_agent::install::solaris` @@ -492,13 +492,13 @@ The following parameters are available in the `puppet_agent::install::suse` clas ##### `package_version` -Data type: `Optional` +Data type: `String` The puppet-agent version to install. ##### `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. @@ -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` ### `puppet_agent::install::windows` @@ -608,9 +608,10 @@ The following parameters are available in the `puppet_agent::prepare::package` c ##### `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. ### `puppet_agent::prepare::puppet_config` @@ -624,7 +625,7 @@ The following parameters are available in the `puppet_agent::prepare::puppet_con ##### `package_version` -Data type: `Optional` +Data type: `String` The puppet-agent version to install. diff --git a/manifests/install.pp b/manifests/install.pp index 8bb6d43a..ba7af90d 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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() diff --git a/manifests/install/darwin.pp b/manifests/install/darwin.pp index ad38da9b..912ab4ae 100644 --- a/manifests/install/darwin.pp +++ b/manifests/install/darwin.pp @@ -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' diff --git a/manifests/install/solaris.pp b/manifests/install/solaris.pp index eedd75e3..e8bc513f 100644 --- a/manifests/install/solaris.pp +++ b/manifests/install/solaris.pp @@ -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' { diff --git a/manifests/install/suse.pp b/manifests/install/suse.pp index 73a04c00..9769ed6b 100644 --- a/manifests/install/suse.pp +++ b/manifests/install/suse.pp @@ -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() diff --git a/manifests/prepare/package.pp b/manifests/prepare/package.pp index 0d649a9d..5711e2d7 100644 --- a/manifests/prepare/package.pp +++ b/manifests/prepare/package.pp @@ -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() diff --git a/manifests/prepare/puppet_config.pp b/manifests/prepare/puppet_config.pp index 74bc68fc..5ba4d35e 100644 --- a/manifests/prepare/puppet_config.pp +++ b/manifests/prepare/puppet_config.pp @@ -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