12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [25.3.0](https://github.com/theforeman/puppet-foreman/tree/25.3.0) (2024-11-04)

[Full Changelog](https://github.com/theforeman/puppet-foreman/compare/25.2.2...25.3.0)

**Implemented enhancements:**

- add support for plugin `ensure` stage \*purged\* [\#1187](https://github.com/theforeman/puppet-foreman/pull/1187) ([UiP9AV6Y](https://github.com/UiP9AV6Y))

**Fixed bugs:**

- properly escape quotes in passwords by calling to\_ruby [\#1189](https://github.com/theforeman/puppet-foreman/pull/1189) ([evgeni](https://github.com/evgeni))

## [25.2.2](https://github.com/theforeman/puppet-foreman/tree/25.2.2) (2024-09-18)

[Full Changelog](https://github.com/theforeman/puppet-foreman/compare/24.2.1...25.2.2)
Expand Down
6 changes: 4 additions & 2 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @summary Manages a plugin installation and optionally its configuration
#
# @param version
# The version to ensure
# The version to ensure, or absent/purged to remove it
#
# @param package
# The package to manage
Expand Down Expand Up @@ -43,8 +43,10 @@
}

if $config {
$config_file_absent = $version in ['absent', 'purged']

file { $config_file:
ensure => bool2str($version == 'absent', 'absent', 'file'),
ensure => bool2str($config_file_absent, 'absent', 'file'),
owner => $config_file_owner,
group => $config_file_group,
mode => $config_file_mode,
Expand Down
12 changes: 7 additions & 5 deletions manifests/plugin/remote_execution/cockpit.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
#
# === Advanced parameters:
#
# $ensure:: Specify the package state, or absent to remove it
# $ensure:: Specify the package state, or absent/purged to remove it
#
class foreman::plugin::remote_execution::cockpit (
Optional[String[1]] $ensure = undef,
Array[Stdlib::HTTPUrl] $origins = [],
) {
if $ensure != 'absent' {
$ensure_absent = $ensure in ['absent', 'purged']

unless $ensure_absent {
require foreman::plugin::remote_execution
}

Expand All @@ -36,7 +38,7 @@
version => $ensure,
}

if $ensure != 'absent' {
unless $ensure_absent {
service { 'foreman-cockpit':
ensure => running,
enable => true,
Expand All @@ -45,7 +47,7 @@
}
}

$file_ensure = bool2str($ensure == 'absent', 'absent', 'file')
$file_ensure = bool2str($ensure_absent, 'absent', 'file')

file { "${config_directory}/cockpit.conf":
ensure => $file_ensure,
Expand All @@ -65,7 +67,7 @@
require => Foreman::Plugin['remote_execution-cockpit'],
}

if $ensure == 'absent' {
if $ensure_absent {
foreman_config_entry { 'remote_execution_cockpit_url':
value => '',
ignore_missing => true,
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system CentOS 8

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system CentOS 8
"name": "theforeman-foreman",
"version": "25.2.2",
"version": "25.3.0",
"author": "theforeman",
"summary": "Foreman server configuration",
"license": "GPL-3.0+",
Expand Down
16 changes: 16 additions & 0 deletions spec/classes/plugin/remote_execution_cockpit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ class {'foreman':
it { is_expected.to contain_file('/etc/foreman/cockpit/foreman-cockpit-session.yml').with_ensure('absent') }
it { is_expected.to contain_foreman_config_entry('remote_execution_cockpit_url').with_value('') }
end

describe 'ensure purged' do
let(:params) do
{
ensure: 'purged',
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_class('foreman::plugin::remote_execution') }
it { is_expected.to contain_foreman__plugin('remote_execution-cockpit').with_version('purged') }
it { is_expected.not_to contain_service('foreman-cockpit') }
it { is_expected.to contain_file('/etc/foreman/cockpit/cockpit.conf').with_ensure('absent') }
it { is_expected.to contain_file('/etc/foreman/cockpit/foreman-cockpit-session.yml').with_ensure('absent') }
it { is_expected.to contain_foreman_config_entry('remote_execution_cockpit_url').with_value('') }
end
end
end
end
14 changes: 14 additions & 0 deletions spec/defines/foreman_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@
it { is_expected.to contain_package('myplugin').with_ensure('absent') }
it { is_expected.to contain_file('/etc/foreman/plugins/foreman_myplugin.yaml').with_ensure('absent') }
end

context 'ensure purged' do
let(:params) do
{
package: 'myplugin', # fixed to make testing easier
version: 'purged',
config: 'the config content',
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('myplugin').with_ensure('purged') }
it { is_expected.to contain_file('/etc/foreman/plugins/foreman_myplugin.yaml').with_ensure('absent') }
end
end
end
end
2 changes: 1 addition & 1 deletion templates/database.yml.epp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
username: <%= $username %>
<% } -%>
<% if $password { -%>
password: "<%= $password %>"
password: <%= stdlib::to_ruby($password) %>
<% } -%>
pool: <%= $db_pool %>