minfra-cli 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/minfra/cli/cli_starter.rb +7 -1
- data/lib/minfra/cli/env.rb +3 -2
- data/lib/minfra/cli/hiera_looker.rb +8 -1
- data/lib/minfra/cli/hiera_yaml_backend_patch.rb +50 -0
- data/lib/minfra/cli/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57af73071c5c324ef7f908176a695c2cbdee6d2a1be1d65f6d0b9a9055c10aa4
|
4
|
+
data.tar.gz: 45e45f3bc0766a8fe6354f3b036bcb3327a4c79df5c1026a9e84d3f8314b8b37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 242cdcc9c027b110adc0fc0c3615de37a627888a594b8104212c9631530c99d7b8fafcc1ab5f3bd7808cc08af53c988b309394583c6abf4a40b7b49b25c9318e
|
7
|
+
data.tar.gz: 286be675ceb5ad1839d5c500fb2e23219fa7dbce860dbe1308f5d884e0c350898b541de1288088e2330b46b1022f93786ca925d8bff608b5cf903737350d090e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Is a KIND (k8s in docker) based development environment.
|
|
17
17
|
| | | default_stacks | | env.stacks or env.roles |
|
18
18
|
| | | | | infra::allow_insecure_k8s_connections |
|
19
19
|
| when set to 'true' all hiera lookups are logged on debug level | MINFRA_DEBUG_HIERA_LOOKUPS | | | |
|
20
|
-
|
20
|
+
| to override the backends in the hiera file, comma separated | MINFRA_HIERA_BACKENDS | | | |
|
21
21
|
|
22
22
|
## Expected hiera data
|
23
23
|
|
@@ -150,7 +150,13 @@ module Minfra
|
|
150
150
|
root = base_path.join('hiera')
|
151
151
|
root.join('hieradata',env_path).glob('*.eyaml').sort.each do |path|
|
152
152
|
env_name = path.basename.sub(/(\..+)/,'').to_s
|
153
|
-
@envs[env_name]=Env.new(
|
153
|
+
@envs[env_name]=Env.new(
|
154
|
+
hiera_root: root,
|
155
|
+
hiera_env_path: env_path,
|
156
|
+
name: env_name,
|
157
|
+
hiera_debug_lookups: ENV['MINFRA_DEBUG_HIERA_LOOKUPS'] == 'true',
|
158
|
+
backends: ENV.fetch('MINFRA_HIERA_BACKENDS','').split(',')
|
159
|
+
)
|
154
160
|
end
|
155
161
|
@env = @envs[@env_name] # set the current env
|
156
162
|
end
|
data/lib/minfra/cli/env.rb
CHANGED
@@ -2,13 +2,14 @@ module Minfra
|
|
2
2
|
module Cli
|
3
3
|
class Env
|
4
4
|
attr_reader :name, :hiera
|
5
|
-
def initialize(name:, hiera_root:, hiera_env_path:, hiera_debug_lookups: )
|
5
|
+
def initialize(name:, hiera_root:, hiera_env_path:, hiera_debug_lookups:, backends: )
|
6
6
|
@name = name
|
7
7
|
@hiera = HieraLooker.new(
|
8
8
|
root: hiera_root,
|
9
9
|
env_name: name,
|
10
10
|
env_path: hiera_env_path,
|
11
|
-
debug_lookups: hiera_debug_lookups
|
11
|
+
debug_lookups: hiera_debug_lookups,
|
12
|
+
backends: backends
|
12
13
|
)
|
13
14
|
end
|
14
15
|
|
@@ -5,13 +5,20 @@ module Minfra
|
|
5
5
|
module Cli
|
6
6
|
class HieraLooker
|
7
7
|
include Logging
|
8
|
-
def initialize(root:, env_name:, env_path:, debug_lookups: false)
|
8
|
+
def initialize(root:, env_name:, env_path:, debug_lookups: false, backends: nil)
|
9
9
|
@root = Pathname.new(root)
|
10
10
|
@env_name = env_name
|
11
11
|
@cache = {}
|
12
12
|
|
13
13
|
@hiera = Hiera.new(config: @root.join('hiera.yaml').to_s)
|
14
|
+
# now that hiera has loaded the backends let's patch 'em
|
15
|
+
require 'minfra/cli/hiera_yaml_backend_patch' if defined?(Hiera::Backend::Yaml_backend)
|
16
|
+
|
14
17
|
Hiera.logger = :noop
|
18
|
+
if backends && !backends.empty?
|
19
|
+
@hiera.config[:backends] = backends
|
20
|
+
Hiera::Config.load_backends
|
21
|
+
end
|
15
22
|
|
16
23
|
hiera_main_path = @root.join("hieradata/#{env_path}/#{env_name}.eyaml")
|
17
24
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Hiera
|
2
|
+
module Backend
|
3
|
+
class Yaml_backend
|
4
|
+
|
5
|
+
def lookup(key, scope, order_override, resolution_type, context)
|
6
|
+
answer = nil
|
7
|
+
found = false
|
8
|
+
|
9
|
+
Hiera.debug("Looking up #{key} in YAML backend")
|
10
|
+
Backend.datasourcefiles(:yaml, scope, Config[:yaml][:extension] || "yaml", order_override) do |source, yamlfile|
|
11
|
+
data = @cache.read_file(yamlfile, Hash) do |data|
|
12
|
+
YAML.load(data) || {}
|
13
|
+
end
|
14
|
+
|
15
|
+
next if data.empty?
|
16
|
+
next unless data.include?(key)
|
17
|
+
found = true
|
18
|
+
|
19
|
+
# Extra logging that we found the key. This can be outputted
|
20
|
+
# multiple times if the resolution type is array or hash but that
|
21
|
+
# should be expected as the logging will then tell the user ALL the
|
22
|
+
# places where the key is found.
|
23
|
+
Hiera.debug("Found #{key} in #{source}")
|
24
|
+
|
25
|
+
# for array resolution we just append to the array whatever
|
26
|
+
# we find, we then goes onto the next file and keep adding to
|
27
|
+
# the array
|
28
|
+
#
|
29
|
+
# for priority searches we break after the first found data item
|
30
|
+
new_answer = Backend.parse_answer(data[key], scope, {}, context)
|
31
|
+
case resolution_type.is_a?(Hash) ? :hash : resolution_type
|
32
|
+
when :array
|
33
|
+
raise Exception, "Hiera type mismatch for key '#{key}': expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
|
34
|
+
answer ||= []
|
35
|
+
answer << new_answer
|
36
|
+
when :hash
|
37
|
+
raise Exception, "Hiera type mismatch for key '#{key}': expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
|
38
|
+
answer ||= {}
|
39
|
+
answer = Backend.merge_answer(new_answer, answer, resolution_type)
|
40
|
+
else
|
41
|
+
answer = new_answer
|
42
|
+
break
|
43
|
+
end
|
44
|
+
end
|
45
|
+
throw :no_such_key unless found
|
46
|
+
return answer
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/minfra/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minfra-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Schrammel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- lib/minfra/cli/errors.rb
|
206
206
|
- lib/minfra/cli/helm_runner.rb
|
207
207
|
- lib/minfra/cli/hiera_looker.rb
|
208
|
+
- lib/minfra/cli/hiera_yaml_backend_patch.rb
|
208
209
|
- lib/minfra/cli/hook.rb
|
209
210
|
- lib/minfra/cli/kubectl_runner.rb
|
210
211
|
- lib/minfra/cli/logging.rb
|