From b1adb67177769ecd5292d653e5957e24201c1a4e Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Mon, 12 Aug 2024 23:11:16 +0200 Subject: [PATCH] fix puppet-lint/rubocop offenses --- examples/init.pp | 12 --- manifests/config.pp | 140 +++++++++++++++---------------- manifests/init.pp | 12 +-- manifests/install.pp | 3 + manifests/install/archive.pp | 12 +-- manifests/install/package.pp | 2 +- manifests/mysql.pp | 8 +- manifests/repo.pp | 2 +- manifests/repo/yum.pp | 6 +- spec/classes/artifactory_spec.rb | 3 +- 10 files changed, 92 insertions(+), 108 deletions(-) delete mode 100644 examples/init.pp diff --git a/examples/init.pp b/examples/init.pp deleted file mode 100644 index f19022a..0000000 --- a/examples/init.pp +++ /dev/null @@ -1,12 +0,0 @@ -# The baseline for module testing used by Puppet Labs is that each manifest -# should have a corresponding test manifest that declares that class or defined -# type. -# -# Tests are then run by using puppet apply --noop (to check for compilation -# errors and view a log of events) or by fully applying the test in a virtual -# environment (to compare the resulting system state to the desired state). -# -# Learn more about module testing here: -# http://docs.puppetlabs.com/guides/tests_smoke.html -# -include ::artifactory diff --git a/manifests/config.pp b/manifests/config.pp index 728bea2..15d55e4 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -7,7 +7,7 @@ # When no version number is specified, we have no choice but to guess. # Future versions of this module should enforce setting a version number. if ($artifactory::package_version =~ Enum['present','installed','latest']) { - notify {'Specifying a version number in $artifactory::package_version is strongly recommended': loglevel => warning } + notify { 'Specifying a version number in $artifactory::package_version is strongly recommended': loglevel => warning } $_legacy = true } elsif (versioncmp($artifactory::package_version, '7.0') >= 0) { $_legacy = false @@ -38,20 +38,20 @@ 'fullDb' => 'full-db', 'cachedFS' => 'cache-fs', 'fullDbDirect' => 'full-db-direct', - 's3' => 's3-storage-v3' + 's3' => 's3-storage-v3', } # Check if a value was provided that need to be replaced. - if $::artifactory::binary_provider_type and $_types[$::artifactory::binary_provider_type] { - $_binary_provider_type = $_types[$::artifactory::binary_provider_type] + if $artifactory::binary_provider_type and $_types[$artifactory::binary_provider_type] { + $_binary_provider_type = $_types[$artifactory::binary_provider_type] } else { # Use the option unmodified. - $_binary_provider_type = $::artifactory::binary_provider_type + $_binary_provider_type = $artifactory::binary_provider_type } # Determine the base type of the binary provider by grouping similar # types. Required to determine the directory in the next step. - case $_types[$::artifactory::binary_provider_type] { + case $_types[$artifactory::binary_provider_type] { 'file-system', 'full-db', 'cache-fs', @@ -67,43 +67,37 @@ } # Determine the directory for the chosen binary provider. - if ($binary_provider_type == 'file-system') and ! $::artifactory::binary_provider_filesystem_dir { - if $::artifactory::binary_provider_base_data_dir { - $binary_provider_filesystem_dir = "${::artifactory::binary_provider_base_data_dir}/filestore" + if ($binary_provider_type == 'file-system') and ! $artifactory::binary_provider_filesystem_dir { + if $artifactory::binary_provider_base_data_dir { + $binary_provider_filesystem_dir = "${artifactory::binary_provider_base_data_dir}/filestore" } else { $binary_provider_filesystem_dir = undef } - } elsif ($binary_provider_type == 'file-system') and $::artifactory::binary_provider_filesystem_dir { - $binary_provider_filesystem_dir = $::artifactory::binary_provider_filesystem_dir + } elsif ($binary_provider_type == 'file-system') and $artifactory::binary_provider_filesystem_dir { + $binary_provider_filesystem_dir = $artifactory::binary_provider_filesystem_dir } else { $binary_provider_filesystem_dir = undef } # Check if a DB configuration was provided. - if ($::artifactory::db_url or - $::artifactory::db_username or - $::artifactory::db_password or - $::artifactory::db_type) { - + if ($artifactory::db_url or $artifactory::db_username or $artifactory::db_password + or $artifactory::db_type) { # Check if all database parameters can be found. - if ($::artifactory::db_url and - $::artifactory::db_username and - $::artifactory::db_password and - $::artifactory::db_type) { - + if ($artifactory::db_url and $artifactory::db_username and $artifactory::db_password + and $artifactory::db_type) { # Download JDBC files. - if ($::artifactory::jdbc_driver_url) { - $file_name = regsubst($::artifactory::jdbc_driver_url, '.+\/([^\/]+)$', '\1') + if ($artifactory::jdbc_driver_url) { + $file_name = regsubst($artifactory::jdbc_driver_url, '.+\/([^\/]+)$', '\1') file { "${_lib_dir}/${file_name}": - source => $::artifactory::jdbc_driver_url, + source => $artifactory::jdbc_driver_url, mode => '0775', owner => 'root', } } # Determine type of database. - $db_driver = $::artifactory::db_type ? { + $db_driver = $artifactory::db_type ? { 'derby' => 'org.apache.derby.jdbc.EmbeddedDriver', 'mariadb' => 'org.mariadb.jdbc.Driver', 'mssql' => 'com.microsoft.sqlserver.jdbc.SQLServerDriver', @@ -115,27 +109,27 @@ # Prepare options hash. Will later be used to setup DB configuration. $__dbpropchanges = { - 'type' => $::artifactory::db_type, - 'url' => $::artifactory::db_url, + 'type' => $artifactory::db_type, + 'url' => $artifactory::db_url, 'driver' => $db_driver, - 'username' => $::artifactory::db_username, + 'username' => $artifactory::db_username, 'binary.provider.type' => $binary_provider_type, - 'pool.max.active' => $::artifactory::pool_max_active, - 'pool.max.idle' => $::artifactory::pool_max_idle, - 'binary.provider.cache.maxsize' => $::artifactory::binary_provider_cache_maxsize, + 'pool.max.active' => $artifactory::pool_max_active, + 'pool.max.idle' => $artifactory::pool_max_idle, + 'binary.provider.cache.maxsize' => $artifactory::binary_provider_cache_maxsize, 'binary.provider.filesystem.dir' => $binary_provider_filesystem_dir, - 'binary.provider.cache_dir' => $::artifactory::binary_provider_cache_dir, + 'binary.provider.cache_dir' => $artifactory::binary_provider_cache_dir, } # We only care to set values that have actually been defined. # Therefore remove empty ones from our collection. $_dbpropchanges = delete_undef_values($__dbpropchanges) # Pre-load secrets from a temporary file when starting up Artifctory. - if $::artifactory::use_temp_db_secrets { + if $artifactory::use_temp_db_secrets { file { $_secrets_dir: ensure => directory, - owner => $::artifactory::config_owner, - group => $::artifactory::config_group, + owner => $artifactory::config_owner, + group => $artifactory::config_group, } file { "${$_secrets_dir}/.temp.db.properties": @@ -143,23 +137,23 @@ content => epp( 'artifactory/db.properties.epp', { - db_url => $::artifactory::db_url, - db_username => $::artifactory::db_username, - db_password => $::artifactory::db_password, - db_type => $::artifactory::db_type, + db_url => $artifactory::db_url, + db_username => $artifactory::db_username, + db_password => $artifactory::db_password, + db_type => $artifactory::db_type, db_driver => $db_driver, binary_provider_type => $binary_provider_type, - pool_max_active => $::artifactory::pool_max_active, - pool_max_idle => $::artifactory::pool_max_idle, - binary_provider_cache_maxsize => $::artifactory::binary_provider_cache_maxsize, - binary_provider_base_data_dir => $::artifactory::binary_provider_base_data_dir, + pool_max_active => $artifactory::pool_max_active, + pool_max_idle => $artifactory::pool_max_idle, + binary_provider_cache_maxsize => $artifactory::binary_provider_cache_maxsize, + binary_provider_base_data_dir => $artifactory::binary_provider_base_data_dir, binary_provider_filesystem_dir => $binary_provider_filesystem_dir, - binary_provider_cache_dir => $::artifactory::binary_provider_cache_dir, + binary_provider_cache_dir => $artifactory::binary_provider_cache_dir, } ), mode => '0640', - owner => $::artifactory::config_owner, - group => $::artifactory::config_group, + owner => $artifactory::config_owner, + group => $artifactory::config_group, } # Setup a symlink for legacy versions. @@ -182,8 +176,8 @@ file { "${artifactory::data_directory}/etc/db.properties": ensure => file, mode => '0640', - owner => $::artifactory::config_owner, - group => $::artifactory::config_group, + owner => $artifactory::config_owner, + group => $artifactory::config_group, } file { "${artifactory::data_directory}/etc/storage.properties": ensure => link, @@ -192,9 +186,9 @@ # Prepare DB hash for use with Augeas. $dbpropchanges = $_dbpropchanges.reduce([]) | $memo, $value | { - # lint:ignore:140chars + # lint:ignore:140chars $memo + "set \"${value[0]}\" \"${value[1]}\"" - # lint:endignore + # lint:endignore } # Setup database configuration in db.properties. @@ -203,8 +197,8 @@ incl => "${artifactory::data_directory}/etc/db.properties", lens => 'Properties.lns', changes => $dbpropchanges, - require => [Class['::artifactory::install']], - notify => Class['::artifactory::service'], + require => [Class['artifactory::install']], + notify => Class['artifactory::service'], } # We treat db_password differently @@ -217,10 +211,10 @@ context => "/files${artifactory::data_directory}/etc/db.properties", incl => "${artifactory::data_directory}/etc/db.properties", lens => 'Properties.lns', - changes => [ "set \"password\" \"${::artifactory::db_password}\"" ], + changes => ["set \"password\" \"${artifactory::db_password}\""], onlyif => "match /files${artifactory::data_directory}/etc/db.properties/password size == 0", - require => [Class['::artifactory::install']], - notify => Class['::artifactory::service'], + require => [Class['artifactory::install']], + notify => Class['artifactory::service'], } } } @@ -228,7 +222,7 @@ else { # We are making an assumption that not passing db_username and db_password we are changing to derby # and do not need db.properties file, but least be explicit in cleaning up. - if ($_legacy == true) and ($::artifactory::db_type == 'derby') { + if ($_legacy == true) and ($artifactory::db_type == 'derby') { file { "${artifactory::data_directory}/etc/db.properties": ensure => absent, } @@ -240,52 +234,52 @@ # Configure the filestore. file { "${_config_dir}/binarystore.xml": ensure => file, - owner => $::artifactory::config_owner, - group => $::artifactory::config_group, + owner => $artifactory::config_owner, + group => $artifactory::config_group, content => epp( 'artifactory/binarystore.xml.epp', { binary_provider_type => $_binary_provider_type, - binary_provider_cache_maxsize => $::artifactory::binary_provider_cache_maxsize, - binary_provider_base_data_dir => $::artifactory::binary_provider_base_data_dir, + binary_provider_cache_maxsize => $artifactory::binary_provider_cache_maxsize, + binary_provider_base_data_dir => $artifactory::binary_provider_base_data_dir, binary_provider_filesystem_dir => $binary_provider_filesystem_dir, - binary_provider_cache_dir => $::artifactory::binary_provider_cache_dir, - binary_provider_config_hash => $::artifactory::binary_provider_config_hash, + binary_provider_cache_dir => $artifactory::binary_provider_cache_dir, + binary_provider_config_hash => $artifactory::binary_provider_config_hash, } ), notify => Class['artifactory::service'], } # Install master key. - if ($::artifactory::master_key) { + if ($artifactory::master_key) { file { $_security_dir: ensure => directory, - owner => $::artifactory::config_owner, - group => $::artifactory::config_group, + owner => $artifactory::config_owner, + group => $artifactory::config_group, } file { "${_security_dir}/master.key": ensure => file, - content => $::artifactory::master_key, + content => $artifactory::master_key, mode => '0640', - owner => $::artifactory::config_owner, - group => $::artifactory::config_group, + owner => $artifactory::config_owner, + group => $artifactory::config_group, notify => Class['artifactory::service'], } } # Install license key for commercial edition. - if ($::artifactory::license_key) { + if ($artifactory::license_key) { file { "${_license_dir}/artifactory.lic": ensure => file, - content => $::artifactory::license_key, + content => $artifactory::license_key, mode => '0664', } } # Automatically setup the database server. - if ($::artifactory::db_automate) and ($::artifactory::db_type == 'mysql') { - include ::artifactory::mysql + if ($artifactory::db_automate) and ($artifactory::db_type == 'mysql') { + include artifactory::mysql file_line { 'limits': ensure => present, @@ -293,6 +287,6 @@ line => "artifactory soft nofile 32000 \n artifactory hard nofile 32000", notify => Class['artifactory::service'], } - contain ::mysql::server + contain mysql::server } } diff --git a/manifests/init.pp b/manifests/init.pp index 755cc2e..503984d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -13,7 +13,7 @@ # @param download_url_oss # The download URL for the open-source edition. # -# @param download_url_oss +# @param download_url_pro # The download URL for the pro edition. # # @param install_method @@ -26,7 +26,7 @@ # Controls the name of a version-independent symlink for the archive # installation. It will always point to the release specified by `$package_version`. # -class artifactory( +class artifactory ( Enum['oss', 'pro', 'enterprise'] $edition = 'oss', Boolean $manage_repo = true, Boolean $use_temp_db_secrets = true, @@ -79,8 +79,8 @@ $data_directory = $archive_data_dir } - Class{'::artifactory::repo': } - -> class{'::artifactory::install': } - -> class{'::artifactory::config': } - -> class{'::artifactory::service': } + Class { 'artifactory::repo': } + -> Class { 'artifactory::install': } + -> Class { 'artifactory::config': } + -> Class { 'artifactory::service': } } diff --git a/manifests/install.pp b/manifests/install.pp index 5f993ec..7e6b0d1 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -12,5 +12,8 @@ contain artifactory::install::archive Class['artifactory::install::archive'] } + default : { + fail("install method ${artifactory::install_method} is not supported") + } } } diff --git a/manifests/install/archive.pp b/manifests/install/archive.pp index fe57194..d62b59f 100644 --- a/manifests/install/archive.pp +++ b/manifests/install/archive.pp @@ -13,7 +13,7 @@ $url = $artifactory::download_url_pro } default : { - fail("install method ${install_method} does not support edition ${artifactory::edition}") + fail("install method ${artifactory::install_method} does not support edition ${artifactory::edition}") } } @@ -49,7 +49,7 @@ subscribe => [ Archive[$archive_file], ], - require => [ + require => [ Archive[$archive_file], ], } @@ -59,10 +59,10 @@ # script handles user/group creation. Hence this directory must # not be altered anymore after initial creation. $command = join([ - # Create the data directory. - "mkdir -p ${artifactory::data_directory}", - # "Initialize" data directory once by copying files from new installation. - "&& mv ${install_dir}/var/* ${artifactory::data_directory}/", + # Create the data directory. + "mkdir -p ${artifactory::data_directory}", + # "Initialize" data directory once by copying files from new installation. + "&& mv ${install_dir}/var/* ${artifactory::data_directory}/", ], ' ') exec { 'create data directory': path => '/usr/bin:/bin:/usr/local/bin:/usr/sbin:/sbin:/usr/local/sbin', diff --git a/manifests/install/package.pp b/manifests/install/package.pp index 298777c..0f59b38 100644 --- a/manifests/install/package.pp +++ b/manifests/install/package.pp @@ -11,6 +11,6 @@ } package { $_package: - ensure => $::artifactory::package_version, + ensure => $artifactory::package_version, } } diff --git a/manifests/mysql.pp b/manifests/mysql.pp index e3f496f..d41a365 100644 --- a/manifests/mysql.pp +++ b/manifests/mysql.pp @@ -1,15 +1,15 @@ # Manages mysql server if automated class artifactory::mysql { - class { '::mysql::server': + class { 'mysql::server': package_name => 'mariadb-server', package_ensure => '5.5.60-1.el7_5', - root_password => $::artifactory::root_password, + root_password => $artifactory::root_password, remove_default_accounts => true, } mysql::db { 'artdb': - user => $::artifactory::db_username, - password => $::artifactory::db_password, + user => $artifactory::db_username, + password => $artifactory::db_password, dbname => 'artdb', host => 'localhost', grant => 'ALL', diff --git a/manifests/repo.pp b/manifests/repo.pp index e2b5b45..34d0910 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -3,7 +3,7 @@ class artifactory::repo () { assert_private() - if $::artifactory::manage_repo { + if $artifactory::manage_repo { case $facts['os']['family'] { 'RedHat', 'Linux': { contain artifactory::repo::yum diff --git a/manifests/repo/yum.pp b/manifests/repo/yum.pp index de947ed..0d58869 100644 --- a/manifests/repo/yum.pp +++ b/manifests/repo/yum.pp @@ -1,7 +1,7 @@ # == Class artifactory::repo::yum # class artifactory::repo::yum { - if $::artifactory::manage_repo { + if $artifactory::manage_repo { case $artifactory::edition { 'enterprise', 'pro' : { $_url = $artifactory::yum_baseurl_pro @@ -12,9 +12,9 @@ } # Add the jfrog yum repo - yumrepo { $::artifactory::yum_name: + yumrepo { $artifactory::yum_name: baseurl => $_url, - descr => $::artifactory::yum_name, + descr => $artifactory::yum_name, gpgcheck => 1, enabled => 1, gpgkey => "${_url}/repodata/repomd.xml.key", diff --git a/spec/classes/artifactory_spec.rb b/spec/classes/artifactory_spec.rb index 1f3873f..6cab3ef 100644 --- a/spec/classes/artifactory_spec.rb +++ b/spec/classes/artifactory_spec.rb @@ -24,7 +24,7 @@ is_expected.to contain_apt__source('artifactory').with( 'location' => 'https://releases.jfrog.io/artifactory/artifactory-debs', 'release' => os_facts[:os]['distro']['codename'], - 'repos' => 'main' + 'repos' => 'main', ) } else @@ -275,7 +275,6 @@ is_expected.to contain_file('/var/opt/jfrog/artifactory/etc/artifactory/binarystore.xml').with_content(%r{true}) } end - end end end