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 +4 -4
- data/lib/helm-wrapper/common.rb +12 -1
- data/lib/helm-wrapper/shared/auths/azure.rb +5 -5
- data/lib/helm-wrapper/shared/auths/common.rb +1 -1
- data/lib/helm-wrapper/shared/config.rb +11 -45
- data/lib/helm-wrapper/shared/runner.rb +2 -4
- data/lib/helm-wrapper/shared/variables.rb +83 -10
- data/lib/helm-wrapper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 923aefc31c6e395f1dc27df249666f1d39b2a02c631b5a1b5393d1605a464e7f
|
4
|
+
data.tar.gz: 83b14577df977b0273399198e95fd5d978c64ed9ab4a9b3321026babf4f497cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f9f3b4fb138c405cad4a2f9c05111354d8f15f098f19da0d266d3e5c26592d857d81a8486580b6537045a02346a78ea305ea5a4bb83687341a35ed178270c9d
|
7
|
+
data.tar.gz: 6d43ad0934729dcdbd429e7746f37ebeefdc20b6c478d183e10223d658b6c0b9699fb977808c7fd176e71c052201d8b6ac202ee9e20fcec1be30e15e11d3401a
|
data/lib/helm-wrapper/common.rb
CHANGED
@@ -4,7 +4,7 @@ module HelmWrapper
|
|
4
4
|
|
5
5
|
###############################################################################
|
6
6
|
|
7
|
-
def self.create_directory(directory:,
|
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.
|
148
|
-
ca = ca % @variables.
|
149
|
-
endpoint = endpoint % @variables.
|
150
|
-
token = token % @variables.
|
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
|
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(
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
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.
|
186
|
-
result.append("--values=\"#{
|
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
|
-
@@
|
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(
|
28
|
-
|
29
|
-
|
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(
|
111
|
+
def cleanse(variables:, reserved:)
|
39
112
|
result = Hash.new
|
40
113
|
|
41
|
-
|
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
|
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
|
46
|
-
logger.fatal("Could not clean variables hash, value for: #{key.downcase} is empty!") if
|
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] =
|
121
|
+
result[key.downcase.to_sym] = variables[key].strip
|
49
122
|
end
|
50
123
|
|
51
124
|
return result
|
data/lib/helm-wrapper/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2021-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|