From: Peter Palfrader Date: Thu, 5 Nov 2015 18:54:43 +0000 (+0100) Subject: support multiple ports in gen tlsa X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=5d19747e6d11fe2a858a25eca511373b1655c88f;p=mirror%2Fdsa-puppet.git support multiple ports in gen tlsa --- 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 7b846b90c..fab4b92cf 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/gen_tlsa_entry.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/gen_tlsa_entry.rb @@ -4,22 +4,30 @@ 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 - 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 + res = [] + 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 - 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