Skip to content

Finish conversion of postgresql_acls_to_resources_hash function #1163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 64 additions & 101 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ _Private Classes_

**Functions**

_Public Functions_

* [`postgresql::default`](#postgresqldefault): This function pull default values from the `params` class or `globals` class if the value is not present in `params`.
* [`postgresql::postgresql_acls_to_resources_hash`](#postgresqlpostgresql_acls_to_resources_hash): This internal function translates the ipv(4|6)acls format into a resource
* [`postgresql::postgresql_escape`](#postgresqlpostgresql_escape): This function safely escapes a string using a consistent random tag
* [`postgresql::postgresql_password`](#postgresqlpostgresql_password): This function returns the postgresql password hash from the clear text username / password
* [`postgresql_acls_to_resources_hash`](#postgresql_acls_to_resources_hash): This internal function translates the ipv(4|6)acls format into a resource suitable for create_resources. It is not intended to be used outsid
* [`postgresql_escape`](#postgresql_escape): This function safely escapes a string using a consistent random tag
* [`postgresql_password`](#postgresql_password): This function returns the postgresql password hash from the clear text username / password

_Private Functions_

* `postgresql::postgresql_acls_to_resources_hash`: This internal function translates the ipv(4|6)acls format into a resource suitable for create_resources.

**Tasks**

* [`sql`](#sql): Allows you to execute arbitary SQL
Expand Down Expand Up @@ -842,15 +846,15 @@ Default value: $postgresql::params::ip_mask_allow_all_users

##### `ipv4acls`

Data type: `Any`
Data type: `Array[String[1]]`

Lists strings for access control for connection method, users, databases, IPv4 addresses;

Default value: $postgresql::params::ipv4acls

##### `ipv6acls`

Data type: `Any`
Data type: `Array[String[1]]`

Lists strings for access control for connection method, users, databases, IPv6 addresses.

Expand Down Expand Up @@ -1097,6 +1101,14 @@ Sets PostgreSQL version

Default value: `undef`

##### `extra_systemd_config`

Data type: `Any`

Adds extra config to systemd config file, can for instance be used to add extra openfiles. This can be a multi line string

Default value: $postgresql::params::extra_systemd_config

##### `manage_selinux`

Data type: `Boolean`
Expand Down Expand Up @@ -1667,6 +1679,22 @@ Specifies whether to grant or revoke the privilege. Default is to grant the priv

Default value: 'present'

##### `group`

Data type: `String`

Sets the OS group to run psql

Default value: $postgresql::server::group

##### `psql_path`

Data type: `String`

Sets the path to psql command

Default value: $postgresql::server::psql_path

##### `object_arguments`

Data type: `Array[String[1],0]`
Expand Down Expand Up @@ -2181,6 +2209,38 @@ Specify whether to create or drop the role. Specifying 'present' creates the rol

Default value: 'present'

##### `psql_user`

Data type: `Any`

Sets the OS user to run psql

Default value: $postgresql::server::user

##### `psql_group`

Data type: `Any`

Sets the OS group to run psql

Default value: $postgresql::server::group

##### `psql_path`

Data type: `Any`

Sets path to psql command

Default value: $postgresql::server::psql_path

##### `module_workdir`

Data type: `Any`

Specifies working directory under which the psql command should be executed. May need to specify if '/tmp' is on volume mounted with noexec option.

Default value: $postgresql::server::module_workdir

### postgresql::server::schema

Create a new schema.
Expand Down Expand Up @@ -2723,69 +2783,6 @@ Data type: `String`



### postgresql::postgresql_acls_to_resources_hash

Type: Ruby 4.x API

This is an autogenerated function, ported from the original legacy version.
It /should work/ as is, but will not have all the benefits of the modern
function API. You should see the function docs to learn how to add function
signatures for type safety and to document this function using puppet-strings.

https://puppet.com/docs/puppet/latest/custom_functions_ruby.html

---- original file header ----
postgresql_acls_to_resources_hash.rb
---- original file header ----

suitable for create_resources. It is not intended to be used outside of the
postgresql internal classes/defined resources.

@return This function accepts an array of strings that are pg_hba.conf rules. It
will return a hash that can be fed into create_resources to create multiple
individual pg_hba_rule resources.

The second parameter is an identifier that will be included in the namevar
to provide uniqueness. It must be a string.

The third parameter is an order offset, so you can start the order at an
arbitrary starting point.

#### `postgresql::postgresql_acls_to_resources_hash(Any *$args)`

This is an autogenerated function, ported from the original legacy version.
It /should work/ as is, but will not have all the benefits of the modern
function API. You should see the function docs to learn how to add function
signatures for type safety and to document this function using puppet-strings.

https://puppet.com/docs/puppet/latest/custom_functions_ruby.html

---- original file header ----
postgresql_acls_to_resources_hash.rb
---- original file header ----

suitable for create_resources. It is not intended to be used outside of the
postgresql internal classes/defined resources.

@return This function accepts an array of strings that are pg_hba.conf rules. It
will return a hash that can be fed into create_resources to create multiple
individual pg_hba_rule resources.

The second parameter is an identifier that will be included in the namevar
to provide uniqueness. It must be a string.

The third parameter is an order offset, so you can start the order at an
arbitrary starting point.

Returns: `Data type` Describe what the function returns here

##### `*args`

Data type: `Any`

The original array of arguments. Port this to individually managed params
to get the full benefit of the modern function API.

### postgresql::postgresql_escape

Type: Ruby 4.x API
Expand Down Expand Up @@ -2836,40 +2833,6 @@ Data type: `Any`
The original array of arguments. Port this to individually managed params
to get the full benefit of the modern function API.

### postgresql_acls_to_resources_hash

Type: Ruby 3.x API

This internal function translates the ipv(4|6)acls format into a resource
suitable for create_resources. It is not intended to be used outside of the
postgresql internal classes/defined resources.

will return a hash that can be fed into create_resources to create multiple
individual pg_hba_rule resources.

The second parameter is an identifier that will be included in the namevar
to provide uniqueness. It must be a string.

The third parameter is an order offset, so you can start the order at an
arbitrary starting point.

#### `postgresql_acls_to_resources_hash()`

This internal function translates the ipv(4|6)acls format into a resource
suitable for create_resources. It is not intended to be used outside of the
postgresql internal classes/defined resources.

will return a hash that can be fed into create_resources to create multiple
individual pg_hba_rule resources.

The second parameter is an identifier that will be included in the namevar
to provide uniqueness. It must be a string.

The third parameter is an order offset, so you can start the order at an
arbitrary starting point.

Returns: `Any` This function accepts an array of strings that are pg_hba.conf rules. It

### postgresql_escape

Type: Ruby 3.x API
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,38 @@
# This is an autogenerated function, ported from the original legacy version.
# It /should work/ as is, but will not have all the benefits of the modern
# function API. You should see the function docs to learn how to add function
# signatures for type safety and to document this function using puppet-strings.
#
# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html
#
# ---- original file header ----
# postgresql_acls_to_resources_hash.rb
# ---- original file header ----
#
# @summary
# This internal function translates the ipv(4|6)acls format into a resource
# suitable for create_resources. It is not intended to be used outside of the
# postgresql internal classes/defined resources.
#
# @return This function accepts an array of strings that are pg_hba.conf rules. It
# will return a hash that can be fed into create_resources to create multiple
# individual pg_hba_rule resources.
#
# The second parameter is an identifier that will be included in the namevar
# to provide uniqueness. It must be a string.
#
# The third parameter is an order offset, so you can start the order at an
# arbitrary starting point.
#
#
# @summary This internal function translates the ipv(4|6)acls format into a resource suitable for create_resources.
# @api private
Puppet::Functions.create_function(:'postgresql::postgresql_acls_to_resources_hash') do
# @param args
# The original array of arguments. Port this to individually managed params
# to get the full benefit of the modern function API.
#
# @return [Data type]
# Describe what the function returns here
# @param acls
# An array of strings that are pg_hba.conf rules.
# @param id
# An identifier that will be included in the namevar to provide uniqueness.
# @param offset
# An order offset, so you can start the order at an arbitrary starting point.
#
# @return [Hash]
# A hash that can be fed into create_resources to create multiple individual pg_hba_rule resources.
dispatch :default_impl do
# Call the method named 'default_impl' when this is matched
# Port this to match individual params for better type safety
repeated_param 'Any', :args
param 'Array[String]', :acls
param 'String[1]', :id
param 'Integer[0]', :offset
end

def default_impl(*args)
func_name = 'postgresql_acls_to_resources_hash()'

if args.size != 3
raise(Puppet::ParseError, "#{func_name}: Wrong number of arguments " \
"given (#{args.size} for 3)")
end

acls = args[0]
raise(Puppet::ParseError, "#{func_name}: first argument must be an array") \
unless acls.instance_of? Array

id = args[1]
raise(Puppet::ParseError, "#{func_name}: second argument must be a string") \
unless id.instance_of? String

offset = args[2].to_i
raise(Puppet::ParseError, "#{func_name}: third argument must be a number") \
unless offset.is_a? Integer

def default_impl(acls, id, offset)
resources = {}
acls.each do |acl|
index = acls.index(acl)

parts = acl.split

unless parts.length >= 4
raise(Puppet::ParseError, "#{func_name}: acl line #{index} does not " \
raise(Puppet::ParseError, "postgresql::postgresql_acls_to_resources_hash(): acl line #{index} does not " \
'have enough parts')
end

resource = {
'type' => parts[0],
'type' => parts[0],
'database' => parts[1],
'user' => parts[2],
'order' => format('%03d', offset + index), # rubocop:disable Style/FormatString
'user' => parts[2],
'order' => '%03d' % (offset + index),
}
if parts[0] == 'local'
resource['auth_method'] = parts[3]
Expand Down
Loading