class Puppetserver::Ca::Config::PuppetServer
Provides an interface for querying Puppetserver settings w/o loading Puppetserver or any TK config service. Uses the ruby-hocon gem for parsing.
Attributes
errors[R]
settings[R]
Public Class Methods
new(supplied_config_path = nil)
click to toggle source
# 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
parse(config_path = nil)
click to toggle source
# File lib/puppetserver/ca/config/puppetserver.rb, line 12 def self.parse(config_path = nil) instance = new(config_path) instance.load return instance end
Public Instance Methods
load()
click to toggle source
Populate this config object with the CA-related settings
# 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
Private Instance Methods
explicitly_given_config_file_or_default_config_exists?()
click to toggle source
# File lib/puppetserver/ca/config/puppetserver.rb, line 78 def explicitly_given_config_file_or_default_config_exists? !@using_default_location || File.exist?(@config_path) end
supply_defaults(overrides = {})
click to toggle source
Supply defaults for any CA settings not present in the config file @param [Hash] overrides setting names and values loaded from the config file,
for overriding the defaults
@return [Hash] CA-related settings
# File lib/puppetserver/ca/config/puppetserver.rb, line 63 def supply_defaults(overrides = {}) ca_settings = overrides['certificate-authority'] || {} settings = {} cadir = settings[:cadir] = ca_settings.fetch('cadir', user_specific_ca_dir) settings[:cacert] = ca_settings.fetch('cacert', "#{cadir}/ca_crt.pem") settings[:cakey] = ca_settings.fetch('cakey', "#{cadir}/ca_key.pem") settings[:cacrl] = ca_settings.fetch('cacrl', "#{cadir}/ca_crl.pem") settings[:serial] = ca_settings.fetch('serial', "#{cadir}/serial") settings[:cert_inventory] = ca_settings.fetch('cert-inventory', "#{cadir}/inventory.txt") return settings end
user_specific_ca_dir()
click to toggle source
Return the correct confdir. We check for being root on *nix, else the user path. We do not include a check for running as Adminstrator since non-development scenarios for Puppet Server on Windows are unsupported. Note that Puppet Server runs as the [pe-]puppet user but to start/stop it you must be root.
# File lib/puppetserver/ca/config/puppetserver.rb, line 51 def user_specific_ca_dir if Puppetserver::Ca::Utils::Config.running_as_root? '/etc/puppetlabs/puppetserver/ca' else "#{ENV['HOME']}/.puppetlabs/etc/puppetserver/ca" end end