Skip to content

Commit

Permalink
Revert "New postgresql_conf provider, handles multiple configs"
Browse files Browse the repository at this point in the history
This reverts commit 179472b.
  • Loading branch information
ekohl committed Oct 23, 2023
1 parent d4560c1 commit d4054b4
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 291 deletions.
37 changes: 5 additions & 32 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,6 @@ The following parameters are available in the `postgresql::server::config_entry`
* [`key`](#-postgresql--server--config_entry--key)
* [`value`](#-postgresql--server--config_entry--value)
* [`path`](#-postgresql--server--config_entry--path)
* [`comment`](#-postgresql--server--config_entry--comment)

##### <a name="-postgresql--server--config_entry--ensure"></a>`ensure`

Expand Down Expand Up @@ -1560,14 +1559,6 @@ Path for postgresql.conf

Default value: `$postgresql::server::postgresql_conf_path`

##### <a name="-postgresql--server--config_entry--comment"></a>`comment`

Data type: `Optional[String[1]]`

Defines the comment for the setting. The # is added by default.

Default value: `undef`

### <a name="postgresql--server--database"></a>`postgresql::server::database`

Define for creating a database.
Expand Down Expand Up @@ -4309,12 +4300,6 @@ This type allows puppet to manage postgresql.conf parameters.

The following properties are available in the `postgresql_conf` type.

##### `comment`

Valid values: `%r{^[\w\W]+$}`

The comment to set for this parameter.

##### `ensure`

Valid values: `present`, `absent`
Expand All @@ -4323,46 +4308,34 @@ The basic property that the resource should be in.

Default value: `present`

##### `value`
##### `target`

Valid values: `%r{^\S(.*\S)?$}`
The path to postgresql.conf

##### `value`

The value to set for this parameter.

#### Parameters

The following parameters are available in the `postgresql_conf` type.

* [`key`](#-postgresql_conf--key)
* [`name`](#-postgresql_conf--name)
* [`provider`](#-postgresql_conf--provider)
* [`target`](#-postgresql_conf--target)

##### <a name="-postgresql_conf--key"></a>`key`

Valid values: `%r{^[\w.]+$}`

The Postgresql parameter to manage.

##### <a name="-postgresql_conf--name"></a>`name`

Valid values: `%r{^[\w.]+$}`

namevar

A unique title for the resource.
The postgresql parameter name to manage.

##### <a name="-postgresql_conf--provider"></a>`provider`

The specific backend to use for this `postgresql_conf` resource. You will seldom need to specify this --- Puppet will
usually discover the appropriate provider for your platform.

##### <a name="-postgresql_conf--target"></a>`target`

Valid values: `%r{^/\S+[a-z0-9(/)-]*\w+.conf$}`

The path to the postgresql config file

### <a name="postgresql_conn_validator"></a>`postgresql_conn_validator`

Verify that a connection can be successfully established between a node
Expand Down
45 changes: 45 additions & 0 deletions lib/puppet/provider/postgresql_conf/parsed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require 'puppet/provider/parsedfile'

Puppet::Type.type(:postgresql_conf).provide(
:parsed,
parent: Puppet::Provider::ParsedFile,
default_target: '/etc/postgresql.conf',
filetype: :flat,
) do
desc 'Set key/values in postgresql.conf.'

text_line :comment, match: %r{^\s*#}
text_line :blank, match: %r{^\s*$}

record_line :parsed,
fields: ['name', 'value', 'comment'],
optional: ['comment'],
match: %r{^\s*([\w.]+)\s*=?\s*(.*?)(?:\s*#\s*(.*))?\s*$},
to_line: proc { |h|
# 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
dontneedquote = val.match(%r{^(\d+.?\d+|\w+)$})
dontneedequal = h[:name].match(%r{^(include|include_if_exists)$}i)

str = h[:name].downcase # normalize case
str += dontneedequal ? ' ' : ' = '
str += "'" unless dontneedquote && !dontneedequal
str += val
str += "'" unless dontneedquote && !dontneedequal
str += " # #{h[:comment]}" unless h[:comment].nil? || h[:comment] == :absent
str
},
post_parse: proc { |h|
h[:name].downcase! # normalize case
h[:value].gsub!(%r{(^'|'$)}, '') # strip out quotes
}
end
167 changes: 0 additions & 167 deletions lib/puppet/provider/postgresql_conf/ruby.rb

This file was deleted.

32 changes: 10 additions & 22 deletions lib/puppet/type/postgresql_conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,28 @@

Puppet::Type.newtype(:postgresql_conf) do
@doc = 'This type allows puppet to manage postgresql.conf parameters.'

ensurable

newparam(:name) do
desc 'A unique title for the resource.'
newvalues(%r{^[\w.]+$})
end
desc 'The postgresql parameter name to manage.'
isnamevar

newparam(:key) do
desc 'The Postgresql parameter to manage.'
newvalues(%r{^[\w.]+$})
end

newproperty(:value) do
desc 'The value to set for this parameter.'
newvalues(%r{^\S(.*\S)?$})
end

munge do |value|
if value.to_i.to_s == value
value.to_i
elsif value.to_f.to_s == value
value.to_f
newproperty(:target) do
desc 'The path to postgresql.conf'
defaultto do
if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
@resource.class.defaultprovider.default_target
else
value
nil
end
end
end

newproperty(:comment) do
desc 'The comment to set for this parameter.'
newvalues(%r{^[\w\W]+$})
end

newparam(:target) do
desc 'The path to the postgresql config file'
newvalues(%r{^/\S+[a-z0-9(/)-]*\w+.conf$})
end
end
13 changes: 5 additions & 8 deletions manifests/server/config_entry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
# @param key Defines the key/name for the setting. Defaults to $name
# @param value Defines the value for the setting.
# @param path Path for postgresql.conf
# @param comment Defines the comment for the setting. The # is added by default.
#
define postgresql::server::config_entry (
Enum['present', 'absent'] $ensure = 'present',
String[1] $key = $name,
Optional[Variant[String[1], Numeric, Array[String[1]]]] $value = undef,
Stdlib::Absolutepath $path = $postgresql::server::postgresql_conf_path,
Optional[String[1]] $comment = undef,
Enum['present', 'absent'] $ensure = 'present',
String[1] $key = $name,
Optional[Variant[String[1], Numeric, Array[String[1]]]] $value = undef,
Stdlib::Absolutepath $path = $postgresql::server::postgresql_conf_path
) {
# Those are the variables that are marked as "(change requires restart)"
# on postgresql.conf. Items are ordered as on postgresql.conf.
Expand Down Expand Up @@ -87,9 +85,8 @@
postgresql_conf { $name:
ensure => $ensure,
target => $path,
key => $key,
name => $key,
value => $value,
comment => $comment,
require => Class['postgresql::server::initdb'],
}
}
Loading

0 comments on commit d4054b4

Please sign in to comment.