module Puppet::TrustedExternal

A method for retrieving external trusted facts

Public Class Methods

fetch_data(command, certname) click to toggle source
   # File lib/puppet/trusted_external.rb
33 def fetch_data(command, certname)
34   result = Puppet::Util::Execution.execute([command, certname], {
35     :combine => false,
36     :failonfail => true,
37   })
38   JSON.parse(result)
39 end
retrieve(certname) click to toggle source
   # File lib/puppet/trusted_external.rb
 3 def retrieve(certname)
 4   command = Puppet[:trusted_external_command]
 5   return nil unless command
 6   Puppet.debug { _("Retrieving trusted external data from %{command}") % {command: command} }
 7   setting_type = Puppet.settings.setting(:trusted_external_command).type
 8   if setting_type == :file
 9     return fetch_data(command, certname)
10   end
11   # command is a directory. Thus, data is a hash of <basename> => <data> for
12   # each executable file in command. For example, if the files 'servicenow.rb',
13   # 'unicorn.sh' are in command, then data is the following hash:
14   #   { 'servicenow' => <servicenow.rb output>, 'unicorn' => <unicorn.sh output> }
15   data = {}
16   Puppet::FileSystem.children(command).each do |file|
17     abs_path = Puppet::FileSystem.expand_path(file)
18     executable_file = Puppet::FileSystem.file?(abs_path) && Puppet::FileSystem.executable?(abs_path)
19     unless executable_file
20       Puppet.debug { _("Skipping non-executable file %{file}")  % { file: abs_path } }
21       next
22     end
23     basename = file.basename(file.extname).to_s
24     unless data[basename].nil?
25       raise Puppet::Error, _("There is more than one '%{basename}' script in %{dir}") % { basename: basename, dir: command }
26     end
27     data[basename] = fetch_data(abs_path, certname)
28   end
29   data
30 end

Private Instance Methods

fetch_data(command, certname) click to toggle source
   # File lib/puppet/trusted_external.rb
33 def fetch_data(command, certname)
34   result = Puppet::Util::Execution.execute([command, certname], {
35     :combine => false,
36     :failonfail => true,
37   })
38   JSON.parse(result)
39 end
retrieve(certname) click to toggle source
   # File lib/puppet/trusted_external.rb
 3 def retrieve(certname)
 4   command = Puppet[:trusted_external_command]
 5   return nil unless command
 6   Puppet.debug { _("Retrieving trusted external data from %{command}") % {command: command} }
 7   setting_type = Puppet.settings.setting(:trusted_external_command).type
 8   if setting_type == :file
 9     return fetch_data(command, certname)
10   end
11   # command is a directory. Thus, data is a hash of <basename> => <data> for
12   # each executable file in command. For example, if the files 'servicenow.rb',
13   # 'unicorn.sh' are in command, then data is the following hash:
14   #   { 'servicenow' => <servicenow.rb output>, 'unicorn' => <unicorn.sh output> }
15   data = {}
16   Puppet::FileSystem.children(command).each do |file|
17     abs_path = Puppet::FileSystem.expand_path(file)
18     executable_file = Puppet::FileSystem.file?(abs_path) && Puppet::FileSystem.executable?(abs_path)
19     unless executable_file
20       Puppet.debug { _("Skipping non-executable file %{file}")  % { file: abs_path } }
21       next
22     end
23     basename = file.basename(file.extname).to_s
24     unless data[basename].nil?
25       raise Puppet::Error, _("There is more than one '%{basename}' script in %{dir}") % { basename: basename, dir: command }
26     end
27     data[basename] = fetch_data(abs_path, certname)
28   end
29   data
30 end