Skip to content

Commit

Permalink
Add omapi_name, key, algorithm parameters
Browse files Browse the repository at this point in the history
Creates a new key section for configuring access to the OMAPI service.

Fixes voxpupuli#90
  • Loading branch information
domcleal committed Mar 3, 2017
1 parent 0dffb40 commit 4a55dc0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ The following is the list of all parameters available for this class.
| `nameservers` | Array | `[ '8.8.8.8', '8.8.4.4' ]` |
| `nameservers_ipv6` | Array | `[]` |
| `ntpservers` | Array | `[]` |
| `omapi_algorithm` | String | `HMAC-MD5` |
| `omapi_key` | String | `undef` |
| `omapi_name` | String | `undef` |
| `omapi_port` | Integer | `undef` |
| `option_code150_label` | String | `pxegrub` |
| `option_code150_value` | String | `text` |
Expand Down
11 changes: 10 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
$max_lease_time = 86400,
$service_ensure = running,
$globaloptions = '',
$omapi_port = undef,
Optional[Integer[0,65535]] $omapi_port = undef,
Optional[String] $omapi_name = undef,
String $omapi_algorithm = 'HMAC-MD5',
Optional[String] $omapi_key = undef,
$authoritative = true,
$extra_config = '',
$dhcp_dir = $dhcp::params::dhcp_dir,
Expand Down Expand Up @@ -82,6 +85,12 @@
validate_integer($mtu)
}

if $omapi_name or $omapi_key {
if !$omapi_port or ! $omapi_name or ! $omapi_key or ! $omapi_algorithm {
fail('$omapi_port, $omapi_name, $omapi_key and $omapi_algorithm are required when defining an OMAPI key')
}
}

# Incase people set interface instead of interfaces work around
# that. If they set both, use interfaces and the user is a unwise
# and deserves what they get.
Expand Down
24 changes: 22 additions & 2 deletions spec/classes/dhcp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,28 @@
)
end

it 'defines dhcp header contents' do
is_expected.to contain_concat__fragment('dhcp-conf-header')
it 'sets omapi-port' do
is_expected.to contain_concat__fragment('dhcp-conf-header').with_content(%r{^omapi-port 7911;})
end

context 'and omapi_name, omapi_key' do
let :params do
default_params.merge(
interfaces: ['eth0'],
omapi_port: 7911,
omapi_name: 'keyname',
omapi_key: 'keyvalue'
)
end

it 'adds key section' do
is_expected.to contain_concat__fragment('dhcp-conf-header').with_content(%r{^key keyname \{})
is_expected.to contain_concat__fragment('dhcp-conf-header').with_content(%r{^\s*algorithm HMAC-MD5;})
end

it 'sets key secret' do
is_expected.to contain_concat__fragment('dhcp-conf-header').with_content(%r{^\s*secret "keyvalue";})
end
end
end

Expand Down
7 changes: 7 additions & 0 deletions templates/dhcpd.conf-header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ not authoritative;
<% end -%>
<% if @omapi_port -%>
omapi-port <%= @omapi_port %>;
<% if @omapi_name && @omapi_key -%>
key <%= @omapi_name %> {
algorithm <%= @omapi_algorithm %>;
secret "<%= @omapi_key %>";
}
omapi-key <%= @omapi_name %>;
<% end -%>
<% end -%>
default-lease-time <%= @default_lease_time %>;
max-lease-time <%= @max_lease_time %>;
Expand Down

0 comments on commit 4a55dc0

Please sign in to comment.