Class: OctocatalogDiff::CatalogUtil::ENC::PE::V1
- Inherits:
-
Object
- Object
- OctocatalogDiff::CatalogUtil::ENC::PE::V1
- Defined in:
- lib/octocatalog-diff/catalog-util/enc/pe/v1.rb
Overview
Support the Puppet Enterprise classification API. Documentation: docs.puppet.com/pe/latest/nc_index.html This is version 1 of the API
Instance Method Summary collapse
-
#body ⇒ String
POST body.
-
#headers ⇒ Hash
Headers.
-
#initialize(options) ⇒ V1
constructor
Constructor.
-
#result(parsed, logger) ⇒ String
Parse response from ENC and return the final ENC data.
-
#url ⇒ String
Return the URL to the API.
Constructor Details
#initialize(options) ⇒ V1
Constructor
19 20 21 |
# File 'lib/octocatalog-diff/catalog-util/enc/pe/v1.rb', line 19 def initialize() @options = end |
Instance Method Details
#body ⇒ String
POST body
42 43 44 45 |
# File 'lib/octocatalog-diff/catalog-util/enc/pe/v1.rb', line 42 def body raise ":facts required (got #{@options[:facts].class})" unless @options[:facts].is_a?(OctocatalogDiff::Facts) { 'fact' => @options[:facts].facts }.to_json end |
#headers ⇒ Hash
Headers
31 32 33 34 35 36 37 38 |
# File 'lib/octocatalog-diff/catalog-util/enc/pe/v1.rb', line 31 def headers result = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } result['X-Authentication'] = @options[:pe_enc_token] if @options[:pe_enc_token] result end |
#result(parsed, logger) ⇒ String
Parse response from ENC and return the final ENC data
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/octocatalog-diff/catalog-util/enc/pe/v1.rb', line 51 def result(parsed, logger) %w(classes parameters).each do |required_key| next if parsed[required_key] logger.debug parsed.keys.inspect raise OctocatalogDiff::Errors::PEClassificationError, "Response missing: #{required_key}" end obj = { 'classes' => parsed['classes'], 'parameters' => parsed['parameters'] } obj.to_yaml end |
#url ⇒ String
Return the URL to the API
25 26 27 |
# File 'lib/octocatalog-diff/catalog-util/enc/pe/v1.rb', line 25 def url "#{@options[:pe_enc_url]}/v1/classified/nodes/#{@options[:node]}" end |