Skip to content

Commit

Permalink
server::database_grant: Always set default user/group/port
Browse files Browse the repository at this point in the history
This enables us to make it configureable. When a user doesn't specify
it, the defaults will be passed, without breaking existing behaviour.
  • Loading branch information
bastelfreak committed Aug 31, 2023
1 parent 26b2555 commit 6232171
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
24 changes: 21 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1543,11 +1543,11 @@ Default value: `undef`

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

Data type: `Variant[Boolean, String[1]]`
Data type: `Stdlib::Absolutepath`

Path for postgresql.conf

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

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

Expand Down Expand Up @@ -1653,7 +1653,9 @@ The following parameters are available in the `postgresql::server::database_gran
* [`ensure`](#-postgresql--server--database_grant--ensure)
* [`psql_db`](#-postgresql--server--database_grant--psql_db)
* [`psql_user`](#-postgresql--server--database_grant--psql_user)
* [`psql_group`](#-postgresql--server--database_grant--psql_group)
* [`connect_settings`](#-postgresql--server--database_grant--connect_settings)
* [`port`](#-postgresql--server--database_grant--port)

##### <a name="-postgresql--server--database_grant--privilege"></a>`privilege`

Expand Down Expand Up @@ -1695,7 +1697,15 @@ Data type: `Optional[String[1]]`

Specifies the OS user for running psql. Default value: The default user for the module, usually 'postgres'.

Default value: `undef`
Default value: `$postgresql::server::user`

##### <a name="-postgresql--server--database_grant--psql_group"></a>`psql_group`

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

Overrides the default postgres user group to be used for related files in the file system.

Default value: `$postgresql::params::group`

##### <a name="-postgresql--server--database_grant--connect_settings"></a>`connect_settings`

Expand All @@ -1705,6 +1715,14 @@ Specifies a hash of environment variables used when connecting to a remote serve

Default value: `undef`

##### <a name="-postgresql--server--database_grant--port"></a>`port`

Data type: `Stdlib::Port`

Port to use when connecting.

Default value: `$postgresql::server::port`

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

Define for conveniently creating a role, database and assigning the correctpermissions.
Expand Down
8 changes: 7 additions & 1 deletion manifests/server/database_grant.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
# @param ensure Specifies whether to grant or revoke the privilege. Revoke or 'absent' works only in PostgreSQL version 9.1.24 or later.
# @param psql_db Defines the database to execute the grant against. This should not ordinarily be changed from the default
# @param psql_user Specifies the OS user for running psql. Default value: The default user for the module, usually 'postgres'.
# @param psql_group Overrides the default postgres user group to be used for related files in the file system.
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
# @param port Port to use when connecting.
define postgresql::server::database_grant (
Enum['ALL', 'CREATE', 'CONNECT', 'TEMPORARY', 'TEMP', 'all', 'create', 'connect', 'temporary', 'temp'] $privilege,
String[1] $db,
String[1] $role,
Optional[Enum['present', 'absent']] $ensure = undef,
Optional[String[1]] $psql_db = undef,
Optional[String[1]] $psql_user = undef,
String[1] $psql_user = $postgresql::server::user,
String[1] $psql_group = $postgresql::server::group,
Optional[Hash] $connect_settings = undef,
Stdlib::Port $port = $postgresql::server::port,
) {
postgresql::server::grant { "database:${name}":
ensure => $ensure,
Expand All @@ -25,6 +29,8 @@
object_name => $db,
psql_db => $psql_db,
psql_user => $psql_user,
group => $psql_group,
port => $port,
connect_settings => $connect_settings,
}
}
37 changes: 27 additions & 10 deletions spec/defines/server/database_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,35 @@
'test'
end

let :params do
{
privilege: 'ALL',
db: 'test',
role: 'test'
}
end

let :pre_condition do
"class {'postgresql::server':}"
end

it { is_expected.to contain_postgresql__server__database_grant('test') }
it { is_expected.to contain_postgresql__server__grant('database:test') }
context 'with minimal settings' do
let :params do
{
privilege: 'ALL',
db: 'test',
role: 'test'
}
end

Check failure on line 23 in spec/defines/server/database_grant_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

RSpec/EmptyLineAfterFinalLet: Add an empty line after the last `let`. (https://rspec.rubystyle.guide/#empty-line-after-let, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet)

Check failure on line 23 in spec/defines/server/database_grant_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

RSpec/EmptyLineAfterFinalLet: Add an empty line after the last `let`. (https://rspec.rubystyle.guide/#empty-line-after-let, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet)
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_postgresql__server__database_grant('test') }
it { is_expected.to contain_postgresql__server__grant('database:test').with_psql_user('postgres').with_port(5432).with_group('postgres') }
end

context 'with different user/group/port' do
let :params do
{
privilege: 'ALL',
db: 'test',
role: 'test',
psql_user: 'foo',
psql_group: 'bar',
port: 1337
}
end

Check failure on line 39 in spec/defines/server/database_grant_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

RSpec/EmptyLineAfterFinalLet: Add an empty line after the last `let`. (https://rspec.rubystyle.guide/#empty-line-after-let, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet)

Check failure on line 39 in spec/defines/server/database_grant_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

RSpec/EmptyLineAfterFinalLet: Add an empty line after the last `let`. (https://rspec.rubystyle.guide/#empty-line-after-let, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet)
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_postgresql__server__grant('database:test').with_psql_user('foo').with_port(1337).with_group('bar') }
end
end

0 comments on commit 6232171

Please sign in to comment.