Skip to content
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

Drop database backends for the PowerDNS plugin #542

Merged
merged 1 commit into from
Jan 13, 2020
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
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,18 @@ class{'::foreman_proxy':
}
```

### PowerDNS support
### DNS plugin support

To use the PowerDNS plugin, the following variables need to be set on the main
`foreman_proxy` class.
To use the a DNS plugin, the following variables need to be set on the main `foreman_proxy` class. Be sure to correct the `dns_provider` to your actual provider.

```puppet
class{'::foreman_proxy':
class { 'foreman_proxy':
dns => true,
dns_provider => 'powerdns',
}
```

Then you also need to include `foreman_proxy::plugin::dns::powerdns`.

The powerdns plugin can optionally manage the database. If that's used, then
the puppetlabs-mysql module must be added to the modulepath, otherwise it's not
required.
Then you also need to include the appropriate class, such as `foreman_proxy::plugin::dns::powerdns`.

### Remote Execution User Management

Expand Down
60 changes: 8 additions & 52 deletions manifests/plugin/dns/powerdns.pp
Original file line number Diff line number Diff line change
@@ -1,59 +1,15 @@
# = Foreman Proxy PowerDNS DNS plugin
# @summary Install the PowerDNS DNS plugin for Foreman proxy
#
# This class installs the PowerDNS DNS plugin for Foreman proxy
# @param rest_url
# The REST API URL
#
# === Parameters:
#
# $backend:: The backend to select, either mysql or postgresql.
#
# $pdnssec:: pdnssec command to run rectify-zone with. Can be an
# empty string.
#
# === MySQL parameters:
#
# $manage_database:: Whether to manage the database. Only works for
# mysql. Includes the mysql server.
#
# $mysql_hostname:: MySQL server hostname. Only used when the backend is mysql.
#
# $mysql_username:: MySQL server username. Only used when the backend is mysql.
#
# $mysql_password:: MySQL server password. Only used when the backend is mysql.
#
# $mysql_database:: MySQL server database. Only used when the backend is mysql.
#
# === PostgreSQL parameters:
#
# $postgresql_connection:: The postgresql connection string.
#
# === REST parameters:
#
# $rest_url:: The REST API URL
#
# $rest_api_key:: The REST API key
# @param rest_api_key
# The REST API key
#
class foreman_proxy::plugin::dns::powerdns (
Enum['rest', 'mysql', 'postgresql'] $backend = $::foreman_proxy::plugin::dns::powerdns::params::backend,
String $mysql_hostname = $::foreman_proxy::plugin::dns::powerdns::params::mysql_hostname,
String $mysql_username = $::foreman_proxy::plugin::dns::powerdns::params::mysql_username,
String $mysql_password = $::foreman_proxy::plugin::dns::powerdns::params::mysql_password,
String $mysql_database = $::foreman_proxy::plugin::dns::powerdns::params::mysql_database,
String $postgresql_connection = $::foreman_proxy::plugin::dns::powerdns::params::postgresql_connection,
Stdlib::HTTPUrl $rest_url = $::foreman_proxy::plugin::dns::powerdns::params::rest_url,
String $rest_api_key = $::foreman_proxy::plugin::dns::powerdns::params::rest_api_key,
Boolean $manage_database = $::foreman_proxy::plugin::dns::powerdns::params::manage_database,
String $pdnssec = $::foreman_proxy::plugin::dns::powerdns::params::pdnssec,
) inherits foreman_proxy::plugin::dns::powerdns::params {
if $manage_database and $backend == 'mysql' {
include ::mysql::server
mysql::db { $mysql_database:
user => $mysql_username,
password => $mysql_password,
host => $mysql_hostname,
grant => ['ALL'],
}
}

Stdlib::HTTPUrl $rest_url = 'http://localhost:8081/api/v1/servers/localhost',
String $rest_api_key = '', # lint:ignore:empty_string_assignment
) {
foreman_proxy::plugin { 'dns_powerdns':
}
-> foreman_proxy::settings_file { 'dns_powerdns':
Expand Down
14 changes: 0 additions & 14 deletions manifests/plugin/dns/powerdns/params.pp

This file was deleted.

90 changes: 3 additions & 87 deletions spec/classes/foreman_proxy__plugin__dns__powerdns_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,6 @@
let(:pre_condition) { 'include foreman_proxy' }

context 'default parameters' do
let :params do
{
:mysql_password => 'password',
}
end

it { should compile.with_all_deps }

it 'should install the correct plugin' do
should contain_foreman_proxy__plugin('dns_powerdns')
end

it 'should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/dns_powerdns.yml', [
'---',
':powerdns_backend: "mysql"',
':powerdns_mysql_hostname: "localhost"',
':powerdns_mysql_username: "pdns"',
':powerdns_mysql_password: "password"',
':powerdns_mysql_database: "pdns"',
':powerdns_pdnssec: "pdnssec"',
])
end
end

context 'with manage_database => true' do
let :params do
{
:mysql_password => 'password',
:manage_database => true,
}
end

it { should compile.with_all_deps }

it 'should install the correct plugin' do
should contain_foreman_proxy__plugin('dns_powerdns')
end

it 'should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/dns_powerdns.yml', [
'---',
':powerdns_backend: "mysql"',
':powerdns_mysql_hostname: "localhost"',
':powerdns_mysql_username: "pdns"',
':powerdns_mysql_password: "password"',
':powerdns_mysql_database: "pdns"',
':powerdns_pdnssec: "pdnssec"',
])
end

it 'should manage the database' do
should contain_class('mysql::server')

should contain_mysql__db('pdns') \
.with_user('pdns') \
.with_password('password') \
.with_host('localhost') \
.with_grant(['ALL'])
end
end

context 'with backend postgresql' do
let :params do
{
:backend => 'postgresql',
:postgresql_connection => 'user=pdns',
:manage_database => true,
}
end

it { should compile.with_all_deps }

it 'should install the correct plugin' do
Expand All @@ -87,22 +16,15 @@
it 'should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/dns_powerdns.yml', [
'---',
':powerdns_backend: "postgresql"',
':powerdns_postgresql_connection: "user=pdns"',
':powerdns_pdnssec: "pdnssec"',
':powerdns_rest_url: "http://localhost:8081/api/v1/servers/localhost"',
':powerdns_rest_api_key: ""',
])
end

it 'should not manage the database' do
should_not contain_class('mysql::server')
should_not contain_mysql__db('pdns')
end
end

context 'with backend rest' do
context 'explicit parameters' do
let :params do
{
:backend => 'rest',
:rest_url => 'http://localhost/api',
:rest_api_key => 'changeme',
}
Expand All @@ -117,16 +39,10 @@
it 'should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/dns_powerdns.yml', [
'---',
':powerdns_backend: "rest"',
':powerdns_rest_url: "http://localhost/api"',
':powerdns_rest_api_key: "changeme"',
])
end

it 'should not manage the database' do
should_not contain_class('mysql::server')
should_not contain_mysql__db('pdns')
end
end
end
end
Expand Down
18 changes: 2 additions & 16 deletions templates/plugin/dns_powerdns.yml.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
---
<% backend = scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::backend') -%>
:powerdns_backend: "<%= backend %>"
<% if backend == 'mysql' -%>
:powerdns_mysql_hostname: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_hostname') %>"
:powerdns_mysql_username: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_username') %>"
:powerdns_mysql_password: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_password') %>"
:powerdns_mysql_database: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_database') %>"
<% elsif backend == 'postgresql' -%>
:powerdns_postgresql_connection: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::postgresql_connection') %>"
<% elsif backend == 'rest' -%>
:powerdns_rest_url: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::rest_url') %>"
:powerdns_rest_api_key: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::rest_api_key') %>"
<% end -%>
<% if ['mysql', 'postgresql'].include?(backend) -%>
:powerdns_pdnssec: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::pdnssec') %>"
<% end -%>
:powerdns_rest_url: "<%= scope.lookupvar('foreman_proxy::plugin::dns::powerdns::rest_url') %>"
:powerdns_rest_api_key: "<%= scope.lookupvar('foreman_proxy::plugin::dns::powerdns::rest_api_key') %>"