Class: Puppet::Node::Cdpe
- Inherits:
-
Indirector::Code
- Object
- Indirector::Code
- Puppet::Node::Cdpe
- Defined in:
- lib/puppet/indirector/node/cdpe.rb
Overview
================= This is a copy paste of https://github.com/puppetlabs/classifier/blob/2019.0.x/puppet/lib/puppet/indirector/node/classifier.rb with modifications to override trusted_facts to use the ones from PDB instead of looking up the one coming from the requesting node since we won't have
that information for CD4PE
Constant Summary collapse
- AgentSpecifiedEnvironment =
'agent-specified'.freeze
- ClassificationConflict =
'classification-conflict'.freeze
- KEY_HIERA_DATA =
'config_data'.freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.load_config ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/indirector/node/cdpe.rb', line 27 def self.load_config config_path = File.join(Puppet[:confdir], 'classifier.yaml') config = nil if File.exist?(config_path) config = YAML.load_file(config_path) else Puppet.warning("Classifier config file '#{config_path}' does not exist, using defaults") config = {} end if config.respond_to?(:to_ary) config.map do |service| merge_defaults(service) end else service = merge_defaults(config) [service] end end |
Instance Method Details
#adapt_node_with_hiera_data(node, hiera_data) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/puppet/indirector/node/cdpe.rb', line 48 def adapt_node_with_hiera_data(node, hiera_data) hiera_data ||= {} flattened_hiera_data = {} hiera_data.each do |scope, kv| kv.each do |k, v| flattened_hiera_data["#{scope}::#{k}"] = v end end Puppet::Node::HieraNodeAdapter.adapt(node).hiera_data = flattened_hiera_data node end |
#find(request) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/puppet/indirector/node/cdpe.rb', line 61 def find(request) name = request.key facts = if request.[:facts].is_a?(Puppet::Node::Facts) request.[:facts] else Puppet::Node::Facts.indirection.find(name, environment: request.environment) end fact_values = if facts.nil? {} else facts.sanitize facts.to_data_hash['values'] end ## REMOVED TO USE PDB FACTS # trusted_data = Puppet.lookup(:trusted_information) do # This block contains a default implementation for trusted # information. It should only get invoked if the node is local # (e.g. running puppet apply) # temp_node = Puppet::Node.new(name) # temp_node.parameters['clientcert'] = Puppet[:certname] # Puppet::Context::TrustedInformation.local(temp_node) # end trusted_data_values = if fact_values['trusted'].nil? {} else fact_values['trusted'] end facts_for_request = { 'fact' => fact_values, 'trusted' => trusted_data_values } if request..include?(:transaction_uuid) facts_for_request['transaction_uuid'] = request.[:transaction_uuid] end requested_environment = request.[:configured_environment] || request.environment services.each do |service| result = retrieve_classification(name, facts_for_request, requested_environment, service) if result.is_a? Puppet::Node # Puppet 5.0 and later supports sending facts along with #fact_merge, to # avoid extra indirection calls if result.method(:fact_merge).arity.zero? result.fact_merge else result.fact_merge(facts) end return result elsif result.respond_to?(:[]) && result['kind'] == ClassificationConflict # got a classification conflict msg = result['msg'] Puppet.err(msg) raise Puppet::Error, msg end end # got neither a valid classification nor a classification conflict, so all the services are # unreachable or having unforeseen problems msg = "Classification of #{name} failed due to a Node Manager service error. Please check /var/log/puppetlabs/console-services/console-services.log on the node(s) running the Node Manager service for more details." Puppet.err(msg) raise Puppet::Error, msg end |