Class: SimplyGenius::Atmos::Config

Inherits:
Object
  • Object
show all
Includes:
FileUtils, GemLogger::LoggerSupport
Defined in:
lib/simplygenius/atmos/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atmos_env, working_group = 'default') ⇒ Config

Returns a new instance of Config.



21
22
23
24
25
26
27
28
# File 'lib/simplygenius/atmos/config.rb', line 21

def initialize(atmos_env, working_group = 'default')
  @atmos_env = atmos_env
  @working_group = working_group
  @root_dir = File.expand_path(Dir.pwd)
  @config_file = File.join(root_dir, "config", "atmos.yml")
  @tmp_root = File.join(root_dir, "tmp")
  @included_configs = []
end

Instance Attribute Details

#atmos_envObject

Returns the value of attribute atmos_env.



16
17
18
# File 'lib/simplygenius/atmos/config.rb', line 16

def atmos_env
  @atmos_env
end

#config_fileObject

Returns the value of attribute config_file.



16
17
18
# File 'lib/simplygenius/atmos/config.rb', line 16

def config_file
  @config_file
end

#root_dirObject

Returns the value of attribute root_dir.



16
17
18
# File 'lib/simplygenius/atmos/config.rb', line 16

def root_dir
  @root_dir
end

#tmp_rootObject

Returns the value of attribute tmp_root.



16
17
18
# File 'lib/simplygenius/atmos/config.rb', line 16

def tmp_root
  @tmp_root
end

#working_groupObject

Returns the value of attribute working_group.



16
17
18
# File 'lib/simplygenius/atmos/config.rb', line 16

def working_group
  @working_group
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
37
38
# File 'lib/simplygenius/atmos/config.rb', line 34

def [](key)
  load
  result = @config.notation_get(key)
  return result
end

#account_hashObject



58
59
60
61
62
63
64
65
# File 'lib/simplygenius/atmos/config.rb', line 58

def 
  load
  environments = @full_config[:environments] || {}
  environments.inject(Hash.new) do |accum, entry|
    accum[entry.first] = entry.last[:account_id]
    accum
  end
end

#add_user_load_path(*paths) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/simplygenius/atmos/config.rb', line 94

def add_user_load_path(*paths)
  load_path = paths + Array(self["atmos.load_path"])
  if load_path.present?
    load_path = load_path.collect { |path| File.expand_path(path) }
    logger.debug("Adding to load path: #{load_path.inspect}")
    $LOAD_PATH.insert(0, *load_path)
  end
end

#all_env_namesObject



53
54
55
56
# File 'lib/simplygenius/atmos/config.rb', line 53

def all_env_names
  load
  @full_config[:environments].keys
end

#auth_cache_dirObject



76
77
78
79
80
81
82
83
# File 'lib/simplygenius/atmos/config.rb', line 76

def auth_cache_dir
  @auth_cache_dir ||= begin
    dir = File.join(tmp_dir, 'auth')
    logger.debug("Auth cache dir: #{dir}")
    mkdir_p(dir)
    dir
  end
end

#is_atmos_repo?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/simplygenius/atmos/config.rb', line 30

def is_atmos_repo?
  File.exist?(config_file)
end

#plugin_managerObject



49
50
51
# File 'lib/simplygenius/atmos/config.rb', line 49

def plugin_manager
  @plugin_manager ||= PluginManager.new(self["atmos.plugins"])
end

#providerObject



45
46
47
# File 'lib/simplygenius/atmos/config.rb', line 45

def provider
  @provider ||= ProviderFactory.get(self[:provider])
end

#tf_working_dirObject



85
86
87
88
89
90
91
92
# File 'lib/simplygenius/atmos/config.rb', line 85

def tf_working_dir
  @tf_working_dir ||= begin
    dir = File.join(tmp_dir, 'tf', working_group)
    logger.debug("Terraform working dir: #{dir}")
    mkdir_p(dir)
    dir
  end
end

#tmp_dirObject



67
68
69
70
71
72
73
74
# File 'lib/simplygenius/atmos/config.rb', line 67

def tmp_dir
  @tmp_dir ||= begin
    dir = File.join(tmp_root, atmos_env)
    logger.debug("Tmp dir: #{dir}")
    mkdir_p(dir)
    dir
  end
end

#to_hObject



40
41
42
43
# File 'lib/simplygenius/atmos/config.rb', line 40

def to_h
  load
  @config.to_hash
end