Module: EasyType::CatalogData

Includes:
Encryption
Included in:
NodeGroupData
Defined in:
lib/easy_type/catalog_data.rb

Instance Method Summary collapse

Methods included from Encryption

#cipher, #decrypt, #decrypted_value, #encrypt, #encrypted?, #encryption_key

Instance Method Details

#catalogObject

Get the content of the catalog from anywhere. This is quite a hack, but it seems to work

Raises:

  • (Puppet::Error)


11
12
13
14
15
16
17
18
19
# File 'lib/easy_type/catalog_data.rb', line 11

def catalog
  #
  # This is a hack to access the catalog
  #
  return @catalog if @catalog
  catalogs = ObjectSpace.each_object(Puppet::Resource::Catalog).to_a
  raise Puppet::Error.new('No catalog found') if catalogs.empty?
  @catalog ||= catalogs.first
end

#get_catalog_data(key) ⇒ Object

Get the data with the specified key from the catalog and transform it back to the original data



25
26
27
28
29
# File 'lib/easy_type/catalog_data.rb', line 25

def get_catalog_data(key)
  data_resource = catalog.resource('em_data',key)
  json_value = data_resource['data']
  JSON.parse(json_value)
end

#get_secured_catalog_data(key) ⇒ Object

Get the secured data with the specified key from the catalog and transform it back to the original data



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/easy_type/catalog_data.rb', line 35

def get_secured_catalog_data(key)
  begin
    data_resource = catalog.resource('em_data',key)
    secured_value = data_resource['data']
  rescue
    Puppet.debug "Catalog data with key '#{key}', not found in catalog"
    raise Puppet::Error.new "Catalog data with key '#{key}', not found in catalog"
  end
  unsecured_json_value = decrypt(secured_value)
  JSON.parse(unsecured_json_value)
end