class Conjur::Config

Public Class Methods

[](key) click to toggle source
# File lib/conjur/config.rb, line 121
def [](key)
  @@attributes[key.to_s]
end
alternate_key(key) click to toggle source
# File lib/conjur/config.rb, line 129
def alternate_key key
  case key
    when String then key.to_sym
    when Symbol then key.to_s
    else key
  end
end
apply() click to toggle source
# File lib/conjur/config.rb, line 75
def apply
  require 'conjur/configuration'

  keys = Config.keys.dup
  keys.delete(:plugins)

  cfg = Conjur.configuration
  keys.each do |k|
    if Conjur.configuration.respond_to?("#{k}_env_var") && (env_var = Conjur.configuration.send("#{k}_env_var")) && (v = ENV[env_var])
      if Conjur.log
        Conjur.log << "Not overriding environment setting #{k}=#{v}\n"
      end
      next
    end
    value = Config[k]
    cfg.set k, value if value
  end

  Conjur.log << "Using authn url #{Conjur.configuration.authn_url}\n" if Conjur.log

  Conjur.config.apply_cert_config!
end
clear() click to toggle source
# File lib/conjur/config.rb, line 29
def clear
  @@attributes = {}
end
default_config_files() click to toggle source
# File lib/conjur/config.rb, line 52
def default_config_files
  ['/etc/conjur.conf', user_config_files, plugin_config_files].flatten.uniq
end
inspect() click to toggle source
# File lib/conjur/config.rb, line 99
def inspect
  @@attributes.inspect
end
keys() click to toggle source
# File lib/conjur/config.rb, line 117
def keys
  @@attributes.keys.map(&:to_sym)
end
load(config_files = default_config_files) click to toggle source
# File lib/conjur/config.rb, line 56
def load(config_files = default_config_files)
  require 'yaml'
  require 'conjur/log'

  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
member?(key) click to toggle source
# File lib/conjur/config.rb, line 125
def member? key
  @@attributes.member?(key) || @@attributes.member?(alternate_key(key))
end
merge(a) click to toggle source
# File lib/conjur/config.rb, line 112
def merge(a)
  a = {} unless a
  @@attributes.deep_merge!(a.stringify_keys)
end
plugin_config_files() click to toggle source
# File lib/conjur/config.rb, line 33
def plugin_config_files
  [ '/opt/conjur/etc/plugins.yml' ]
end
plugins() click to toggle source
# File lib/conjur/config.rb, line 103
def plugins
  plugins = @@attributes['plugins']
  if plugins
    plugins.is_a?(Array) ? plugins : plugins.split(',')
  else
    []
  end
end
user_config_files() click to toggle source
# File lib/conjur/config.rb, line 37
def user_config_files
  if ENV['CONJURRC']
    return ENV['CONJURRC']
  else
    homefile = File.expand_path "~/.conjurrc"
    pwdfile = File.expand_path ".conjurrc"
    if homefile != pwdfile && File.file?(pwdfile)
      $stderr.puts """NOTE:\t.conjurrc file detected in the current directory.\n"\
          "\tIt's no longer consulted in this version. Please explicitly\n"\
          "\tset CONJURRC=./.conjurrc if you're sure you want to use it."
    end
    [ homefile ]
  end
end