helm-wrapper 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 453b628d2ec6b587d545ae37bf7958c3d2937e811365a9cd78713cb37f68c22b
4
- data.tar.gz: b2444e0d7631d04086b36daa0ff5bb5c99389b4164c3d65260110715a3e56823
3
+ metadata.gz: 923aefc31c6e395f1dc27df249666f1d39b2a02c631b5a1b5393d1605a464e7f
4
+ data.tar.gz: 83b14577df977b0273399198e95fd5d978c64ed9ab4a9b3321026babf4f497cf
5
5
  SHA512:
6
- metadata.gz: c66d59f3616769bc87932c01d21bd84541a8b9599bd7403cc66d91add83917701ebc6d545f6fc9b115b34e105b4790a60563cf200d12541d732e86e28dbe25e8
7
- data.tar.gz: 2882c132e00fda70acd0b1a1bccefe6c831d245cbad896d51a61c072ebf8f8836128f3e9856e837de28b3c5c22ac747205a20524aa225ac3cd772dbb4f6c9a46
6
+ metadata.gz: 4f9f3b4fb138c405cad4a2f9c05111354d8f15f098f19da0d266d3e5c26592d857d81a8486580b6537045a02346a78ea305ea5a4bb83687341a35ed178270c9d
7
+ data.tar.gz: 6d43ad0934729dcdbd429e7746f37ebeefdc20b6c478d183e10223d658b6c0b9699fb977808c7fd176e71c052201d8b6ac202ee9e20fcec1be30e15e11d3401a
@@ -4,7 +4,7 @@ module HelmWrapper
4
4
 
5
5
  ###############################################################################
6
6
 
7
- def self.create_directory(directory:, purpose: nil, exists: true)
7
+ def self.create_directory(directory:, exists: true, purpose: nil)
8
8
  return exists if File.directory?(directory)
9
9
 
10
10
  result = false
@@ -20,6 +20,17 @@ module HelmWrapper
20
20
  result = File.directory?(directory)
21
21
  end
22
22
 
23
+ ###############################################################################
24
+
25
+ def self.find(base:, name:, exts:, description: "File")
26
+ exts.each do |ext|
27
+ path = File.join(base, name + ext)
28
+ return path if File.file?(path)
29
+ end
30
+
31
+ @logger.fatal("#{description} name: #{name} not found in location: #{base}!")
32
+ end
33
+
23
34
  ###############################################################################
24
35
 
25
36
  end
@@ -144,12 +144,12 @@ module HelmWrapper
144
144
  end
145
145
 
146
146
  begin
147
- keyvault = keyvault % @variables.values
148
- ca = ca % @variables.values
149
- endpoint = endpoint % @variables.values
150
- token = token % @variables.values
147
+ keyvault = keyvault % @variables.identifiers
148
+ ca = ca % @variables.identifiers
149
+ endpoint = endpoint % @variables.identifiers
150
+ token = token % @variables.identifiers
151
151
  rescue
152
- logger.fatal("Azure authenticator options contain variables that are not included in the configuration file!")
152
+ logger.fatal("Azure authenticator options contain identifiers that are not included in the configuration file!")
153
153
  end
154
154
 
155
155
  @ca = secret(vault: keyvault, name: ca)
@@ -29,7 +29,7 @@ module HelmWrapper
29
29
 
30
30
  ###############################################################################
31
31
 
32
- def initialize(code:, config:, options:, service:, variables:)
32
+ def initialize(options:, variables:)
33
33
  logger.fatal("This class should not be used directly! Please create an authenticator-specific class instead!")
34
34
  end
35
35
 
@@ -22,11 +22,6 @@ module HelmWrapper
22
22
 
23
23
  @@config_exts = [ "", ".yaml", ".yml" ]
24
24
 
25
- ###############################################################################
26
-
27
- @@variable_files_name = "helmvars"
28
- @@variable_files_exts = [ ".yaml", ".yml" ]
29
-
30
25
  ###############################################################################
31
26
 
32
27
  attr_reader :auths
@@ -36,7 +31,6 @@ module HelmWrapper
36
31
  attr_reader :namespace
37
32
  attr_reader :path
38
33
  attr_reader :release
39
- attr_reader :variable_files
40
34
  attr_reader :variables
41
35
 
42
36
  ###############################################################################
@@ -71,19 +65,22 @@ module HelmWrapper
71
65
  auth_azure_options = options["auth-azure-options"]
72
66
 
73
67
  @chart = chart
74
- @path = find(base: @base, name: @name, exts: @@config_exts, description: "Configuration")
68
+ @path = ::HelmWrapper.find(base: @base, name: @name, exts: @@config_exts, description: "Configuration")
75
69
 
76
70
  yaml = YAML.load(File.read(@path))
77
71
  logger.fatal("Invalid YAML in configuration file: #{@path}") unless yaml.kind_of?(Hash)
78
72
 
79
- if yaml.key?("variables") then
80
- logger.fatal("Key 'variables' is not a hash in configuration file: #{@path}") unless yaml["variables"].kind_of?(Hash)
81
- @variables = HelmWrapper::Shared::Variables.new(values: yaml["variables"])
82
- else
83
- @variables = HelmWrapper::Shared::Variables.new()
84
- end
73
+ identifers = yaml.key?("identifiers") ? yaml["identifiers"] : Hash.new
74
+ @variables = HelmWrapper::Shared::Variables.new(chart: @chart.name, config: @name, namespace: namespace, release: release, identifiers: identifers)
75
+ @variables.add_variables(variables: yaml["globals"]) if yaml.key?("globals")
76
+
77
+ if yaml.key?("helm") then
78
+ logger.fatal("Key 'helm' is not a hash in configuration file: #{@path}") unless yaml["helm"].kind_of?(Hash)
79
+ helm = yaml["helm"]
85
80
 
86
- @variable_files = yaml.key?("helm") ? validate(variable_files: yaml["helm"]) : Array.new
81
+ @variables.add_variables(variables: helm["variables"]) if helm.key?("variables")
82
+ @variables.add_files(base: @base, files: helm["files"]) if helm.key?("files")
83
+ end
87
84
 
88
85
  begin
89
86
  namespace = namespace % @variables.values
@@ -99,37 +96,6 @@ module HelmWrapper
99
96
  @auths.append(HelmWrapper::Shared::Auths::Azure.new(options: auth_azure_options, variables: @variables)) if auth_azure
100
97
  end
101
98
 
102
- ###############################################################################
103
-
104
- private
105
-
106
- ###############################################################################
107
-
108
- def find(base:, name:, exts:, description: "File")
109
- exts.each do |ext|
110
- path = File.join(base, name + ext)
111
- return path if File.file?(path)
112
- end
113
-
114
- logger.fatal("#{description} name: #{@name} not found in location: #{@base}!")
115
- end
116
-
117
- ###############################################################################
118
-
119
- def validate(variable_files:)
120
- logger.fatal("Optional key 'variable_files' must be a list of strings!") unless variable_files.kind_of?(Array)
121
-
122
- result = Array.new
123
-
124
- variable_files.each do |variable_file|
125
- logger.fatal("All elements of 'helm' must be strings!") unless variable_file.kind_of?(String)
126
- logger.fatal("All elements of 'helm' must not be blank!") if variable_file.strip.empty?
127
- result.append(find(base: File.join(@base, @@variable_files_name), name: variable_file.strip, exts: @@variable_files_exts, description: "Helm values file"))
128
- end
129
-
130
- return result
131
- end
132
-
133
99
  ###############################################################################
134
100
 
135
101
  end
@@ -182,8 +182,8 @@ module HelmWrapper
182
182
  def variable_files
183
183
  result = Array.new
184
184
 
185
- @config.variable_files.each do |variable_file|
186
- result.append("--values=\"#{variable_file}\"")
185
+ @config.variables.files.each do |file|
186
+ result.append("--values=\"#{file}\"")
187
187
  end
188
188
 
189
189
  return result
@@ -194,8 +194,6 @@ module HelmWrapper
194
194
  def variable_strings
195
195
  result = Array.new
196
196
 
197
- result.append("--set=\"config=#{@config.name}\"")
198
-
199
197
  @config.variables.values.each do |key, value|
200
198
  result.append("--set=\"#{key.to_s}=#{value}\"")
201
199
  end
@@ -16,36 +16,109 @@ module HelmWrapper
16
16
 
17
17
  ###############################################################################
18
18
 
19
- @@reserved = [ "chart" ]
19
+ @@variable_files_name = "helmvars"
20
+ @@variable_files_exts = [ ".yaml", ".yml" ]
20
21
 
21
22
  ###############################################################################
22
23
 
24
+ attr_reader :core
25
+ attr_reader :files
26
+ attr_reader :identifiers
23
27
  attr_reader :values
24
28
 
25
29
  ###############################################################################
26
30
 
27
- def initialize(values: Hash.new, sort: true)
28
- cleansed = cleanse(values: values)
29
- @values = sort ? cleansed.sort.to_h : cleansed
31
+ def initialize(chart:, config:, namespace:, release:, identifiers: Hash.new, sort: false)
32
+ logger.fatal("Identifiers provided must be a hash!") unless identifiers.kind_of?(Hash)
33
+
34
+ core = Hash.new()
35
+ core[:chart] = chart
36
+ core[:config] = config
37
+ core[:namespace] = nil
38
+ core[:release] = nil
39
+
40
+ user = cleanse(variables: identifiers, reserved: core.keys)
41
+
42
+ begin
43
+ core[:namespace] = namespace % user
44
+ core[:release] = release % user
45
+ rescue
46
+ logger.fatal("Provided configuration options include identifiers that are not included in the configuration file!")
47
+ end
48
+
49
+ merged = core.merge(user)
50
+
51
+ @core = core
52
+ @identifiers = sort ? merged.sort.to_h : merged
53
+ @values = @identifiers
54
+ @files = Array.new
55
+ end
56
+
57
+ ###############################################################################
58
+
59
+ def add_files(base:, files:)
60
+ logger.fatal("Variable files provided must be an array!") unless files.kind_of?(Array)
61
+
62
+ files.each do |file|
63
+ logger.fatal("All provided variable file names must be strings!") unless file.kind_of?(String)
64
+ logger.fatal("All provided variable file names must not be blank!") if file.strip.empty?
65
+
66
+ path = ::HelmWrapper.find(base: File.join(base, @@variable_files_name), name: file.strip, exts: @@variable_files_exts, description: "Helm values file")
67
+
68
+ if @files.include?(path) then
69
+ logger.warn("Helm variables file is included more than once: #{file.strip}")
70
+ else
71
+ @files.append(path)
72
+ end
73
+ end
30
74
  end
31
75
 
32
76
  ###############################################################################
33
77
 
78
+ def add_variables(variables:, sort: false)
79
+ logger.fatal("Variables provided must be a hash!") unless variables.kind_of?(Hash)
80
+
81
+ cleansed = cleanse(variables: variables, reserved: @values.keys)
82
+
83
+ begin
84
+ cleansed = cleansed.map{ |key, value| [ key, value % @identifiers ] }.to_h
85
+ rescue
86
+ logger.fatal("Variables contain identifiers that are not included in the configuration file!")
87
+ end
88
+
89
+ merged = @values.merge(cleansed)
90
+ @values = sort ? merged.sort.to_h : merged
91
+ end
92
+
93
+ ###############################################################################
94
+
95
+ def clear_files()
96
+ @files = Array.new
97
+ end
98
+
99
+ ###############################################################################
100
+
101
+ def clear_variables()
102
+ @values = @identifers
103
+ end
104
+
105
+ ###############################################################################
106
+
34
107
  private
35
108
 
36
109
  ###############################################################################
37
110
 
38
- def cleanse(values:)
111
+ def cleanse(variables:, reserved:)
39
112
  result = Hash.new
40
113
 
41
- values.keys.each do |key|
114
+ variables.keys.each do |key|
42
115
  logger.fatal("Could not clean variables hash. All keys MUST be strings!") unless key.kind_of?(String)
43
- logger.fatal("Could not clean variables hash, key: #{key.downcase} is reserved and cannot be used!") if @@reserved.include?(key.downcase)
116
+ logger.fatal("Could not clean variables hash, key: #{key.downcase} is reserved or already in use and cannot be used!") if reserved.include?(key.downcase.to_sym)
44
117
  logger.fatal("Could not clean variables hash, duplicate key found: #{key.downcase}!") if result.key?(key.downcase.to_sym)
45
- logger.fatal("Could not clean variables hash, value for: #{key.downcase} is not a string!") unless values[key].kind_of?(String)
46
- logger.fatal("Could not clean variables hash, value for: #{key.downcase} is empty!") if values[key].strip.empty?
118
+ logger.fatal("Could not clean variables hash, value for: #{key.downcase} is not a string!") unless variables[key].kind_of?(String)
119
+ logger.fatal("Could not clean variables hash, value for: #{key.downcase} is empty!") if variables[key].strip.empty?
47
120
 
48
- result[key.downcase.to_sym] = values[key].strip
121
+ result[key.downcase.to_sym] = variables[key].strip
49
122
  end
50
123
 
51
124
  return result
@@ -4,7 +4,7 @@ module HelmWrapper
4
4
 
5
5
  ###############################################################################
6
6
 
7
- VERSION = "0.1.1"
7
+ VERSION = "1.0.0"
8
8
 
9
9
  ###############################################################################
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helm-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lees
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-05 00:00:00.000000000 Z
11
+ date: 2021-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake