Class: KY::EnvGeneration
- Inherits:
-
Object
- Object
- KY::EnvGeneration
- Defined in:
- lib/ky/env_generation.rb
Constant Summary collapse
- ConflictingProjectError =
Class.new(StandardError)
- OverlappingKeysInConfigmapAndSecretsError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#config_hsh ⇒ Object
readonly
Returns the value of attribute config_hsh.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#secret_hsh ⇒ Object
readonly
Returns the value of attribute secret_hsh.
Class Method Summary collapse
Instance Method Summary collapse
- #immutable_project_name ⇒ Object
-
#initialize(input1, input2, configuration = Configuration.new) ⇒ EnvGeneration
constructor
A new instance of EnvGeneration.
- #project ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(input1, input2, configuration = Configuration.new) ⇒ EnvGeneration
Returns a new instance of EnvGeneration.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ky/env_generation.rb', line 26 def initialize(input1, input2, configuration = Configuration.new) input_hashes = YAML.load(input1.read).with_indifferent_access, YAML.load(input2.read).with_indifferent_access @configuration = configuration @config_hsh = input_hashes.find {|h| h[kind] == config_map } @secret_hsh = input_hashes.find {|h| h[kind] == secret } secret_project = secret_hsh[][name] config_project = config_hsh[][name] input_hashes.each do |env_hsh| env_hsh[:metadata][:namespace] = configuration[:namespace] env_hsh[:metadata][:name] = immutable_project_name end raise ConflictingProjectError.new("Config and Secret metadata names do not agree") unless secret_project == config_project intersection = config_hsh[data].keys & secret_hsh[data].keys raise OverlappingKeysInConfigmapAndSecretsError.new(intersection) unless intersection.empty? end |
Instance Attribute Details
#config_hsh ⇒ Object (readonly)
Returns the value of attribute config_hsh.
25 26 27 |
# File 'lib/ky/env_generation.rb', line 25 def config_hsh @config_hsh end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
25 26 27 |
# File 'lib/ky/env_generation.rb', line 25 def configuration @configuration end |
#secret_hsh ⇒ Object (readonly)
Returns the value of attribute secret_hsh.
25 26 27 |
# File 'lib/ky/env_generation.rb', line 25 def secret_hsh @secret_hsh end |
Class Method Details
.env(output, input1, input2) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ky/env_generation.rb', line 14 def self.env(output, input1, input2) output << generate_env(input1, input2).to_plain_yaml rescue ConflictingProjectError => e $stderr << "Error processing yml files, please provide a config and a secrets file from the same kubernetes project/name" exit(1) end |
.generate_env(input1, input2) ⇒ Object
21 22 23 |
# File 'lib/ky/env_generation.rb', line 21 def self.generate_env(input1, input2) new(input1, input2).to_h end |
Instance Method Details
#immutable_project_name ⇒ Object
51 52 53 |
# File 'lib/ky/env_generation.rb', line 51 def immutable_project_name project + env_suffix end |
#project ⇒ Object
47 48 49 |
# File 'lib/ky/env_generation.rb', line 47 def project @name ||= config_hsh[][name] end |
#to_h ⇒ Object
43 44 45 |
# File 'lib/ky/env_generation.rb', line 43 def to_h output_hash(config_hsh[data].map {|key, value| config_env(key, value) } + secret_hsh[data].map {|key, value| secret_env(key, value) } + force_config) end |