minfra-cli 4.1.1 → 4.3.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/CHANGELOG.md +9 -1
- data/lib/{minfra/cli/hiera_yaml_backend_patch.rb → hiera/backend/yeaml_backend.rb} +6 -4
- data/lib/minfra/cli/cli_starter.rb +23 -24
- data/lib/minfra/cli/errors.rb +2 -0
- data/lib/minfra/cli/hiera_looker.rb +7 -7
- data/lib/minfra/cli/patches.rb +9 -0
- data/lib/minfra/cli/templater.rb +2 -2
- data/lib/minfra/cli/version.rb +1 -1
- data/lib/minfra/cli.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3130c38b75f95a1e33c187d6b2026ef0eead6ae92855021ef8c52a3d47aefc28
|
4
|
+
data.tar.gz: fe0fbbfee11d712ae34668bd9c5f87696fbf7c08186b409f0e33baf1d24ec449
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b52d83585031a954c4db6a632322ecb3077936bed7ffa824d125e5ca6fb6341aead5abf1220671e9e17fcd6c7c0f541ea2a39405d541b51b5c1db11d9c8ffd1
|
7
|
+
data.tar.gz: 46aaa7a2acfe06a6fc190a21e5c7e0c391a55d503eda59618961b77f334203a1efa47d6c0ea337bdccbf2c22d255021ca1f148e9a23ae9f1863e543fa1748e27
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# 4.3.0
|
2
|
+
* raising EnvNotFound when the environment is not found
|
3
|
+
* instead of patching yaml we're introducing yeaml backend to lookup eyaml files without decryption
|
4
|
+
* fixing hiera setup so environment file is loaded first and merged into scope
|
5
|
+
# 4.2.0
|
6
|
+
* --no-rc don't load rc files
|
7
|
+
* MINFRA_DEBUG_HIERA_LOOKUPS=true also shows the results of the lookup
|
8
|
+
* adding some needed hiera patches
|
1
9
|
# 4.1.1
|
2
10
|
* fix: puts statement removed
|
3
11
|
# 4.1.0
|
@@ -26,7 +34,7 @@
|
|
26
34
|
* fixing: setup dev
|
27
35
|
* adding: colored errors and warnings
|
28
36
|
* change: wrapping hiera lookup errors of gpg
|
29
|
-
* adding:
|
37
|
+
* adding: MINFRA_DEBUG_HIERA_LOOKUPS=true
|
30
38
|
# 2.0.1
|
31
39
|
Refactorings
|
32
40
|
* installing into Kernel only when 'exec' not at 'init' time
|
@@ -1,13 +1,15 @@
|
|
1
|
+
require 'hiera/backend/yaml_backend'
|
2
|
+
# require 'debug'
|
1
3
|
class Hiera
|
2
4
|
module Backend
|
3
|
-
class Yaml_backend
|
4
|
-
|
5
|
+
class Yeaml_backend < Hiera::Backend::Yaml_backend
|
5
6
|
def lookup(key, scope, order_override, resolution_type, context)
|
6
7
|
answer = nil
|
7
8
|
found = false
|
8
9
|
|
9
|
-
Hiera.debug("Looking up #{key} in
|
10
|
-
Backend.datasourcefiles(:
|
10
|
+
Hiera.debug("Looking up #{key} in YEAML backend")
|
11
|
+
Backend.datasourcefiles(:yeaml, scope, Config[:yeaml][:extension] || "eyaml", order_override) do |source, yamlfile|
|
12
|
+
# debugger if scope['env']== "dev-on-premises" && ['cluster', 'env','lookup_options'].include?(key)
|
11
13
|
data = @cache.read_file(yamlfile, Hash) do |data|
|
12
14
|
YAML.load(data) || {}
|
13
15
|
end
|
@@ -27,9 +27,9 @@ module Minfra
|
|
27
27
|
|
28
28
|
init_logger
|
29
29
|
|
30
|
-
@logger.debug("Minfra: loglevel: #{@logger.level}, env: #{@config.orch_env}")
|
30
|
+
@logger.debug("Minfra: loglevel: #{@logger.level}, env: #{@config.orch_env}, options: #{@options.inspect}")
|
31
31
|
|
32
|
-
init_minfrarc
|
32
|
+
init_minfrarc unless @options[:norc]
|
33
33
|
init_envs
|
34
34
|
|
35
35
|
init_hiera
|
@@ -86,28 +86,23 @@ module Minfra
|
|
86
86
|
|
87
87
|
# will parse -e, --argv_file, --
|
88
88
|
def parse_global_options
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
if (idx = argv.index('--minfra_argv_file'))
|
97
|
-
@options[:argv_file] = @argv[idx + 1]
|
98
|
-
@argv.delete_at(idx)
|
99
|
-
@argv.delete_at(idx)
|
100
|
-
end
|
89
|
+
extract_option('-e', :env, 1)
|
90
|
+
extract_option('--minfra_argv_file', :argv_file, 1)
|
91
|
+
extract_option('--minfra_path', :base_path, 1)
|
92
|
+
extract_option('--no-rc', :norc)
|
93
|
+
end
|
101
94
|
|
102
|
-
|
103
|
-
|
104
|
-
|
95
|
+
def extract_option(name, sym, arity=0)
|
96
|
+
if idx = @argv.index(name)
|
97
|
+
if arity == 0
|
98
|
+
@options[sym] = true
|
99
|
+
else
|
100
|
+
@options[sym] = @argv[idx + 1]
|
101
|
+
@argv.delete_at(idx)
|
102
|
+
end
|
105
103
|
@argv.delete_at(idx)
|
106
104
|
end
|
107
|
-
|
108
|
-
@options
|
109
105
|
end
|
110
|
-
|
111
106
|
def init_minfrarc
|
112
107
|
# load minfrarc for configs
|
113
108
|
project_minfrarc_path = @config.base_path.join('config', 'minfrarc.rb')
|
@@ -149,15 +144,19 @@ module Minfra
|
|
149
144
|
env_path = config.project.dig(:minfra, :hiera, :env_path) || 'environments'
|
150
145
|
root = base_path.join('hiera')
|
151
146
|
root.join('hieradata',env_path).glob('*.eyaml').sort.each do |path|
|
152
|
-
|
153
|
-
@envs[
|
147
|
+
local_env_name = path.basename.sub(/(\..+)/,'').to_s
|
148
|
+
@envs[local_env_name]=Env.new(
|
154
149
|
hiera_root: root,
|
155
150
|
hiera_env_path: env_path,
|
156
|
-
name:
|
157
|
-
hiera_debug_lookups: ENV['MINFRA_DEBUG_HIERA_LOOKUPS'] == 'true',
|
151
|
+
name: local_env_name,
|
152
|
+
hiera_debug_lookups: ENV['MINFRA_DEBUG_HIERA_LOOKUPS'] == 'true' && env_name == local_env_name,
|
158
153
|
backends: ENV.fetch('MINFRA_HIERA_BACKENDS','').split(',')
|
159
154
|
)
|
160
155
|
end
|
156
|
+
unless @envs[@env_name]
|
157
|
+
@logger.error("Environment '#{@env_name}' not found")
|
158
|
+
raise Errors::EnvNotFound.new(@env_name)
|
159
|
+
end
|
161
160
|
@env = @envs[@env_name] # set the current env
|
162
161
|
end
|
163
162
|
|
data/lib/minfra/cli/errors.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'English'
|
4
|
+
# require 'debug'
|
4
5
|
module Minfra
|
5
6
|
module Cli
|
6
7
|
class HieraLooker
|
@@ -12,11 +13,10 @@ module Minfra
|
|
12
13
|
|
13
14
|
@hiera = Hiera.new(config: @root.join('hiera.yaml').to_s)
|
14
15
|
# 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
16
|
|
17
17
|
Hiera.logger = :noop
|
18
18
|
if backends && !backends.empty?
|
19
|
-
@hiera.config[:backends] = backends
|
19
|
+
@hiera.config[:backends] = backends
|
20
20
|
Hiera::Config.load_backends
|
21
21
|
end
|
22
22
|
|
@@ -25,17 +25,16 @@ module Minfra
|
|
25
25
|
raise("unknown environment #{@env_name}, I expect a file at #{hiera_main_path}") unless hiera_main_path.exist?
|
26
26
|
|
27
27
|
scope = { 'hieraroot' => @root.to_s, 'env' => @env_name }
|
28
|
+
# we have to do this first as the hierarchy definitions only are valid if with the env variables injected
|
29
|
+
node_scope = @hiera.lookup('env', {}, scope, nil, :priority)
|
30
|
+
@scope = scope.merge(node_scope)
|
28
31
|
|
29
32
|
@special_lookups = @hiera.lookup('lookup_options', {}, scope, nil, :priority)
|
30
|
-
|
31
|
-
node_scope = @hiera.lookup('env', {}, scope, nil, :deeper)
|
32
|
-
@scope = scope.merge(node_scope)
|
33
33
|
@debug_lookups = debug_lookups
|
34
|
+
debug("hiera: scope -> #{@scope}") if @debug_lookups
|
34
35
|
end
|
35
36
|
|
36
37
|
def l(value, default = nil)
|
37
|
-
debug "hiera: #{value}" if @debug_lookups
|
38
|
-
# debugger if @env_name == 'production-management' && value == 'env.tags'
|
39
38
|
return @cache[value] if @cache.key?(value)
|
40
39
|
|
41
40
|
values = value.split('.')
|
@@ -67,6 +66,7 @@ module Minfra
|
|
67
66
|
result = default if result.nil?
|
68
67
|
result = Hashie::Mash.new(result) if result.is_a?(Hash)
|
69
68
|
@cache[value] = result
|
69
|
+
debug "hiera: #{value} -> #{result.inspect}" if @debug_lookups
|
70
70
|
result
|
71
71
|
end
|
72
72
|
|
data/lib/minfra/cli/templater.rb
CHANGED
@@ -24,7 +24,7 @@ module Minfra
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.read(path, params: {}, fallback: nil)
|
27
|
+
def self.read(path, params: {}, helpers: [], fallback: nil)
|
28
28
|
p = Pathname.new(path)
|
29
29
|
if p.exist?
|
30
30
|
content = File.read(path)
|
@@ -34,7 +34,7 @@ module Minfra
|
|
34
34
|
content = fallback
|
35
35
|
|
36
36
|
end
|
37
|
-
render(content, params)
|
37
|
+
render(content, params, helpers: )
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.render(template, params, helpers: [])
|
data/lib/minfra/cli/version.rb
CHANGED
data/lib/minfra/cli.rb
CHANGED
@@ -7,6 +7,8 @@ require 'ostruct'
|
|
7
7
|
require 'hiera'
|
8
8
|
|
9
9
|
require_relative 'cli/core_ext'
|
10
|
+
require_relative 'cli/patches'
|
11
|
+
|
10
12
|
require_relative 'cli/errors'
|
11
13
|
require_relative 'cli/logging'
|
12
14
|
require_relative 'cli/templater'
|
@@ -49,6 +51,7 @@ module Minfra
|
|
49
51
|
end
|
50
52
|
|
51
53
|
def self.exec(argv)
|
54
|
+
|
52
55
|
init(argv) unless init?
|
53
56
|
cli.install
|
54
57
|
cli.run
|
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: 4.
|
4
|
+
version: 4.3.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-
|
11
|
+
date: 2024-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- exe/minfra
|
183
183
|
- lib/deep_merge.rb
|
184
184
|
- lib/hash.rb
|
185
|
+
- lib/hiera/backend/yeaml_backend.rb
|
185
186
|
- lib/minfra/cli.rb
|
186
187
|
- lib/minfra/cli/ask.rb
|
187
188
|
- lib/minfra/cli/cli_starter.rb
|
@@ -205,11 +206,11 @@ files:
|
|
205
206
|
- lib/minfra/cli/errors.rb
|
206
207
|
- lib/minfra/cli/helm_runner.rb
|
207
208
|
- lib/minfra/cli/hiera_looker.rb
|
208
|
-
- lib/minfra/cli/hiera_yaml_backend_patch.rb
|
209
209
|
- lib/minfra/cli/hook.rb
|
210
210
|
- lib/minfra/cli/kubectl_runner.rb
|
211
211
|
- lib/minfra/cli/logging.rb
|
212
212
|
- lib/minfra/cli/main_command.rb
|
213
|
+
- lib/minfra/cli/patches.rb
|
213
214
|
- lib/minfra/cli/plugin.rb
|
214
215
|
- lib/minfra/cli/plugins.rb
|
215
216
|
- lib/minfra/cli/runner.rb
|