Class: Config
Overview
rubocop:disable Metrics/ClassLength
Constant Summary
collapse
- CONFIG_FILE_LOCATION =
".controlplane/controlplane.yml"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
normalize_command_name, normalize_option_name, random_four_digits, strip_str_and_validate
Constructor Details
#initialize(args, options, required_options) ⇒ Config
Returns a new instance of Config.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/core/config.rb', line 14
def initialize(args, options, required_options)
@args = args
@options = options
@required_options = required_options
ensure_required_options!
warn_deprecated_options
Shell.verbose_mode(options[:verbose])
trace_mode = options[:trace]
return unless trace_mode
ControlplaneApiDirect.trace = trace_mode
Shell.warn("Trace mode is enabled, this will print sensitive information to the console.")
end
|
Instance Attribute Details
#app_comes_from_env ⇒ Object
Returns the value of attribute app_comes_from_env.
6
7
8
|
# File 'lib/core/config.rb', line 6
def app_comes_from_env
@app_comes_from_env
end
|
#args ⇒ Object
Returns the value of attribute args.
6
7
8
|
# File 'lib/core/config.rb', line 6
def args
@args
end
|
#options ⇒ Object
Returns the value of attribute options.
6
7
8
|
# File 'lib/core/config.rb', line 6
def options
@options
end
|
#org_comes_from_env ⇒ Object
Returns the value of attribute org_comes_from_env.
6
7
8
|
# File 'lib/core/config.rb', line 6
def org_comes_from_env
@org_comes_from_env
end
|
#required_options ⇒ Object
Returns the value of attribute required_options.
6
7
8
|
# File 'lib/core/config.rb', line 6
def required_options
@required_options
end
|
Instance Method Details
#[](key) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/core/config.rb', line 75
def [](key)
ensure_current_config!
raise "Can't find option '#{key}' for app '#{app}' in 'controlplane.yml'." unless current.key?(key)
current.fetch(key)
end
|
#app ⇒ Object
35
36
37
|
# File 'lib/core/config.rb', line 35
def app
@app ||= load_app_from_options || load_app_from_env
end
|
#app_cpln_dir ⇒ Object
87
88
89
|
# File 'lib/core/config.rb', line 87
def app_cpln_dir
"#{app_dir}/.controlplane"
end
|
#app_dir ⇒ Object
95
96
97
|
# File 'lib/core/config.rb', line 95
def app_dir
Pathname.new(config_file_path).parent.parent.to_s
end
|
#app_matches?(app_name1, app_name2, app_options) ⇒ Boolean
130
131
132
133
134
135
|
# File 'lib/core/config.rb', line 130
def app_matches?(app_name1, app_name2, app_options)
app_name1 && app_name2 &&
(app_name1.to_s == app_name2.to_s ||
(app_options[:match_if_app_name_starts_with] && app_name1.to_s.start_with?(app_name2.to_s))
)
end
|
#app_prefix ⇒ Object
39
40
41
|
# File 'lib/core/config.rb', line 39
def app_prefix
current&.fetch(:name)
end
|
#apps ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/core/config.rb', line 109
def apps
@apps ||= config[:apps].to_h do |app_name, app_options|
ensure_config_app!(app_name, app_options)
check_deprecated_options(app_options)
app_options_with_new_keys = app_options.to_h do |key, value|
new_key = new_option_keys[key]
new_key ? [new_key, value] : [key, value]
end
[app_name, app_options_with_new_keys]
end
end
|
#config ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/core/config.rb', line 99
def config
@config ||= begin
global_config = YAML.safe_load_file(config_file_path, symbolize_names: true, aliases: true)
ensure_config!(global_config)
ensure_config_apps!(global_config)
global_config
end
end
|
#current ⇒ Object
124
125
126
127
128
|
# File 'lib/core/config.rb', line 124
def current
return unless app
@current ||= find_app_config(app)
end
|
#domain ⇒ Object
71
72
73
|
# File 'lib/core/config.rb', line 71
def domain
@domain ||= load_domain_from_options || load_domain_from_file
end
|
#find_app_config(app_name1) ⇒ Object
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/core/config.rb', line 137
def find_app_config(app_name1)
@app_configs ||= {}
@app_configs[app_name1] ||= apps.filter_map do |app_name2, app_config|
next unless app_matches?(app_name1, app_name2, app_config)
app_config[:name] = app_name2
app_config
end&.last
end
|
#identity ⇒ Object
43
44
45
|
# File 'lib/core/config.rb', line 43
def identity
"#{app}-identity"
end
|
#identity_link ⇒ Object
47
48
49
|
# File 'lib/core/config.rb', line 47
def identity_link
"/org/#{org}/gvc/#{app}/identity/#{identity}"
end
|
#image_link(image) ⇒ Object
67
68
69
|
# File 'lib/core/config.rb', line 67
def image_link(image)
"/org/#{org}/image/#{image}"
end
|
#location ⇒ Object
59
60
61
|
# File 'lib/core/config.rb', line 59
def location
@location ||= load_location_from_options || load_location_from_env || load_location_from_file
end
|
#location_link ⇒ Object
63
64
65
|
# File 'lib/core/config.rb', line 63
def location_link
"/org/#{org}/location/#{location}"
end
|
#org ⇒ Object
31
32
33
|
# File 'lib/core/config.rb', line 31
def org
@org ||= load_org_from_options || load_org_from_env || load_org_from_file
end
|
#script_path ⇒ Object
83
84
85
|
# File 'lib/core/config.rb', line 83
def script_path
Pathname.new(__dir__).parent.parent
end
|
#secrets ⇒ Object
51
52
53
|
# File 'lib/core/config.rb', line 51
def secrets
current&.dig(:secrets_name) || "#{app_prefix}-secrets"
end
|
#secrets_policy ⇒ Object
55
56
57
|
# File 'lib/core/config.rb', line 55
def secrets_policy
current&.dig(:secrets_policy_name) || "#{secrets}-policy"
end
|
#should_app_start_with?(app_name) ⇒ Boolean
91
92
93
|
# File 'lib/core/config.rb', line 91
def should_app_start_with?(app_name)
apps[app_name.to_sym]&.dig(:match_if_app_name_starts_with) || false
end
|