Module: Conjur::PuppetModule::Config
- Defined in:
- lib/conjur/puppet_module/config.rb
Overview
This module is in charge of retrieving Conjur configuration data from the agent
Constant Summary collapse
- CONFIG_FILE_PATH =
'/etc/conjur.conf'- REG_KEY_NAME =
'Software\CyberArk\Conjur'
Class Method Summary collapse
- .from_file ⇒ Object
- .from_registry ⇒ Object
- .load ⇒ Object
- .load_cert_file(path) ⇒ Object
-
.load_registry_module ⇒ Object
We do this in a method to allow for easier testing.
Class Method Details
.from_file ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/conjur/puppet_module/config.rb', line 21 def from_file return {} unless File.file?(CONFIG_FILE_PATH) c = YAML.safe_load(File.read(CONFIG_FILE_PATH)) if c['cert_file'] c['ssl_certificate'] = load_cert_file(c['cert_file']) end c end |
.from_registry ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/conjur/puppet_module/config.rb', line 40 def from_registry raise 'Conjur::PuppetModule::Config#from_registry is only supported on Windows' \ unless Puppet.features.microsoft_windows? load_registry_module c = {} begin Win32::Registry::HKEY_LOCAL_MACHINE.open(REG_KEY_NAME) do |reg| # Convert registry value names from camel case to underscores # e.g. ApplianceUrl => appliance_url c = reg.map { |name, _type, data| [name.gsub(%r{(.)([A-Z])}, '\1_\2').downcase, data] }.to_h end rescue Puppet.notice "Windows Registry on the agent did not contain path '#{REG_KEY_NAME}'. " \ 'If this is the first time using server-provided credentials, this is ' \ 'expected behavior.' end if c['cert_file'] c['ssl_certificate'] = load_cert_file(c['cert_file']) end c end |
.load ⇒ Object
12 13 14 |
# File 'lib/conjur/puppet_module/config.rb', line 12 def load Puppet.features.microsoft_windows? ? from_registry : from_file end |
.load_cert_file(path) ⇒ Object
16 17 18 19 |
# File 'lib/conjur/puppet_module/config.rb', line 16 def load_cert_file(path) raise "Cert file '#{path}' cannot be found!" unless File.file?(path) File.read path end |
.load_registry_module ⇒ Object
We do this in a method to allow for easier testing
34 35 36 37 38 |
# File 'lib/conjur/puppet_module/config.rb', line 34 def load_registry_module # :nocov: require 'win32/registry' # :nocov: end |