diff --git a/REFERENCE.md b/REFERENCE.md index 42b24d6..979c1ea 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1437,6 +1437,8 @@ The following parameters are available in the `knot::domain` defined type: * [`zone_csync`](#-knot--domain--zone_csync) * [`zone_subzones`](#-knot--domain--zone_subzones) * [`local_subzones`](#-knot--domain--local_subzones) +* [`catalog_entries`](#-knot--domain--catalog_entries) +* [`catalog_salt`](#-knot--domain--catalog_salt) ##### `ensure` @@ -2047,6 +2049,33 @@ remark: only relevant if $manage_zone set to true Default value: `[]` +##### `catalog_entries` + +Data type: `Hash[String[1],String[1]]` + +if this domain is a catalog zone, this parameter let's you simplify +adding zone records to it. +example: + { myzone.org => mygroup } +ends up in records like: + _unique-id.zones 0 IN PTR myzone.org + group._unique-id.zones 0 IN TXT "mygroup" +remark: only relevant if $manage_zone set to true + +Default value: `{}` + +##### `catalog_salt` + +Data type: `String[1]` + +to generate the _unique-id of the catalog entries, the md5sum of +the zone, the group and this salt is used +per rfc, if the unique-id changes, the zone has to be deleted and +newly rebuild. Changing this salt lets you force a reload. +defaults to fqdn which result in a reload if name changes ! + +Default value: `$facts['networking']['fqdn']` + ### `knot::records::caa` default values can be configured in the class diff --git a/manifests/domain.pp b/manifests/domain.pp index 9171f24..793e860 100644 --- a/manifests/domain.pp +++ b/manifests/domain.pp @@ -193,6 +193,21 @@ # - manage_zone is set to true for both domains # Any violation of above restrictions is ignored. # remark: only relevant if $manage_zone set to true +# @param catalog_entries +# if this domain is a catalog zone, this parameter let's you simplify +# adding zone records to it. +# example: +# { myzone.org => mygroup } +# ends up in records like: +# _unique-id.zones 0 IN PTR myzone.org +# group._unique-id.zones 0 IN TXT "mygroup" +# remark: only relevant if $manage_zone set to true +# @param catalog_salt +# to generate the _unique-id of the catalog entries, the md5sum of +# the zone, the group and this salt is used +# per rfc, if the unique-id changes, the zone has to be deleted and +# newly rebuild. Changing this salt lets you force a reload. +# defaults to fqdn which result in a reload if name changes ! # define knot::domain ( Enum['absent', 'present'] $ensure = 'present', @@ -265,6 +280,8 @@ Optional[Knot::Record::Csync] $zone_csync = undef, Hash[String[1],Knot::Subzone] $zone_subzones = {}, Array[String[1]] $local_subzones = [], + Hash[String[1],String[1]] $catalog_entries = {}, + String[1] $catalog_salt = $facts['networking']['fqdn'], ) { knot::add_conf { $domain: ensure => $ensure, @@ -408,4 +425,21 @@ } } } + $catalog_entries.each | String[1] $z, String[1] $gr | { + $unique_id = md5([$z,$gr,$catalog_salt].join(':')) + knot_record { "Catalog for ${z} (${gr})": + target_zone => $domain, + rname => "${unique_id}.zones", + rtype => 'PTR', + rttl => 0, + rcontent => "${z}.", + } + knot_record { "Catalog group for ${z} (${gr})": + target_zone => $domain, + rname => "group.${unique_id}.zones", + rtype => 'TXT', + rttl => 0, + rcontent => "\"${gr}\"", + } + } } diff --git a/spec/defines/domain_spec.rb b/spec/defines/domain_spec.rb index cbea938..ecf2d24 100644 --- a/spec/defines/domain_spec.rb +++ b/spec/defines/domain_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'spec_helper' +require 'digest' describe 'knot::domain' do let :default_params do @@ -11,7 +12,8 @@ zone_serial_policy: 'increment', zone_nameservers: [], zone_subzones: {}, - local_subzones: [] } + local_subzones: [], + catalog_entries: {}, } end shared_examples 'knot::domain shared examples' do @@ -80,7 +82,22 @@ .with_rttl(params[:zone_nameservers_ttl]) .with_rcontent("#{params[:zone_csync][:serial]} #{params[:zone_csync][:flags]} #{params[:zone_csync][:value]}") end - else + params[:catalog_entries].each do |z, g| + uniqueid = Digest::MD5.hexdigest([z, g, params[:catalog_salt]].join(':')) + is_expected.to contain_knot_record("Catalog for #{z} (#{g})") + .with_target_zone(params[:domain]) + .with_rname("#{uniqueid}.zones") + .with_rtype('PTR') + .with_rttl(0) + .with_rcontent("#{z}.") + is_expected.to contain_knot_record("Catalog group for #{z} (#{g})") + .with_target_zone(params[:domain]) + .with_rname("group.#{uniqueid}.zones") + .with_rtype('TXT') + .with_rttl(0) + .with_rcontent("\"#{g}\"") + end + else # params[:ensure] != 'present' params[:zone_records].each do |r| is_expected.not_to contain_knot_record("record #{r[:rname]}.#{params[:domain]} (#{i})") end @@ -167,6 +184,20 @@ it_behaves_like 'knot::domain shared examples' end + + context 'with a catalog zone' do + let(:title) { 'testdomain' } + let :params do + default_params.merge({ domain: 'catalog.zone', + manage_zone: true, + zone_records: [{ rname: 'verision', rtype: 'TXT', rcontent: '2' }], + zone_nameservers: ['ns1.example.org.'], + catalog_entries: { 'example.org' => 'secondary' }, + catalog_salt: '42' }) + end + + it_behaves_like 'knot::domain shared examples' + end end end end