Sha256: 1fc18ef0753cc46f806a7c0a667985502583617a500e691c5110226d66c3efa6

Contents?: true

Size: 1.35 KB

Versions: 8

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require_relative '../../puppet/ssl'
require_relative '../../puppet/util/yaml'

# This class transforms simple key/value pairs into the equivalent ASN1
# structures. Values may be strings or arrays of strings.
#
# @api private
class Puppet::SSL::CertificateRequestAttributes
  attr_reader :path, :custom_attributes, :extension_requests

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

  # Attempt to load a yaml file at the given @path.
  # @return true if we are able to load the file, false otherwise
  # @raise [Puppet::Error] if there are unexpected attribute keys
  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]) || {}
      if !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') || {}
      if not hash.keys.empty?
        raise Puppet::Error, _("unexpected attributes %{keys} in %{path}") % { keys: hash.keys.inspect, path: @path.inspect }
      end

      return true
    end
    return false
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puppet-8.5.1 lib/puppet/ssl/certificate_request_attributes.rb
puppet-8.5.1-x86-mingw32 lib/puppet/ssl/certificate_request_attributes.rb
puppet-8.5.1-x64-mingw32 lib/puppet/ssl/certificate_request_attributes.rb
puppet-8.5.1-universal-darwin lib/puppet/ssl/certificate_request_attributes.rb
puppet-8.5.0 lib/puppet/ssl/certificate_request_attributes.rb
puppet-8.5.0-x86-mingw32 lib/puppet/ssl/certificate_request_attributes.rb
puppet-8.5.0-x64-mingw32 lib/puppet/ssl/certificate_request_attributes.rb
puppet-8.5.0-universal-darwin lib/puppet/ssl/certificate_request_attributes.rb