From c7b72068fd2293fc90d3568ddf6cde8f794f6e46 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 2 May 2023 14:23:42 +0100 Subject: [PATCH 1/4] (CONT-950) - Resolve inadequate datatype for $value Resolves an issue introduced during the syntax update carried out in this module. The parameter $value in config_entry, can be either a String, Integer or Float. However, it was wrongly set to exclude Floating point numbers. --- manifests/server/config_entry.pp | 6 +++--- spec/defines/server/config_entry_spec.rb | 27 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/manifests/server/config_entry.pp b/manifests/server/config_entry.pp index 974114359a..73ee8e5fb3 100644 --- a/manifests/server/config_entry.pp +++ b/manifests/server/config_entry.pp @@ -5,9 +5,9 @@ # @param path Path for postgresql.conf # define postgresql::server::config_entry ( - Enum['present', 'absent'] $ensure = 'present', - Optional[Variant[String[1], Integer]] $value = undef, - Variant[Boolean, String[1]] $path = false + Enum['present', 'absent'] $ensure = 'present', + Optional[Variant[String[1], Integer, Float]] $value = undef, + Variant[Boolean, String[1]] $path = false ) { $postgresql_conf_path = $postgresql::server::postgresql_conf_path diff --git a/spec/defines/server/config_entry_spec.rb b/spec/defines/server/config_entry_spec.rb index 2ee8c6db4e..223ac7b070 100644 --- a/spec/defines/server/config_entry_spec.rb +++ b/spec/defines/server/config_entry_spec.rb @@ -42,6 +42,33 @@ end end + context 'passes values through appropriately' do + let(:params) { { ensure: 'present', name: 'string_value', value: 'entry_test' } } + + it 'as a String' do + expect(subject).to contain_postgresql_conf('string_value').with(name: 'string_value', + value: 'entry_test') + end + end + + context 'passes values through appropriately' do + let(:params) { { ensure: 'present', name: 'integer_value', value: 40 } } + + it 'as an Integer' do + expect(subject).to contain_postgresql_conf('integer_value').with(name: 'integer_value', + value: 40) + end + end + + context 'passes values through appropriately' do + let(:params) { { ensure: 'present', name: 'floating_point_value', value: 4.0 } } + + it 'a Float' do + expect(subject).to contain_postgresql_conf('floating_point_value').with(name: 'floating_point_value', + value: 4.0) + end + end + context 'unix_socket_directories' do let(:params) { { ensure: 'present', name: 'unix_socket_directories', value: '/var/pgsql, /opt/postgresql, /root/' } } From 339ea33307d68b45f223895f3d97692d7cc791cf Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 2 May 2023 15:24:07 +0100 Subject: [PATCH 2/4] (CONT-950) - Array of $listen_addresses This commit adds functionality to allow an array of $listen_addresses to be specified as a string containing a comma-seperated list of addresses, which was removed unintentioanlly in https://github.com/puppetlabs/puppetlabs-postgresql/pull/1397. Fixes https://github.com/puppetlabs/puppetlabs-postgresql/issues/1426. --- lib/puppet/provider/postgresql_conf/parsed.rb | 3 ++ manifests/server.pp | 2 +- manifests/server/instance/config.pp | 54 +++++++++---------- .../provider/postgresql_conf/parsed_spec.rb | 8 ++- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/puppet/provider/postgresql_conf/parsed.rb b/lib/puppet/provider/postgresql_conf/parsed.rb index f90570ce70..8918769cab 100644 --- a/lib/puppet/provider/postgresql_conf/parsed.rb +++ b/lib/puppet/provider/postgresql_conf/parsed.rb @@ -21,6 +21,9 @@ # simple string and numeric values don't need to be enclosed in quotes val = if h[:value].is_a?(Numeric) h[:value].to_s + elsif h[:value].is_a?(Array) + # multiple listen_addresses specified as a string containing a comma-speparated list + h[:value].join(', ') else h[:value] end diff --git a/manifests/server.pp b/manifests/server.pp index b205a1384c..582049c720 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -107,7 +107,7 @@ Optional[String[1]] $service_status = $postgresql::params::service_status, String[1] $default_database = $postgresql::params::default_database, Hash $default_connect_settings = $postgresql::globals::default_connect_settings, - Optional[String[1]] $listen_addresses = $postgresql::params::listen_addresses, + Optional[Variant[String[1], Array[String[1]]]] $listen_addresses = $postgresql::params::listen_addresses, Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::params::port, String[1] $ip_mask_deny_postgres_user = $postgresql::params::ip_mask_deny_postgres_user, String[1] $ip_mask_allow_all_users = $postgresql::params::ip_mask_allow_all_users, diff --git a/manifests/server/instance/config.pp b/manifests/server/instance/config.pp index 7926dc6529..d9e1cd94b5 100644 --- a/manifests/server/instance/config.pp +++ b/manifests/server/instance/config.pp @@ -35,33 +35,33 @@ # @param extra_systemd_config Adds extra config to systemd config file, can for instance be used to add extra openfiles. This can be a multi line string # lint:endignore:140chars define postgresql::server::instance::config ( - String[1] $ip_mask_deny_postgres_user = $postgresql::server::ip_mask_deny_postgres_user, - String[1] $ip_mask_allow_all_users = $postgresql::server::ip_mask_allow_all_users, - Optional[String[1]] $listen_addresses = $postgresql::server::listen_addresses, - Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port, - Array[String[1]] $ipv4acls = $postgresql::server::ipv4acls, - Array[String[1]] $ipv6acls = $postgresql::server::ipv6acls, - Variant[String[1], Stdlib::Absolutepath] $pg_hba_conf_path = $postgresql::server::pg_hba_conf_path, - Variant[String[1], Stdlib::Absolutepath] $pg_ident_conf_path = $postgresql::server::pg_ident_conf_path, - Variant[String[1], Stdlib::Absolutepath] $postgresql_conf_path = $postgresql::server::postgresql_conf_path, - Optional[Stdlib::Filemode] $postgresql_conf_mode = $postgresql::server::postgresql_conf_mode, - Variant[String[1], Stdlib::Absolutepath] $recovery_conf_path = $postgresql::server::recovery_conf_path, - Boolean $pg_hba_conf_defaults = $postgresql::server::pg_hba_conf_defaults, - String[1] $user = $postgresql::server::user, - String[1] $group = $postgresql::server::group, - Optional[String[1]] $version = $postgresql::server::_version, - Boolean $manage_pg_hba_conf = $postgresql::server::manage_pg_hba_conf, - Boolean $manage_pg_ident_conf = $postgresql::server::manage_pg_ident_conf, - Boolean $manage_recovery_conf = $postgresql::server::manage_recovery_conf, - Boolean $manage_postgresql_conf_perms = $postgresql::server::manage_postgresql_conf_perms, - String[1] $datadir = $postgresql::server::datadir, - Optional[String[1]] $logdir = $postgresql::server::logdir, - String[1] $service_name = $postgresql::server::service_name, - Boolean $service_enable = $postgresql::server::service_enable, - Optional[String[1]] $log_line_prefix = $postgresql::server::log_line_prefix, - Optional[String[1]] $timezone = $postgresql::server::timezone, - Optional[String] $password_encryption = $postgresql::server::password_encryption, - Optional[String] $extra_systemd_config = $postgresql::server::extra_systemd_config, + String[1] $ip_mask_deny_postgres_user = $postgresql::server::ip_mask_deny_postgres_user, + String[1] $ip_mask_allow_all_users = $postgresql::server::ip_mask_allow_all_users, + Optional[Variant[String[1], Array[String[1]]]] $listen_addresses = $postgresql::server::listen_addresses, + Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port, + Array[String[1]] $ipv4acls = $postgresql::server::ipv4acls, + Array[String[1]] $ipv6acls = $postgresql::server::ipv6acls, + Variant[String[1], Stdlib::Absolutepath] $pg_hba_conf_path = $postgresql::server::pg_hba_conf_path, + Variant[String[1], Stdlib::Absolutepath] $pg_ident_conf_path = $postgresql::server::pg_ident_conf_path, + Variant[String[1], Stdlib::Absolutepath] $postgresql_conf_path = $postgresql::server::postgresql_conf_path, + Optional[Stdlib::Filemode] $postgresql_conf_mode = $postgresql::server::postgresql_conf_mode, + Variant[String[1], Stdlib::Absolutepath] $recovery_conf_path = $postgresql::server::recovery_conf_path, + Boolean $pg_hba_conf_defaults = $postgresql::server::pg_hba_conf_defaults, + String[1] $user = $postgresql::server::user, + String[1] $group = $postgresql::server::group, + Optional[String[1]] $version = $postgresql::server::_version, + Boolean $manage_pg_hba_conf = $postgresql::server::manage_pg_hba_conf, + Boolean $manage_pg_ident_conf = $postgresql::server::manage_pg_ident_conf, + Boolean $manage_recovery_conf = $postgresql::server::manage_recovery_conf, + Boolean $manage_postgresql_conf_perms = $postgresql::server::manage_postgresql_conf_perms, + String[1] $datadir = $postgresql::server::datadir, + Optional[String[1]] $logdir = $postgresql::server::logdir, + String[1] $service_name = $postgresql::server::service_name, + Boolean $service_enable = $postgresql::server::service_enable, + Optional[String[1]] $log_line_prefix = $postgresql::server::log_line_prefix, + Optional[String[1]] $timezone = $postgresql::server::timezone, + Optional[String] $password_encryption = $postgresql::server::password_encryption, + Optional[String] $extra_systemd_config = $postgresql::server::extra_systemd_config, ) { if ($manage_pg_hba_conf == true) { # Prepare the main pg_hba file diff --git a/spec/unit/provider/postgresql_conf/parsed_spec.rb b/spec/unit/provider/postgresql_conf/parsed_spec.rb index 3c3de16ddc..7f6fdaef05 100644 --- a/spec/unit/provider/postgresql_conf/parsed_spec.rb +++ b/spec/unit/provider/postgresql_conf/parsed_spec.rb @@ -136,10 +136,16 @@ ) end - it 'quotes addresses' do + it 'quotes single string address' do expect(provider.to_line(name: 'listen_addresses', value: '0.0.0.0', comment: nil, record_type: :parsed)).to eq( "listen_addresses = '0.0.0.0'", ) end + + it 'quotes an array of addresses' do + expect(provider.to_line(name: 'listen_addresses', value: ['0.0.0.0', '127.0.0.1'], comment: nil, record_type: :parsed)).to eq( + "listen_addresses = '0.0.0.0, 127.0.0.1'", + ) + end end end From d0ff0ac1af28376d2b47856a59c78ef3dcc2358b Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 2 May 2023 15:41:28 +0100 Subject: [PATCH 3/4] (CONT-950) - Address rubocop --- spec/defines/server/config_entry_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/defines/server/config_entry_spec.rb b/spec/defines/server/config_entry_spec.rb index 223ac7b070..8b13e020bd 100644 --- a/spec/defines/server/config_entry_spec.rb +++ b/spec/defines/server/config_entry_spec.rb @@ -42,28 +42,28 @@ end end - context 'passes values through appropriately' do + context 'passes a string value through appropriately' do let(:params) { { ensure: 'present', name: 'string_value', value: 'entry_test' } } - it 'as a String' do + it 'and adds string value to config' do expect(subject).to contain_postgresql_conf('string_value').with(name: 'string_value', - value: 'entry_test') + value: 'entry_test') end end - context 'passes values through appropriately' do + context 'passes an integer value through appropriately' do let(:params) { { ensure: 'present', name: 'integer_value', value: 40 } } - it 'as an Integer' do + it 'and adds integer value to config' do expect(subject).to contain_postgresql_conf('integer_value').with(name: 'integer_value', - value: 40) + value: 40) end end - context 'passes values through appropriately' do + context 'passes a float value through appropriately' do let(:params) { { ensure: 'present', name: 'floating_point_value', value: 4.0 } } - it 'a Float' do + it 'and adds float value to config' do expect(subject).to contain_postgresql_conf('floating_point_value').with(name: 'floating_point_value', value: 4.0) end From 50df6088331c50bc79f7fd41b3bb26e6768a44ab Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 2 May 2023 15:42:20 +0100 Subject: [PATCH 4/4] (CONT-950) - Opt for Numeric data type --- manifests/server/config_entry.pp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/server/config_entry.pp b/manifests/server/config_entry.pp index 73ee8e5fb3..607ef3ca20 100644 --- a/manifests/server/config_entry.pp +++ b/manifests/server/config_entry.pp @@ -5,9 +5,9 @@ # @param path Path for postgresql.conf # define postgresql::server::config_entry ( - Enum['present', 'absent'] $ensure = 'present', - Optional[Variant[String[1], Integer, Float]] $value = undef, - Variant[Boolean, String[1]] $path = false + Enum['present', 'absent'] $ensure = 'present', + Optional[Variant[String[1], Numeric]] $value = undef, + Variant[Boolean, String[1]] $path = false ) { $postgresql_conf_path = $postgresql::server::postgresql_conf_path