Skip to content

Commit b82db53

Browse files
committed
Finish conversion of postgresql_acls_to_resources_hash function
In puppetlabs#1129 the 3 functions from this module were ported to the modern function API and namespaced. None of the boilerplate was fixed up, tests weren't updated, documentation wasn't updated etc. This commit finishes the work for the `postgresql_acls_to_resources_hash` function. The existing function documentation made it pretty clear that this function is for internal use only. As such, I've marked it `@api private` and haven't created a non-namespaced shim (like I've being doing with the other functions in this module).
1 parent 3293067 commit b82db53

File tree

6 files changed

+224
-362
lines changed

6 files changed

+224
-362
lines changed

REFERENCE.md

Lines changed: 62 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,18 @@ _Private Classes_
6161

6262
**Functions**
6363

64+
_Public Functions_
65+
6466
* [`postgresql::default`](#postgresqldefault): This function pull default values from the `params` class or `globals` class if the value is not present in `params`.
65-
* [`postgresql::postgresql_acls_to_resources_hash`](#postgresqlpostgresql_acls_to_resources_hash): This internal function translates the ipv(4|6)acls format into a resource
6667
* [`postgresql::postgresql_escape`](#postgresqlpostgresql_escape): This function safely escapes a string using a consistent random tag
6768
* [`postgresql::postgresql_password`](#postgresqlpostgresql_password): This function returns the postgresql password hash from the clear text username / password
68-
* [`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
6969
* [`postgresql_escape`](#postgresql_escape): This function safely escapes a string using a consistent random tag
7070
* [`postgresql_password`](#postgresql_password): This function returns the postgresql password hash from the clear text username / password
7171

72+
_Private Functions_
73+
74+
* `postgresql::postgresql_acls_to_resources_hash`: This internal function translates the ipv(4|6)acls format into a resource suitable for create_resources.
75+
7276
**Tasks**
7377

7478
* [`sql`](#sql): Allows you to execute arbitary SQL
@@ -1097,6 +1101,14 @@ Sets PostgreSQL version
10971101

10981102
Default value: `undef`
10991103

1104+
##### `extra_systemd_config`
1105+
1106+
Data type: `Any`
1107+
1108+
Adds extra config to systemd config file, can for instance be used to add extra openfiles. This can be a multi line string
1109+
1110+
Default value: $postgresql::params::extra_systemd_config
1111+
11001112
##### `manage_selinux`
11011113

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

16681680
Default value: 'present'
16691681

1682+
##### `group`
1683+
1684+
Data type: `String`
1685+
1686+
Sets the OS group to run psql
1687+
1688+
Default value: $postgresql::server::group
1689+
1690+
##### `psql_path`
1691+
1692+
Data type: `String`
1693+
1694+
Sets the path to psql command
1695+
1696+
Default value: $postgresql::server::psql_path
1697+
16701698
##### `object_arguments`
16711699

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

21822210
Default value: 'present'
21832211

2212+
##### `psql_user`
2213+
2214+
Data type: `Any`
2215+
2216+
Sets the OS user to run psql
2217+
2218+
Default value: $postgresql::server::user
2219+
2220+
##### `psql_group`
2221+
2222+
Data type: `Any`
2223+
2224+
Sets the OS group to run psql
2225+
2226+
Default value: $postgresql::server::group
2227+
2228+
##### `psql_path`
2229+
2230+
Data type: `Any`
2231+
2232+
Sets path to psql command
2233+
2234+
Default value: $postgresql::server::psql_path
2235+
2236+
##### `module_workdir`
2237+
2238+
Data type: `Any`
2239+
2240+
Specifies working directory under which the psql command should be executed. May need to specify if '/tmp' is on volume mounted with noexec option.
2241+
2242+
Default value: $postgresql::server::module_workdir
2243+
21842244
### postgresql::server::schema
21852245

21862246
Create a new schema.
@@ -2723,69 +2783,6 @@ Data type: `String`
27232783

27242784

27252785

2726-
### postgresql::postgresql_acls_to_resources_hash
2727-
2728-
Type: Ruby 4.x API
2729-
2730-
This is an autogenerated function, ported from the original legacy version.
2731-
It /should work/ as is, but will not have all the benefits of the modern
2732-
function API. You should see the function docs to learn how to add function
2733-
signatures for type safety and to document this function using puppet-strings.
2734-
2735-
https://puppet.com/docs/puppet/latest/custom_functions_ruby.html
2736-
2737-
---- original file header ----
2738-
postgresql_acls_to_resources_hash.rb
2739-
---- original file header ----
2740-
2741-
suitable for create_resources. It is not intended to be used outside of the
2742-
postgresql internal classes/defined resources.
2743-
2744-
@return This function accepts an array of strings that are pg_hba.conf rules. It
2745-
will return a hash that can be fed into create_resources to create multiple
2746-
individual pg_hba_rule resources.
2747-
2748-
The second parameter is an identifier that will be included in the namevar
2749-
to provide uniqueness. It must be a string.
2750-
2751-
The third parameter is an order offset, so you can start the order at an
2752-
arbitrary starting point.
2753-
2754-
#### `postgresql::postgresql_acls_to_resources_hash(Any *$args)`
2755-
2756-
This is an autogenerated function, ported from the original legacy version.
2757-
It /should work/ as is, but will not have all the benefits of the modern
2758-
function API. You should see the function docs to learn how to add function
2759-
signatures for type safety and to document this function using puppet-strings.
2760-
2761-
https://puppet.com/docs/puppet/latest/custom_functions_ruby.html
2762-
2763-
---- original file header ----
2764-
postgresql_acls_to_resources_hash.rb
2765-
---- original file header ----
2766-
2767-
suitable for create_resources. It is not intended to be used outside of the
2768-
postgresql internal classes/defined resources.
2769-
2770-
@return This function accepts an array of strings that are pg_hba.conf rules. It
2771-
will return a hash that can be fed into create_resources to create multiple
2772-
individual pg_hba_rule resources.
2773-
2774-
The second parameter is an identifier that will be included in the namevar
2775-
to provide uniqueness. It must be a string.
2776-
2777-
The third parameter is an order offset, so you can start the order at an
2778-
arbitrary starting point.
2779-
2780-
Returns: `Data type` Describe what the function returns here
2781-
2782-
##### `*args`
2783-
2784-
Data type: `Any`
2785-
2786-
The original array of arguments. Port this to individually managed params
2787-
to get the full benefit of the modern function API.
2788-
27892786
### postgresql::postgresql_escape
27902787

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

2839-
### postgresql_acls_to_resources_hash
2840-
2841-
Type: Ruby 3.x API
2842-
2843-
This internal function translates the ipv(4|6)acls format into a resource
2844-
suitable for create_resources. It is not intended to be used outside of the
2845-
postgresql internal classes/defined resources.
2846-
2847-
will return a hash that can be fed into create_resources to create multiple
2848-
individual pg_hba_rule resources.
2849-
2850-
The second parameter is an identifier that will be included in the namevar
2851-
to provide uniqueness. It must be a string.
2852-
2853-
The third parameter is an order offset, so you can start the order at an
2854-
arbitrary starting point.
2855-
2856-
#### `postgresql_acls_to_resources_hash()`
2857-
2858-
This internal function translates the ipv(4|6)acls format into a resource
2859-
suitable for create_resources. It is not intended to be used outside of the
2860-
postgresql internal classes/defined resources.
2861-
2862-
will return a hash that can be fed into create_resources to create multiple
2863-
individual pg_hba_rule resources.
2864-
2865-
The second parameter is an identifier that will be included in the namevar
2866-
to provide uniqueness. It must be a string.
2867-
2868-
The third parameter is an order offset, so you can start the order at an
2869-
arbitrary starting point.
2870-
2871-
Returns: `Any` This function accepts an array of strings that are pg_hba.conf rules. It
2872-
28732836
### postgresql_escape
28742837

28752838
Type: Ruby 3.x API

lib/puppet/functions/postgresql/postgresql_acls_to_resources_hash.rb

Lines changed: 18 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,38 @@
1-
# This is an autogenerated function, ported from the original legacy version.
2-
# It /should work/ as is, but will not have all the benefits of the modern
3-
# function API. You should see the function docs to learn how to add function
4-
# signatures for type safety and to document this function using puppet-strings.
5-
#
6-
# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html
7-
#
8-
# ---- original file header ----
9-
# postgresql_acls_to_resources_hash.rb
10-
# ---- original file header ----
11-
#
12-
# @summary
13-
# This internal function translates the ipv(4|6)acls format into a resource
14-
# suitable for create_resources. It is not intended to be used outside of the
15-
# postgresql internal classes/defined resources.
16-
#
17-
# @return This function accepts an array of strings that are pg_hba.conf rules. It
18-
# will return a hash that can be fed into create_resources to create multiple
19-
# individual pg_hba_rule resources.
20-
#
21-
# The second parameter is an identifier that will be included in the namevar
22-
# to provide uniqueness. It must be a string.
23-
#
24-
# The third parameter is an order offset, so you can start the order at an
25-
# arbitrary starting point.
26-
#
27-
#
1+
# @summary This internal function translates the ipv(4|6)acls format into a resource suitable for create_resources.
2+
# @api private
283
Puppet::Functions.create_function(:'postgresql::postgresql_acls_to_resources_hash') do
29-
# @param args
30-
# The original array of arguments. Port this to individually managed params
31-
# to get the full benefit of the modern function API.
32-
#
33-
# @return [Data type]
34-
# Describe what the function returns here
4+
# @param acls
5+
# An array of strings that are pg_hba.conf rules.
6+
# @param id
7+
# An identifier that will be included in the namevar to provide uniqueness.
8+
# @param offset
9+
# An order offset, so you can start the order at an arbitrary starting point.
3510
#
11+
# @return [Hash]
12+
# A hash that can be fed into create_resources to create multiple individual pg_hba_rule resources.
3613
dispatch :default_impl do
37-
# Call the method named 'default_impl' when this is matched
38-
# Port this to match individual params for better type safety
39-
repeated_param 'Any', :args
14+
param 'Array[String]', :acls
15+
param 'String[1]', :id
16+
param 'Integer[0]', :offset
4017
end
4118

42-
def default_impl(*args)
43-
func_name = 'postgresql_acls_to_resources_hash()'
44-
45-
if args.size != 3
46-
raise(Puppet::ParseError, "#{func_name}: Wrong number of arguments " \
47-
"given (#{args.size} for 3)")
48-
end
49-
50-
acls = args[0]
51-
raise(Puppet::ParseError, "#{func_name}: first argument must be an array") \
52-
unless acls.instance_of? Array
53-
54-
id = args[1]
55-
raise(Puppet::ParseError, "#{func_name}: second argument must be a string") \
56-
unless id.instance_of? String
57-
58-
offset = args[2].to_i
59-
raise(Puppet::ParseError, "#{func_name}: third argument must be a number") \
60-
unless offset.is_a? Integer
61-
19+
def default_impl(acls, id, offset)
6220
resources = {}
6321
acls.each do |acl|
6422
index = acls.index(acl)
6523

6624
parts = acl.split
6725

6826
unless parts.length >= 4
69-
raise(Puppet::ParseError, "#{func_name}: acl line #{index} does not " \
27+
raise(Puppet::ParseError, "postgresql::postgresql_acls_to_resources_hash(): acl line #{index} does not " \
7028
'have enough parts')
7129
end
7230

7331
resource = {
74-
'type' => parts[0],
32+
'type' => parts[0],
7533
'database' => parts[1],
76-
'user' => parts[2],
77-
'order' => format('%03d', offset + index), # rubocop:disable Style/FormatString
34+
'user' => parts[2],
35+
'order' => '%03d' % (offset + index),
7836
}
7937
if parts[0] == 'local'
8038
resource['auth_method'] = parts[3]

lib/puppet/parser/functions/postgresql_acls_to_resources_hash.rb

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)