X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fpuppetmaster%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fgen_tlsa_entry.rb;h=0bf6bbafadfc12d5bc6fbff616bd587259724796;hb=4b4d9aa9c9b9081406b1083f85d7fc0e2d851a62;hp=11ca3e49f3bdeff2ab2fbaf1d0e565e57bb51f11;hpb=34fcd443020860dc3562eb8358fc2fc7e84a3258;p=mirror%2Fdsa-puppet.git diff --git a/modules/puppetmaster/lib/puppet/parser/functions/gen_tlsa_entry.rb b/modules/puppetmaster/lib/puppet/parser/functions/gen_tlsa_entry.rb index 11ca3e49f..0bf6bbafa 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/gen_tlsa_entry.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/gen_tlsa_entry.rb @@ -4,19 +4,31 @@ module Puppet::Parser::Functions hostname = args.shift() port = args.shift() - res = [] - if File.exist?(certfile) - cmd = ['swede', 'create', '--usage=3', '--selector=1', '--mtype=1', '--certificate', certfile, '--port', port.to_s, hostname] - IO.popen(cmd, "r") {|i| res << i.read } + if port.kind_of?(Array) + ports = port else - res << "; certfile #{certfile} did not exist to create TLSA record for #{hostname}:#{port}." + ports = [ port ] end - certfile += ".new" - if File.exist?(certfile) - cmd = ['swede', 'create', '--usage=3', '--selector=1', '--mtype=1', '--certificate', certfile, '--port', port.to_s, hostname] - IO.popen(cmd, "r") {|i| res << i.read } - end + res = [] + res << "; cert #{certfile} for #{hostname}:#{port}." + ports.each{ |port| + if File.exist?(certfile) + cmd = ['swede', 'create', '--usage=3', '--selector=1', '--mtype=1', '--certificate', certfile, '--port', port.to_s, hostname] + IO.popen(cmd, "r") {|i| res << i.read } + else + res << "; certfile #{certfile} did not exist to create TLSA record for #{hostname}:#{port}." + end + + if certfile.gsub!(/\.crt$/, '-new.crt') and File.exist?(certfile) + cmd = ['swede', 'create', '--usage=3', '--selector=1', '--mtype=1', '--certificate', certfile, '--port', port.to_s, hostname] + new_entry = '' + IO.popen(cmd, "r") {|i| new_entry = i.read } + if not res.include?(new_entry) + res << new_entry + end + end + } return res.join("\n") end