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.



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

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")
  @user_config_file = "~/.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

#user_config_fileObject

Returns the value of attribute user_config_file.



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

def user_config_file
  @user_config_file
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



36
37
38
39
40
# File 'lib/simplygenius/atmos/config.rb', line 36

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

#[]=(key, value) ⇒ Object



42
43
44
45
46
# File 'lib/simplygenius/atmos/config.rb', line 42

def []=(key, value)
  load
  result = @config.notation_put(key, value)
  return result
end

#account_hashObject



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

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



102
103
104
105
106
107
108
109
# File 'lib/simplygenius/atmos/config.rb', line 102

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



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

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

#auth_cache_dirObject



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

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)


32
33
34
# File 'lib/simplygenius/atmos/config.rb', line 32

def is_atmos_repo?
  File.exist?(config_file)
end

#plugin_managerObject



57
58
59
# File 'lib/simplygenius/atmos/config.rb', line 57

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

#providerObject



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

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

#save_user_config_file(data, merge_to_existing: true) ⇒ Object



111
112
113
114
115
116
117
118
119
120
# File 'lib/simplygenius/atmos/config.rb', line 111

def save_user_config_file(data, merge_to_existing: true)
  logger.debug("Saving to user config file (merging=#{merge_to_existing}): #{user_config_file}")

  if merge_to_existing
    existing = load_file(user_config_file, SettingsHash.new)
    data = config_merge(existing, data, ["saving #{user_config_file}"])
  end
  File.write(user_config_file, YAML.dump(data.to_hash))
  File.chmod(0600, user_config_file)
end

#tf_working_dirObject



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

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



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

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



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

def to_h
  load
  @config.to_hash
end