Class: Conjur::Config

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

Constant Summary collapse

@@attributes =
{}

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



91
92
93
# File 'lib/conjur/config.rb', line 91

def [](key)
  @@attributes[key.to_s]
end

.applyObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/conjur/config.rb', line 53

def apply
  keys = Config.keys.dup
  keys.delete(:plugins)
  keys.each do |k|
    value = Config[k]
    Conjur.configuration.set k, value if value
  end
  
  if Conjur.log
    Conjur.log << "Using authn host #{Conjur::Authn::API.host}\n"
  end
  if Config[:cert_file]
    OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE.add_file Config[:cert_file]
  end
end

.clearObject



29
30
31
# File 'lib/conjur/config.rb', line 29

def clear
  @@attributes = {}
end

.default_config_filesObject



33
34
35
# File 'lib/conjur/config.rb', line 33

def default_config_files
  [ File.join("/etc", "conjur.conf"), ( ENV['CONJURRC'] || File.join(ENV['HOME'], ".conjurrc") ), '.conjurrc' ]
end

.inspectObject



69
70
71
# File 'lib/conjur/config.rb', line 69

def inspect
  @@attributes.inspect
end

.keysObject



87
88
89
# File 'lib/conjur/config.rb', line 87

def keys
  @@attributes.keys.map(&:to_sym)
end

.load(config_files = default_config_files) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/conjur/config.rb', line 37

def load(config_files = default_config_files)
  require 'yaml'
  config_files.each do |f|
    if File.file?(f)
      if Conjur.log
        Conjur.log << "Loading #{f}\n"
      end
      config = YAML.load(IO.read(f)).stringify_keys rescue {}
      if config['cert_file']
        config['cert_file'] = File.expand_path(config['cert_file'], File.dirname(f))
      end
      Conjur::Config.merge config
    end
  end
end

.merge(a) ⇒ Object



82
83
84
85
# File 'lib/conjur/config.rb', line 82

def merge(a)
  a = {} unless a
  @@attributes.deep_merge!(a.stringify_keys)
end

.pluginsObject



73
74
75
76
77
78
79
80
# File 'lib/conjur/config.rb', line 73

def plugins
  plugins = @@attributes['plugins']
  if plugins
    plugins.is_a?(Array) ? plugins : plugins.split(',')
  else
    []
  end
end