Class: SimplyGenius::Atmos::Config
- Inherits:
-
Object
- Object
- SimplyGenius::Atmos::Config
- Includes:
- FileUtils, GemLogger::LoggerSupport
- Defined in:
- lib/simplygenius/atmos/config.rb
Instance Attribute Summary collapse
-
#atmos_env ⇒ Object
Returns the value of attribute atmos_env.
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
-
#tmp_root ⇒ Object
Returns the value of attribute tmp_root.
-
#user_config_file ⇒ Object
Returns the value of attribute user_config_file.
-
#working_group ⇒ Object
Returns the value of attribute working_group.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #account_hash ⇒ Object
- #add_user_load_path(*paths) ⇒ Object
- #all_env_names ⇒ Object
- #auth_cache_dir ⇒ Object
-
#initialize(atmos_env, working_group = 'default') ⇒ Config
constructor
A new instance of Config.
- #is_atmos_repo? ⇒ Boolean
- #plugin_manager ⇒ Object
- #provider ⇒ Object
- #save_user_config_file(data, merge_to_existing: true) ⇒ Object
- #tf_working_dir ⇒ Object
- #tmp_dir ⇒ Object
- #to_h ⇒ Object
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.(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_env ⇒ Object
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_file ⇒ Object
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_dir ⇒ Object
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_root ⇒ Object
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_file ⇒ Object
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_group ⇒ Object
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_hash ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/simplygenius/atmos/config.rb', line 66 def account_hash 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.(path) } logger.debug("Adding to load path: #{load_path.inspect}") $LOAD_PATH.insert(0, *load_path) end end |
#all_env_names ⇒ Object
61 62 63 64 |
# File 'lib/simplygenius/atmos/config.rb', line 61 def all_env_names load @full_config[:environments].keys end |
#auth_cache_dir ⇒ Object
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
32 33 34 |
# File 'lib/simplygenius/atmos/config.rb', line 32 def is_atmos_repo? File.exist?(config_file) end |
#plugin_manager ⇒ Object
57 58 59 |
# File 'lib/simplygenius/atmos/config.rb', line 57 def plugin_manager @plugin_manager ||= PluginManager.new(self["atmos.plugins"]) end |
#provider ⇒ Object
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_dir ⇒ Object
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_dir ⇒ Object
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_h ⇒ Object
48 49 50 51 |
# File 'lib/simplygenius/atmos/config.rb', line 48 def to_h load @config.to_hash end |