Module: Muchkeys

Includes:
ActiveSupport::Configurable
Defined in:
lib/muchkeys.rb,
lib/muchkeys/cli.rb,
lib/muchkeys/rails.rb,
lib/muchkeys/version.rb,
lib/muchkeys/key_validator.rb

Defined Under Namespace

Classes: AmbigousPath, ApplicationClient, CLI, CLIOptionsError, ConsulClient, InvalidKey, KeyNotSet, KeyValidator, Rails, Secret, UnknownApplication

Constant Summary collapse

VERSION =
"0.7.1"

Class Method Summary collapse

Class Method Details

.configure_from_yaml(file) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/muchkeys.rb', line 58

def self.configure_from_yaml(file)
  app_config = YAML.load(File.read(file)).with_indifferent_access
  Muchkeys.configure do |config|
    config.application_name = app_config[:application_name] if app_config.has_key?(:application_name)
    config.consul_url       = app_config[:consul_url]       if app_config.has_key?(:consul_url)
    config.keys_dir         = app_config[:keys_dir]         if app_config.has_key?(:keys_dir)
    config.private_key      = app_config[:private_key]      if app_config.has_key?(:private_key)
    config.public_key       = app_config[:public_key]       if app_config.has_key?(:public_key)
    config.search_paths     = app_config[:search_paths]     if app_config.has_key?(:search_paths)
    config.secrets_hint     = app_config[:secrets_hint]     if app_config.has_key?(:secrets_hint)
  end
end

.env_keysObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/muchkeys.rb', line 42

def self.env_keys
  # parse all environments found in .env and populate them from consul
  if defined? ::Rails
    check_dir = ::Rails.root
  else
    check_dir = Pathname.getwd
  end


  unless File.exists?(check_dir.join(".env"))
    raise IOError, ".env files are required for Muchkeys ENV injection to work"
  end

  File.read(check_dir.join(".env")).each_line.select(&:presence).map { |x| x.split("=")[0] }
end

.populate_environment!(*required_keys) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/muchkeys.rb', line 71

def self.populate_environment!(*required_keys)
  app = ApplicationClient.new(config)
  app.verify_keys(*required_keys)

  app.known_keys.each do |key|
    ENV[key] ||= app.first(key)
  end

  nil
end