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