Class: Puppet::SSL::CertificateRequestAttributes Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/ssl/certificate_request_attributes.rb

Overview

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

This class transforms simple key/value pairs into the equivalent ASN1 structures. Values may be strings or arrays of strings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ CertificateRequestAttributes

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.

Returns a new instance of CertificateRequestAttributes.



13
14
15
16
17
# File 'lib/puppet/ssl/certificate_request_attributes.rb', line 13

def initialize(path)
  @path = path
  @custom_attributes = {}
  @extension_requests = {}
end

Instance Attribute Details

#custom_attributesObject (readonly)

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.



11
12
13
# File 'lib/puppet/ssl/certificate_request_attributes.rb', line 11

def custom_attributes
  @custom_attributes
end

#extension_requestsObject (readonly)

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.



11
12
13
# File 'lib/puppet/ssl/certificate_request_attributes.rb', line 11

def extension_requests
  @extension_requests
end

#pathObject (readonly)

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.



11
12
13
# File 'lib/puppet/ssl/certificate_request_attributes.rb', line 11

def path
  @path
end

Instance Method Details

#loadObject

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.

Attempt to load a yaml file at the given @path.

Returns:

  • true if we are able to load the file, false otherwise

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppet/ssl/certificate_request_attributes.rb', line 22

def load
  Puppet.info(_("csr_attributes file loading from %{path}") % { path: path })
  if Puppet::FileSystem.exist?(path)
    hash = Puppet::Util::Yaml.safe_load_file(path, [Symbol]) || {}
    unless hash.is_a?(Hash)
      raise Puppet::Error, _("invalid CSR attributes, expected instance of Hash, received instance of %{klass}") % { klass: hash.class }
    end

    @custom_attributes = hash.delete('custom_attributes') || {}
    @extension_requests = hash.delete('extension_requests') || {}
    unless hash.keys.empty?
      raise Puppet::Error, _("unexpected attributes %{keys} in %{path}") % { keys: hash.keys.inspect, path: @path.inspect }
    end

    return true
  end
  false
end