]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/puppetmaster/lib/puppet/parser/functions/gen_tlsa_entry.rb
variable assignment does not clone string...
[dsa-puppet.git] / modules / puppetmaster / lib / puppet / parser / functions / gen_tlsa_entry.rb
1 module Puppet::Parser::Functions
2   newfunction(:gen_tlsa_entry, :type => :rvalue) do |args|
3     certfile = args.shift()
4     hostname = args.shift()
5     port = args.shift()
6
7     if port.kind_of?(Array)
8       ports = port
9     else
10       ports = [port]
11     end
12
13     res = []
14     res << "; cert #{certfile} for #{hostname}:#{ports}."
15     ports.each do |port|
16       if File.exist?(certfile)
17         cmd = ['swede', 'create', '--usage=3', '--selector=1', '--mtype=1', '--certificate', certfile, '--port', port.to_s, hostname]
18         IO.popen(cmd, "r") {|i| res << i.read }
19       else
20         res << "; certfile #{certfile} did not exist to create TLSA record for #{hostname}:#{port}."
21       end
22
23       cfnew = certfile.gsub(/\.crt$/, '-new.crt')
24       if cfnew != certfile and File.exist?(cfnew)
25         cmd = ['swede', 'create', '--usage=3', '--selector=1', '--mtype=1', '--certificate', cfnew, '--port', port.to_s, hostname]
26         new_entry = ''
27         IO.popen(cmd, "r") {|i| new_entry = i.read }
28         if not res.include?(new_entry)
29           res << new_entry
30         end
31       end
32     end
33
34     return res.join("\n")
35   end
36 end