onion classes updates from tor: support direct onion services also
[mirror/dsa-puppet.git] / modules / puppetmaster / lib / puppet / parser / functions / onion_global_service_hostname.rb
1 # This function returns the .onion name for a given service name on Debian's onionbalance instance
2 # for this, it reads /srv/puppet.debian.org/puppet-facts/onionbalance-services.yaml
3 # this comes from the onionbalance-host, via puppet's storedconf
4 #
5 module Puppet::Parser::Functions
6   newfunction(:onion_global_service_hostname, :type => :rvalue) do |args|
7     servicename = args.shift()
8
9     fn = '/srv/puppet.debian.org/puppet-facts/onionbalance-services.yaml'
10     unless File.exist?(fn)
11       return false
12     end
13
14     facts = IO.read(fn)
15
16     require 'json'
17     parsed = {}
18     facts.each_line do |l|
19       p.update(JSON.parse(l))
20     end
21     return parsed[servicename]
22   end
23 end
24 # vim:set ts=2:
25 # vim:set et:
26 # vim:set shiftwidth=2: