Class: EasySettings::CertificateManagerSource

Inherits:
PathSource
  • Object
show all
Defined in:
lib/easy-settings/certificate_manager_source.rb

Instance Attribute Summary

Attributes inherited from PathSource

#base_path, #converter, #parse_values, #separator, #settings_root

Instance Method Summary collapse

Methods inherited from PathSource

#assign_value

Constructor Details

#initialize(base_path, settings_root: ["certificates"], separator: "__", converter: :downcase) ⇒ CertificateManagerSource

Returns a new instance of CertificateManagerSource.



4
5
6
# File 'lib/easy-settings/certificate_manager_source.rb', line 4

def initialize(base_path, settings_root: ["certificates"], separator: "__", converter: :downcase)
  super(base_path, settings_root: settings_root, separator: separator, converter: converter, parse_values: false)
end

Instance Method Details

#filenamesObject



30
31
32
# File 'lib/easy-settings/certificate_manager_source.rb', line 30

def filenames
  {"ca.crt" => "ca", "tls.crt" => "crt", "tls.key" => "key"}
end

#loadObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/easy-settings/certificate_manager_source.rb', line 8

def load
  {}.tap do |data|
    Dir["#{base_path}/*"].each do |path|
      next unless File.directory?(path)
      next unless valid_folder?(path)

      variable = path.gsub("#{base_path}/", "")
      keys = settings_root + variable.to_s.split(separator)

      filenames.each do |filename, key|
        value = File.binread("#{path}/#{filename}").strip
        assign_value(data, keys + [key], value)
      end
    end
  end
end

#valid_folder?(path) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/easy-settings/certificate_manager_source.rb', line 25

def valid_folder?(path)
  # ensure the folder contains all the files we expect
  (filenames.keys - Dir["#{path}/*"].map{ |path| File.basename(path) }).none?
end