minfra-cli 3.0.2 → 4.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: 92da9781782e7ba198def006e419ccdcdd1fd09ebec4c3850b7aa6f8c49df1c2
4
- data.tar.gz: 45d9cacec937e7a3f54e9c728ccec7162f74425cfb2b6ad9994ef910d31491fa
3
+ metadata.gz: 6f3b63b9c6e391715e568fed4c5e113a7574afc4d8944b78bbed9b0a8f1fed28
4
+ data.tar.gz: 915a61225192f2f2d306b3736f02c5573e737932a7bab2ccdc64dffb6108eda1
5
5
  SHA512:
6
- metadata.gz: a7c643f8620a6f35877a38cd2e7b0c2b01c72404c13fc959ad786c362c45991df8b4c8a5bb701f21453646ce81cb7e22c3b3ccddea468e1e58ac8ada595e45c4
7
- data.tar.gz: 041023473c66e0debd3e0f549e137795b532d1275d7fc31c4217ce6da7a2b108b78e30bcc04137a68e9019e2502e6d2f69960fd76f0123d2a5dbafbdcfc85a5e
6
+ metadata.gz: c8cea1d91de6744dd40eb6ae3d841b95fc0890723c953f9ac2af27b5c1e0e22af13be7bb1fc996bdd552cca9e1488e9eed24ae0f0c4d4479d97eb8a31ffd052a
7
+ data.tar.gz: 2d427efb9533341b778d700f44d5f7596972331a4cb8e0f2beb6e23af83cad67ce36445102bd5de9251de9d0be16941772de4dfa2475918c42372b50d7d277ce
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 4.0.0
2
+ * in apply mode of secrets we prefix the name with the chart name
3
+ # 3.1.0
4
+ * overriding backends via MINFRA_HIERA_BACKENDS
5
+ * overriding Yaml Backend to allow :extension: setting
1
6
  # 3.0.2
2
7
  * removing complex dns manipulation and hardcoding google servers
3
8
  # 3.0.1
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(hiera_root: root, hiera_env_path: env_path, name: env_name, hiera_debug_lookups: ENV['MINFRA_DEBUG_HIERA_LOOKUPS'] == 'true')
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
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Minfra
4
4
  module Cli
5
- VERSION = '3.0.2'
5
+ VERSION = '4.0.0'
6
6
  end
7
7
  end
@@ -390,7 +390,7 @@ module Orchparty
390
390
  result = ServiceBuilder.build(name, 'apply', block)
391
391
  file = Tempfile.create(name)
392
392
  result.tmp_file = file.path
393
- file.puts "apiVersion: v1\nkind: Secret\nmetadata:\n name: #{name}\ntype: Opaque\ndata:"
393
+ file.puts "apiVersion: v1\nkind: Secret\nmetadata:\n name: #{@node.name}-#{name}\ntype: Opaque\ndata:"
394
394
  result._.each do |key, value|
395
395
  file.puts " #{key}: #{Base64.strict_encode64(value.respond_to?(:call) ? value.call : value)}"
396
396
  end
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.2
4
+ version: 4.0.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-07 00:00:00.000000000 Z
11
+ date: 2024-03-27 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