Class: OctocatalogDiff::CatalogUtil::ENC::PE::V1

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(options) ⇒ V1

Constructor

Parameters:

  • options (Hash)

    All input options



19
20
21
# File 'lib/octocatalog-diff/catalog-util/enc/pe/v1.rb', line 19

def initialize(options)
  @options = options
end

Instance Method Details

#bodyString

POST body

Returns:



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

#headersHash

Headers

Returns:

  • (Hash)

    Headers for request



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

Parameters:

  • parsed (Parsed response)

    Parsed response from ENC

  • logger (Logger)

    Logger.object

Returns:

  • (String)

    ENC data as text



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

#urlString

Return the URL to the API

Returns:



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