From 9ced0386718f7ae4b09ba64707b88b79eafe7676 Mon Sep 17 00:00:00 2001 From: Joris29 Date: Tue, 16 Jan 2024 08:22:54 +0100 Subject: [PATCH] Add cli support in rundeck class and update unit tests --- manifests/init.pp | 43 +++++++++++++++++++++-- spec/classes/config/ssl_spec.rb | 16 ++++----- spec/classes/config_spec.rb | 18 ++++++---- spec/classes/install_spec.rb | 31 +++++----------- spec/classes/rundeck_spec.rb | 17 +++++++-- spec/classes/service_spec.rb | 6 ++-- spec/defines/config/aclpolicyfile_spec.rb | 12 +++---- 7 files changed, 91 insertions(+), 52 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 8e98f393d..cd2c4eb41 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,10 +1,13 @@ # @summary Class to manage installation and configuration of Rundeck. # -# @param manage_repo -# Whether to manage the package repository. +# @param override_dir +# An absolute path to the overrides directory. +# Examples/defaults for yumrepo can be found at RedHat.yaml, and for apt at Debian.yaml # @param repo_config # A hash of repository attributes for configuring the rundeck package repositories. # Examples/defaults for yumrepo can be found at RedHat.yaml, and for apt at Debian.yaml +# @param manage_repo +# Whether to manage the package repository. # @param package_ensure # Ensure the state of the rundeck package, either present, absent or a specific version. # @param manage_home @@ -35,6 +38,8 @@ # Wheter to enable cluster mode. # @param execution_mode # Set the execution mode to 'active' or 'passive'. +# @param api_token_max_duration +# Set the token max duration. # @param java_home # Set the home directory of java. # @param jvm_args @@ -106,6 +111,18 @@ # Allows you to use your own override template instead to config rundeckd init script. # @param service_script # Allows you to use your own override template instead of the default from the package maintainer for rundeckd init script. +# @param manage_cli +# Wheter to manage rundeck cli config and resource with the rundeck class or not. +# @param cli_version +# Ensure the state of the rundeck cli package, either present, absent or a specific version. +# @param cli_user +# Cli user to authenticate. +# @param cli_password +# Cli password to authenticate. +# @param cli_token +# Cli token to authenticate. +# @param cli_projects +# Cli projects config. # class rundeck ( Stdlib::Absolutepath $override_dir, @@ -222,6 +239,12 @@ Boolean $service_notify = true, Optional[String[1]] $service_config = undef, Optional[String[1]] $service_script = undef, + Boolean $manage_cli = true, + String[1] $cli_version = 'installed', + String[1] $cli_user = 'admin', + String[1] $cli_password = 'admin', + Optional[String[8]] $cli_token = undef, + Hash[String, Rundeck::Project] $cli_projects = {}, ) { validate_rd_policy($admin_policies) validate_rd_policy($api_policies) @@ -239,4 +262,20 @@ -> Class['rundeck::config'] -> Class['rundeck::service'] } + + if $manage_cli { + class { 'rundeck::cli': + manage_repo => false, + version => $cli_version, + url => $rundeck::config::framework_config['framework.server.url'], + bypass_url => $grails_server_url, + user => $cli_user, + password => $cli_password, + token => $cli_token, + projects => $cli_projects, + } + + Class['rundeck::service'] + -> Class['rundeck::cli'] + } } diff --git a/spec/classes/config/ssl_spec.rb b/spec/classes/config/ssl_spec.rb index 4f17ed721..0ee3f38a9 100644 --- a/spec/classes/config/ssl_spec.rb +++ b/spec/classes/config/ssl_spec.rb @@ -26,7 +26,7 @@ it { is_expected.to contain_file('/etc/rundeck/ssl').with('ensure' => 'directory') } it { is_expected.to contain_file('/etc/rundeck/ssl/ssl.properties') } - it { + it do is_expected.to contain_java_ks('keystore').with( ensure: 'present', certificate: '/etc/rundeck/ssl/rundeck.crt', @@ -35,15 +35,15 @@ password: 'adminadmin', target: '/etc/rundeck/ssl/keystore' ) - } + end - it { + it do is_expected.to contain_java_ks('truststore').with( ensure: 'present', password: 'adminadmin', target: '/etc/rundeck/ssl/truststore' ) - } + end ssl_details.each do |key, value| it 'generates valid content for ssl.properties' do @@ -61,19 +61,19 @@ } end - it { + it do is_expected.to contain_java_ks('keystore').with( ensure: 'present', destkeypass: 'verysecure' ) - } + end - it { + it do is_expected.to contain_java_ks('truststore').with( ensure: 'present', destkeypass: 'verysecure' ) - } + end it 'generates valid content for ssl.properties' do content = catalogue.resource('file', '/etc/rundeck/ssl/ssl.properties')[:content] diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 0cabe488b..3b16e1799 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -12,11 +12,15 @@ facts end - context 'without any parameters test rundeck::config' do - it { is_expected.to contain_file('/var/lib/rundeck').with('ensure' => 'directory') } - it { is_expected.to contain_file('/var/lib/rundeck/libext').with('ensure' => 'directory') } - it { is_expected.to contain_file('/etc/rundeck').with('ensure' => 'directory') } - it { is_expected.to contain_file('/var/log/rundeck').with('ensure' => 'directory') } + context 'with default parameters test rundeck::config' do + it { is_expected.to contain_file('/var/lib/rundeck').with(ensure: 'directory') } + it { is_expected.to contain_file('/var/lib/rundeck/libext').with(ensure: 'directory') } + it { is_expected.to contain_file('/etc/rundeck').with(ensure: 'directory') } + it { is_expected.to contain_file('/var/lib/rundeck/var').with(ensure: 'directory') } + it { is_expected.to contain_file('/var/lib/rundeck/var/tmp').with(ensure: 'directory') } + it { is_expected.to contain_file('/var/lib/rundeck/var/logs').with(ensure: 'directory') } + + it { is_expected.to contain_file('/var/log/rundeck').with(ensure: 'directory') } it { is_expected.to contain_file('/etc/rundeck/log4j2.properties') } @@ -46,8 +50,8 @@ it { is_expected.to contain_class('rundeck::config::jaas_auth') } it { is_expected.to contain_class('rundeck::config::framework') } - it { is_expected.to contain_file('/etc/rundeck/project.properties').with('ensure' => 'absent') } - it { is_expected.to contain_file('/etc/rundeck/rundeck-config.properties').with('ensure' => 'file') } + it { is_expected.to contain_file('/etc/rundeck/project.properties').with(ensure: 'absent') } + it { is_expected.to contain_file('/etc/rundeck/rundeck-config.properties').with(ensure: 'file') } it 'generates valid content for rundeck-config.properties' do content = catalogue.resource('file', '/etc/rundeck/rundeck-config.properties')[:content] diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb index fb928b631..04202a186 100644 --- a/spec/classes/install_spec.rb +++ b/spec/classes/install_spec.rb @@ -9,9 +9,8 @@ facts end - context 'without any parameters test rundeck::install' do - let(:params) { {} } - + context 'with default parameters test rundeck::install' do + it { is_expected.not_to contain_group('rundeck') } it { is_expected.not_to contain_user('rundeck') } case facts[:os]['family'] @@ -35,7 +34,7 @@ 'name' => 'rundeck.asc', 'content' => %r{^-----BEGIN PGP PUBLIC KEY BLOCK-----}, } - ) + ).that_comes_before('Package[rundeck]') end it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck]') } @@ -54,13 +53,13 @@ } end - it { is_expected.to contain_group('A1234').with('ensure' => 'present') } + it { is_expected.to contain_group('A1234').with(ensure: 'present') } - it { is_expected.to contain_group('rundeck').with('ensure' => 'absent') } + it { is_expected.to contain_group('rundeck').with(ensure: 'absent') } - it { is_expected.to contain_user('A1234').with('ensure' => 'present') } + it { is_expected.to contain_user('A1234').with(ensure: 'present') } - it { is_expected.to contain_user('rundeck').with('ensure' => 'absent') } + it { is_expected.to contain_user('rundeck').with(ensure: 'absent') } end context 'different user and group with ids' do @@ -75,20 +74,8 @@ } end - it do - is_expected.to contain_group('A1234').with( - 'ensure' => 'present', - 'gid' => 10_000 - ) - end - - it do - is_expected.to contain_user('A1234').with( - 'ensure' => 'present', - 'gid' => '10000', - 'uid' => '10000' - ) - end + it { is_expected.to contain_group('A1234').with(ensure: 'present', gid: 10_000) } + it { is_expected.to contain_user('A1234').with(ensure: 'present', gid: 10_000, uid: 10_000) } end end end diff --git a/spec/classes/rundeck_spec.rb b/spec/classes/rundeck_spec.rb index 983cff476..148471ff7 100644 --- a/spec/classes/rundeck_spec.rb +++ b/spec/classes/rundeck_spec.rb @@ -9,9 +9,7 @@ facts end - context 'without any parameters test rundeck' do - let(:params) { {} } - + context 'with default parameters test rundeck' do it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('rundeck::install').that_comes_before('Class[rundeck::config]') } it { is_expected.to contain_class('rundeck::config').that_notifies('Class[rundeck::service]') } @@ -19,6 +17,7 @@ it { is_expected.to contain_class('rundeck::config::jaas_auth') } it { is_expected.to contain_class('rundeck::config::framework') } it { is_expected.not_to contain_class('rundeck::config::ssl') } + it { is_expected.to contain_class('rundeck::cli') } end context 'with service_notify => false' do @@ -31,6 +30,7 @@ it { is_expected.to contain_class('rundeck::install').that_comes_before('Class[rundeck::config]') } it { is_expected.to contain_class('rundeck::config').that_comes_before('Class[rundeck::service]') } it { is_expected.to contain_class('rundeck::service') } + it { is_expected.to contain_class('rundeck::cli') } end context 'with ssl_enabled => true' do @@ -57,6 +57,17 @@ expect(content).to include('rundeck.server.uuid = ac7c2cbd-14fa-5ba3-b3f2-d436e9b8a3b0') end end + + context 'with manage_cli => false' do + let(:params) do + { + manage_cli: false + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.not_to contain_class('rundeck::cli') } + end end end end diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index 23428d89e..615873a28 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -9,10 +9,8 @@ facts end - context 'without any parameters test rundeck::service' do - let(:params) { {} } - - it { is_expected.to contain_service('rundeckd') } + context 'with default parameters test rundeck::service' do + it { is_expected.to contain_service('rundeckd').with(ensure: 'running') } end end end diff --git a/spec/defines/config/aclpolicyfile_spec.rb b/spec/defines/config/aclpolicyfile_spec.rb index 133bb9f71..a58e11ad8 100644 --- a/spec/defines/config/aclpolicyfile_spec.rb +++ b/spec/defines/config/aclpolicyfile_spec.rb @@ -91,14 +91,14 @@ } end - it { + it do is_expected.to contain_file('/etc/rundeck/test.aclpolicy').with( owner: 'rundeck', group: 'rundeck', mode: '0644', content: test_acl ) - } + end end context 'with test acl and custom parameters' do @@ -112,22 +112,22 @@ } end - it { + it do is_expected.to contain_file('/etc/rundeck-acl').with( ensure: 'directory', owner: 'myUser', group: 'myGroup', mode: '0755' ) - } + end - it { + it do is_expected.to contain_file('/etc/rundeck-acl/test.aclpolicy').with( owner: 'myUser', group: 'myGroup', mode: '0644', content: test_acl ) - } + end end end