Class: Puppetserver::Ca::Config::PuppetServer

Inherits:
Object
  • Object
show all
Defined in:
lib/puppetserver/ca/config/puppetserver.rb

Overview

Provides an interface for querying Puppetserver settings w/o loading Puppetserver or any TK config service. Uses the ruby-hocon gem for parsing.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(supplied_config_path = nil) ⇒ PuppetServer

Returns a new instance of PuppetServer.



21
22
23
24
25
26
27
# File 'lib/puppetserver/ca/config/puppetserver.rb', line 21

def initialize(supplied_config_path = nil)
  @using_default_location = !supplied_config_path
  @config_path = supplied_config_path || "/etc/puppetlabs/puppetserver/conf.d/ca.conf"

  @settings = nil
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



19
20
21
# File 'lib/puppetserver/ca/config/puppetserver.rb', line 19

def errors
  @errors
end

#settingsObject (readonly)

Returns the value of attribute settings.



19
20
21
# File 'lib/puppetserver/ca/config/puppetserver.rb', line 19

def settings
  @settings
end

Class Method Details

.parse(config_path = nil) ⇒ Object



12
13
14
15
16
17
# File 'lib/puppetserver/ca/config/puppetserver.rb', line 12

def self.parse(config_path = nil)
  instance = new(config_path)
  instance.load

  return instance
end

Instance Method Details

#loadObject

Populate this config object with the CA-related settings



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/puppetserver/ca/config/puppetserver.rb', line 30

def load
  if explicitly_given_config_file_or_default_config_exists?
    begin
      results = Hocon.load(@config_path)
    rescue Hocon::ConfigError => e
      errors << e.message
    end
  end

  overrides = results || {}
  @settings = supply_defaults(overrides).freeze
end