Class: Minfra::Cli::Config
- Inherits:
-
Object
- Object
- Minfra::Cli::Config
- Defined in:
- lib/minfra/cli/config.rb
Overview
responsible the read the config file(s) and add a small abstraction layer on top of it
Defined Under Namespace
Classes: ConfigNotFoundError, EnvironmentNotFoundError
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#kind_config_path ⇒ Object
readonly
Returns the value of attribute kind_config_path.
-
#kube_config_path ⇒ Object
readonly
Returns the value of attribute kube_config_path.
-
#kube_path ⇒ Object
readonly
Returns the value of attribute kube_path.
-
#me_path ⇒ Object
readonly
Returns the value of attribute me_path.
-
#orch_env ⇒ Object
readonly
Returns the value of attribute orch_env.
-
#orch_env_config ⇒ Object
readonly
Returns the value of attribute orch_env_config.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#stacks_path ⇒ Object
readonly
Returns the value of attribute stacks_path.
-
#status_path ⇒ Object
readonly
Returns the value of attribute status_path.
Instance Method Summary collapse
- #api_key ⇒ Object
- #describe(_environment) ⇒ Object
- #dev? ⇒ Boolean
- #email ⇒ Object
- #endpoint(name) ⇒ Object
- #init!(base_path_str, orch_env) ⇒ Object
-
#initialize(base_path_str, orch_env) ⇒ Config
constructor
A new instance of Config.
- #name ⇒ Object
Constructor Details
#initialize(base_path_str, orch_env) ⇒ Config
Returns a new instance of Config.
20 21 22 |
# File 'lib/minfra/cli/config.rb', line 20 def initialize(base_path_str, orch_env) init!(base_path_str, orch_env) end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def base_path @base_path end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def config @config end |
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def config_path @config_path end |
#kind_config_path ⇒ Object (readonly)
Returns the value of attribute kind_config_path.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def kind_config_path @kind_config_path end |
#kube_config_path ⇒ Object (readonly)
Returns the value of attribute kube_config_path.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def kube_config_path @kube_config_path end |
#kube_path ⇒ Object (readonly)
Returns the value of attribute kube_path.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def kube_path @kube_path end |
#me_path ⇒ Object (readonly)
Returns the value of attribute me_path.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def me_path @me_path end |
#orch_env ⇒ Object (readonly)
Returns the value of attribute orch_env.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def orch_env @orch_env end |
#orch_env_config ⇒ Object (readonly)
Returns the value of attribute orch_env_config.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def orch_env_config @orch_env_config end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def project @project end |
#stacks_path ⇒ Object (readonly)
Returns the value of attribute stacks_path.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def stacks_path @stacks_path end |
#status_path ⇒ Object (readonly)
Returns the value of attribute status_path.
17 18 19 |
# File 'lib/minfra/cli/config.rb', line 17 def status_path @status_path end |
Instance Method Details
#api_key ⇒ Object
74 75 76 |
# File 'lib/minfra/cli/config.rb', line 74 def api_key @project.account_api_key end |
#describe(_environment) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/minfra/cli/config.rb', line 51 def describe(_environment) { env: { minfra_name: ENV.fetch('MINFRA_NAME', nil), minfra_path: ENV.fetch('MINFRA_PATH', nil) }, base_path: base_path.to_s, me_path: me_path.to_s, kube_path: kube_path.to_s, config_path: config_path.to_s, config: @config.to_h, project: @project } end |
#dev? ⇒ Boolean
66 67 68 |
# File 'lib/minfra/cli/config.rb', line 66 def dev? @orch_env == 'dev' end |
#email ⇒ Object
70 71 72 |
# File 'lib/minfra/cli/config.rb', line 70 def email @config.identity.email end |
#endpoint(name) ⇒ Object
78 79 80 81 82 |
# File 'lib/minfra/cli/config.rb', line 78 def endpoint(name) Hashie::Mash.new({ api_key: }).deep_merge(@project.endpoints[name]) rescue StandardError raise("endpoint #{name} is undefinded please add <env>:endpoints:#{name} to you #{config_path} file ") end |
#init!(base_path_str, orch_env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/minfra/cli/config.rb', line 24 def init!(base_path_str, orch_env) @orch_env = orch_env @base_path = Pathname.new(base_path_str). @me_path = @base_path.join('me') @project_config_path = @base_path.join('config', 'project.json') @config_path = @me_path.join('config.json') @stacks_path = @base_path.join('stacks') @status_path = @base_path.join('state') @kube_path = @me_path.join('kube') @kube_config_path = @kube_path.join('config') @kind_config_path = @me_path.join('kind.yaml') if config_path.exist? @config = Hashie::Mash.new(JSON.parse(Minfra::Cli::Templater.render(File.read(config_path), {}))) else warn("personal minfra configuration file '#{config_path}' not found, you might have to run 'minfra setup dev'") @config = Hashie::Mash.new({}) end @project = Hashie::Mash.new(JSON.parse(Minfra::Cli::Templater.render(File.read(@project_config_path), {}))) @project = @project .deep_merge(@config) end |
#name ⇒ Object
47 48 49 |
# File 'lib/minfra/cli/config.rb', line 47 def name @project.name end |