Method: Puppet::SSL::Oids.parse_custom_oid_file

Defined in:
lib/puppet/ssl/oids.rb

.parse_custom_oid_file(custom_oid_file, map_key = 'oid_mapping') ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse custom OID mapping file that enables custom OIDs to be resolved into user-friendly names.


oid_mapping:

'1.3.6.1.4.1.34380.1.2.1.1':
  shortname : 'myshortname'
  longname  : 'Long name'
'1.3.6.1.4.1.34380.1.2.1.2':
  shortname: 'myothershortname'
  longname: 'Other Long name'

Examples:

Custom OID mapping file


Parameters:

  • custom_oid_file (String)

    File to obtain custom OIDs mapping from

  • map_key (String) (defaults to: 'oid_mapping')

    Hash key in which custom OIDs mapping is stored



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/puppet/ssl/oids.rb', line 107

def self.parse_custom_oid_file(custom_oid_file, map_key='oid_mapping')
  if File.exist?(custom_oid_file) && File.readable?(custom_oid_file)
    mapping = nil
    begin
      mapping = Puppet::Util::Yaml.safe_load_file(custom_oid_file, [Symbol])
    rescue => err
      raise Puppet::Error, _("Error loading ssl custom OIDs mapping file from '%{custom_oid_file}': %{err}") % { custom_oid_file: custom_oid_file, err: err }, err.backtrace
    end

    unless mapping.has_key?(map_key)
      raise Puppet::Error, _("Error loading ssl custom OIDs mapping file from '%{custom_oid_file}': no such index '%{map_key}'") % { custom_oid_file: custom_oid_file, map_key: map_key }
    end

    unless mapping[map_key].is_a?(Hash)
      raise Puppet::Error, _("Error loading ssl custom OIDs mapping file from '%{custom_oid_file}': data under index '%{map_key}' must be a Hash") % { custom_oid_file: custom_oid_file, map_key: map_key }
    end

    oid_defns = []
    mapping[map_key].keys.each do |oid|
      shortname, longname = mapping[map_key][oid].values_at("shortname","longname")
      if shortname.nil? || longname.nil?
        raise Puppet::Error, _("Error loading ssl custom OIDs mapping file from '%{custom_oid_file}': incomplete definition of oid '%{oid}'") % { custom_oid_file: custom_oid_file, oid: oid }
      end
      oid_defns << [oid, shortname, longname]
    end

    oid_defns
  end
end