Skip to content

Commit

Permalink
Merge pull request #142 from bastelfreak/password
Browse files Browse the repository at this point in the history
make gpgsql-password optional
  • Loading branch information
ju5t authored Dec 21, 2022
2 parents bff32a7 + a4c3742 commit e815917
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
14 changes: 8 additions & 6 deletions manifests/backends/mysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
type => 'authoritative',
}

powerdns::config { 'gmysql-password':
ensure => present,
setting => 'gmysql-password',
value => $::powerdns::db_password,
type => 'authoritative',
if $powerdns::db_password {
powerdns::config { 'gmysql-password':
ensure => present,
setting => 'gmysql-password',
value => $::powerdns::db_password,
type => 'authoritative',
}
}

powerdns::config { 'gmysql-dbname':
Expand Down Expand Up @@ -65,7 +67,7 @@
}
}

if $::powerdns::backend_create_tables {
if $::powerdns::backend_create_tables and $powerdns::db_password {
# make sure the database exists
mysql::db { $::powerdns::db_name:
user => $::powerdns::db_username,
Expand Down
12 changes: 7 additions & 5 deletions manifests/backends/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
type => 'authoritative',
}

powerdns::config { 'gpgsql-password':
ensure => present,
setting => 'gpgsql-password',
value => $::powerdns::db_password,
type => 'authoritative',
if $powerdns::db_password {
powerdns::config { 'gpgsql-password':
ensure => present,
setting => 'gpgsql-password',
value => $::powerdns::db_password,
type => 'authoritative',
}
}

powerdns::config { 'gpgsql-dbname':
Expand Down
8 changes: 7 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Integer[1] $db_port = 3306,
String[1] $db_dir = $::powerdns::params::db_dir,
String[1] $db_file = $::powerdns::params::db_file,
Boolean $require_db_password = true,
String[1] $ldap_host = 'ldap://localhost/',
Optional[String[1]] $ldap_basedn = undef,
String[1] $ldap_method = 'strict',
Expand All @@ -27,7 +28,7 @@
) inherits powerdns::params {
# Do some additional checks. In certain cases, some parameters are no longer optional.
if $authoritative {
if ($::powerdns::backend != 'bind') and ($::powerdns::backend != 'ldap') and ($::powerdns::backend != 'sqlite') {
if ($::powerdns::backend != 'bind') and ($::powerdns::backend != 'ldap') and ($::powerdns::backend != 'sqlite') and $require_db_password {
assert_type(String[1], $db_password) |$expected, $actual| {
fail("'db_password' must be a non-empty string when 'authoritative' == true")
}
Expand All @@ -37,6 +38,11 @@
}
}
}
if $backend_create_tables and $backend == 'mysql' {
assert_type(String[1], $db_root_password) |$expected, $actual| {
fail("On MySQL 'db_root_password' must be a non-empty string when 'backend_create_tables' == true")
}
}
}

# Include the required classes
Expand Down
38 changes: 38 additions & 0 deletions spec/classes/powerdns_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,44 @@
}
end

context 'powerdns class with require_db_password at false' do
let :params do
{
require_db_password: false
}
end

it {
is_expected.to raise_error(
%r{On MySQL 'db_root_password' must be a non-empty string when 'backend_create_tables' == true},
)
}
end

context 'powerdns class with require_db_password at false and backend postgresql' do
let :params do
{
require_db_password: false,
backend: 'postgresql'
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_powerdns__config('gpgsql-password') }
end

context 'powerdns class with require_db_password at false and backend_create_tables at false' do
let :params do
{
require_db_password: false,
backend_create_tables: false
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_powerdns__config('gmysql-password') }
end

context 'powerdns class with parameters' do
let(:params) do
{
Expand Down

0 comments on commit e815917

Please sign in to comment.