minfra-cli 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -1
- data/README.md +3 -1
- data/lib/minfra/cli/ask.rb +1 -0
- data/lib/minfra/cli/cli_starter.rb +3 -2
- data/lib/minfra/cli/commands/setup.rb +0 -2
- data/lib/minfra/cli/common.rb +0 -8
- data/lib/minfra/cli/env.rb +3 -2
- data/lib/minfra/cli/hiera_looker.rb +20 -5
- data/lib/minfra/cli/hook.rb +4 -0
- data/lib/minfra/cli/logging.rb +11 -3
- data/lib/minfra/cli/runner.rb +11 -7
- data/lib/minfra/cli/templater.rb +2 -2
- data/lib/minfra/cli/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5429a3e13b8387b6c3e011eaa2513ac5963ef30c4a14f9458e882a7df0507753
|
4
|
+
data.tar.gz: 2dbdd6e4e0f4c3cbade95033f52af2480a7a0b421508a68066e1a87ab6049109
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 188ce70ec6fabf9b6d72ddfc0855ce499e63c92bc079d525e044dec3c21b49d5a6c2aba1576a869c5126ef3a27f14bc7aa1e7222b1deff49e8cc35c645cda621
|
7
|
+
data.tar.gz: 877789c92138b28e33314592464fc5650765729a90ea8d84388c9ca10ea4065dd5988fbfbc9b047ebf0604d28552e38243d5407a52ee7cf9ae18f03b075b8e19
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 2.1.0
|
2
|
+
* add :all hook
|
3
|
+
* fixing setup dev
|
4
|
+
* colored errors
|
5
|
+
* wrapping hiera lookup errors of gpg
|
6
|
+
* adding HIERA_DEBUG_LOOKUPS=true
|
1
7
|
# 2.0.1
|
2
8
|
Refactorings
|
3
9
|
* installing into Kernel only when 'exec' not at 'init' time
|
@@ -17,7 +23,7 @@
|
|
17
23
|
* new Kernel method: minfra_cli which is the CliStarter Object
|
18
24
|
|
19
25
|
# 1.13.3
|
20
|
-
* BUG: fixing '
|
26
|
+
* BUG: fixing 'label'
|
21
27
|
# 1.13.2
|
22
28
|
* BUG: fixing 'generic_secret'
|
23
29
|
# 1.13.1
|
data/README.md
CHANGED
@@ -14,7 +14,9 @@ Is a KIND (k8s in docker) based development environment.
|
|
14
14
|
| | MINFRA_ARGV_FILE | | --minfra_argv_file [PATH TO A CSV FILE FILE] | |
|
15
15
|
| | MINFRA_LOGGING_LEVEL | minfra.logging_level | | |
|
16
16
|
| | | minfra.hiera.env_path | | |
|
17
|
-
| | | default_stacks | | env.stacks
|
17
|
+
| | | default_stacks | | env.stacks or env.roles |
|
18
|
+
| | | | | infra::allow_insecure_k8s_connections |
|
19
|
+
| when set to 'true' all hiera lookups are logged on debug level | MINFRA_DEBUG_HIERA_LOOKUPS | | | |
|
18
20
|
|
19
21
|
|
20
22
|
## Expected hiera data
|
data/lib/minfra/cli/ask.rb
CHANGED
@@ -31,6 +31,7 @@ module Minfra
|
|
31
31
|
|
32
32
|
init_minfrarc
|
33
33
|
init_envs
|
34
|
+
|
34
35
|
init_hiera
|
35
36
|
init_plugins
|
36
37
|
|
@@ -140,7 +141,7 @@ module Minfra
|
|
140
141
|
end
|
141
142
|
|
142
143
|
def init_hiera
|
143
|
-
@hiera = @env.hiera
|
144
|
+
@hiera = @env.hiera
|
144
145
|
end
|
145
146
|
|
146
147
|
def init_envs
|
@@ -149,7 +150,7 @@ module Minfra
|
|
149
150
|
root = base_path.join('hiera')
|
150
151
|
root.join('hieradata',env_path).glob('*.eyaml').sort.each do |path|
|
151
152
|
env_name = path.basename.sub(/(\..+)/,'').to_s
|
152
|
-
@envs[env_name]=Env.new(hiera_root: root, hiera_env_path: env_path, name: env_name)
|
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
154
|
end
|
154
155
|
@env = @envs[@env_name] # set the current env
|
155
156
|
end
|
@@ -18,8 +18,6 @@ module Minfra
|
|
18
18
|
def setup_config
|
19
19
|
config = Minfra::Cli.config
|
20
20
|
ensure_path_and_template(config.config_path, config.base_path.join('config', 'me_config.json.erb'))
|
21
|
-
config.init!
|
22
|
-
config.load('dev')
|
23
21
|
end
|
24
22
|
|
25
23
|
def ensure_path_and_template(dest_path, template_path, params = {})
|
data/lib/minfra/cli/common.rb
CHANGED
@@ -25,14 +25,6 @@ module Minfra
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def parse_cmd(cmd, silence: false)
|
29
|
-
reply = JSON.parse(run_cmd(cmd, silence:))
|
30
|
-
rescue JSON::ParserError, TypeError
|
31
|
-
error "ERROR: #{$ERROR_INFO.message}"
|
32
|
-
error reply
|
33
|
-
error "command was: #{cmd}"
|
34
|
-
exit 1
|
35
|
-
end
|
36
28
|
end
|
37
29
|
end
|
38
30
|
end
|
data/lib/minfra/cli/env.rb
CHANGED
@@ -2,12 +2,13 @@ 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:)
|
5
|
+
def initialize(name:, hiera_root:, hiera_env_path:, hiera_debug_lookups: )
|
6
6
|
@name = name
|
7
7
|
@hiera = HieraLooker.new(
|
8
8
|
root: hiera_root,
|
9
9
|
env_name: name,
|
10
|
-
env_path: hiera_env_path
|
10
|
+
env_path: hiera_env_path,
|
11
|
+
debug_lookups: hiera_debug_lookups
|
11
12
|
)
|
12
13
|
end
|
13
14
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'English'
|
3
4
|
module Minfra
|
4
5
|
module Cli
|
5
6
|
class HieraLooker
|
6
|
-
|
7
|
+
include Logging
|
8
|
+
def initialize(root:, env_name:, env_path:, debug_lookups: false)
|
7
9
|
@root = Pathname.new(root)
|
8
10
|
@env_name = env_name
|
9
11
|
@cache = {}
|
@@ -18,13 +20,15 @@ module Minfra
|
|
18
20
|
scope = { 'hieraroot' => @root.to_s, 'env' => @env_name }
|
19
21
|
|
20
22
|
@special_lookups = @hiera.lookup('lookup_options', {}, scope, nil, :priority)
|
21
|
-
|
23
|
+
|
22
24
|
node_scope = @hiera.lookup('env', {}, scope, nil, :deeper)
|
23
25
|
@scope = scope.merge(node_scope)
|
26
|
+
@debug_lookups = debug_lookups
|
24
27
|
end
|
25
28
|
|
26
29
|
def l(value, default = nil)
|
27
|
-
|
30
|
+
debug "hiera: #{value}" if @debug_lookups
|
31
|
+
# debugger if @env_name == 'production-management' && value == 'env.tags'
|
28
32
|
return @cache[value] if @cache.key?(value)
|
29
33
|
|
30
34
|
values = value.split('.')
|
@@ -35,7 +39,18 @@ module Minfra
|
|
35
39
|
else
|
36
40
|
:deep
|
37
41
|
end
|
38
|
-
|
42
|
+
begin
|
43
|
+
result = @hiera.lookup(fst_value, default, @scope, nil, lookup_type)
|
44
|
+
rescue GPGME::Error::NoSecretKey
|
45
|
+
error("Have no gpg configuration to decrypt your hiera key: #{value}")
|
46
|
+
raise Errors::ExitError
|
47
|
+
rescue GPGME::Error::BadPassphrase
|
48
|
+
error("Your password was wrong for hiera key: #{value}")
|
49
|
+
raise Errors::ExitError
|
50
|
+
rescue GPGME::Error
|
51
|
+
error("Having decrypt problems for hiera key: #{value}, #{$ERROR_INFO.message}")
|
52
|
+
raise Errors::ExitError
|
53
|
+
end
|
39
54
|
result = result.dig(*values) if !values.empty? && result.is_a?(Hash) # we return nil or the scalar value and only drill down on hashes
|
40
55
|
result = default if result.nil?
|
41
56
|
result = Hashie::Mash.new(result) if result.is_a?(Hash)
|
@@ -46,9 +61,9 @@ module Minfra
|
|
46
61
|
def l!(value, default = nil)
|
47
62
|
v = l(value, default)
|
48
63
|
raise("Value not found! #{value}") if v.nil?
|
64
|
+
|
49
65
|
v
|
50
66
|
end
|
51
|
-
|
52
67
|
end
|
53
68
|
end
|
54
69
|
end
|
data/lib/minfra/cli/hook.rb
CHANGED
@@ -12,9 +12,12 @@ class Thor
|
|
12
12
|
elsif public_method?(instance)
|
13
13
|
hooks = instance.instance_variable_get(:@_invocations).values.flatten
|
14
14
|
arity = instance.method(name).arity
|
15
|
+
Minfra::Cli.call_before_hooks(instance, ['all']) if hooks.size == 1
|
15
16
|
Minfra::Cli.call_before_hooks(instance, hooks)
|
17
|
+
# debugger
|
16
18
|
instance.__send__(name, *args)
|
17
19
|
Minfra::Cli.call_after_hooks(instance, hooks)
|
20
|
+
Minfra::Cli.call_after_hooks(instance, ['all']) if hooks.size == 1
|
18
21
|
elsif local_method?(instance, :method_missing)
|
19
22
|
# Minfra::Cli.call_before_hooks(instance,hooks)
|
20
23
|
instance.__send__(:method_missing, name.to_sym, *args)
|
@@ -77,6 +80,7 @@ module Minfra
|
|
77
80
|
end
|
78
81
|
|
79
82
|
def call_after_hooks(obj, names)
|
83
|
+
# debug("Checking after hook #{names}")
|
80
84
|
@hooks.select { |h| h.match?(:after, names) }.each do |h|
|
81
85
|
debug("Hook after: #{names.join(',')}")
|
82
86
|
h.exec(obj)
|
data/lib/minfra/cli/logging.rb
CHANGED
@@ -4,7 +4,7 @@ module Minfra
|
|
4
4
|
module Cli
|
5
5
|
module Logging
|
6
6
|
def error(str)
|
7
|
-
logger.error
|
7
|
+
logger.error(colored(str, :red))
|
8
8
|
end
|
9
9
|
|
10
10
|
def exit_error(str)
|
@@ -17,11 +17,11 @@ module Minfra
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def warn(str)
|
20
|
-
logger.warn
|
20
|
+
logger.warn(colored(str, :yellow))
|
21
21
|
end
|
22
22
|
|
23
23
|
def debug(str)
|
24
|
-
logger.debug
|
24
|
+
logger.debug(str)
|
25
25
|
end
|
26
26
|
|
27
27
|
def deprecated(comment)
|
@@ -33,6 +33,14 @@ module Minfra
|
|
33
33
|
def logger
|
34
34
|
Minfra::Cli.logger
|
35
35
|
end
|
36
|
+
LOGGING_COLORS={ red: '1;31;40', green: '1;32;40' , dark_green: '0;32;40' , yellow: '1;33;40' }
|
37
|
+
def colored(str, color)
|
38
|
+
if $stdout.isatty
|
39
|
+
"\e[#{LOGGING_COLORS[color] || LOGGING_COLORS[:color1]}m#{str}\e[0m"
|
40
|
+
else
|
41
|
+
str
|
42
|
+
end
|
43
|
+
end
|
36
44
|
end
|
37
45
|
end
|
38
46
|
end
|
data/lib/minfra/cli/runner.rb
CHANGED
@@ -13,14 +13,16 @@ module Minfra
|
|
13
13
|
|
14
14
|
attr_reader :stdout_lines
|
15
15
|
|
16
|
-
def initialize
|
16
|
+
def initialize(on_output: nil)
|
17
17
|
@stderr_lines = []
|
18
18
|
@stdout_lines = []
|
19
19
|
@status = nil
|
20
|
+
@on_output = on_output
|
20
21
|
end
|
21
22
|
|
22
23
|
def add(line, stream = :stdout)
|
23
24
|
line.chomp!
|
25
|
+
@on_output.call(line, stream) if @on_output
|
24
26
|
if stream == :stdout
|
25
27
|
@stdout_lines << line
|
26
28
|
debug line
|
@@ -60,23 +62,25 @@ module Minfra
|
|
60
62
|
new(cmd, **args).run
|
61
63
|
end
|
62
64
|
|
63
|
-
attr_reader :exit_on_error, :runner, :cmd
|
65
|
+
attr_reader :exit_on_error, :runner, :cmd, :on_output
|
64
66
|
|
65
|
-
def initialize(cmd, exit_on_error: true, runner: :popen)
|
67
|
+
def initialize(cmd, exit_on_error: true, runner: :popen, on_output: nil)
|
66
68
|
@cmd = cmd
|
67
69
|
@exit_on_error = exit_on_error
|
68
70
|
@runner = runner
|
71
|
+
@on_output = on_output
|
69
72
|
end
|
70
73
|
|
71
74
|
def run
|
72
75
|
debug("running (#{@runner}): #{@cmd}")
|
73
|
-
res =
|
76
|
+
res = Result.new(on_output:)
|
77
|
+
case @runner
|
74
78
|
when :system
|
75
|
-
run_system(
|
79
|
+
run_system(res)
|
76
80
|
when :popen
|
77
|
-
run_threaded(
|
81
|
+
run_threaded(res)
|
78
82
|
when :exec
|
79
|
-
run_exec(
|
83
|
+
run_exec(res)
|
80
84
|
else
|
81
85
|
raise "unknown runner #{@runner}"
|
82
86
|
end
|
data/lib/minfra/cli/templater.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'erb'
|
4
|
-
|
5
4
|
module Minfra
|
6
5
|
module Cli
|
7
6
|
# not threadsafe!
|
@@ -30,14 +29,15 @@ module Minfra
|
|
30
29
|
|
31
30
|
source.glob('**/*') do |filename|
|
32
31
|
rel_path = filename.relative_path_from(source)
|
33
|
-
|
34
32
|
if File.directory?(filename) # check if it s file and extension is not .tf
|
35
33
|
FileUtils.mkdir_p("#{destination}/#{rel_path}")
|
36
34
|
elsif extensions.include?(File.extname(filename)) # a file
|
35
|
+
# puts("templating: #{filename}")
|
37
36
|
content = File.read(filename)
|
38
37
|
modified_content = Minfra::Cli::Templater.render(content, {})
|
39
38
|
File.write("#{destination}/#{rel_path}", modified_content)
|
40
39
|
else
|
40
|
+
# puts("copying : #{filename}")
|
41
41
|
FileUtils.cp(filename, destination.join(rel_path))
|
42
42
|
end
|
43
43
|
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: 2.0
|
4
|
+
version: 2.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-01-
|
11
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -157,7 +157,6 @@ files:
|
|
157
157
|
- CHANGELOG.md
|
158
158
|
- Dockerfile
|
159
159
|
- Gemfile
|
160
|
-
- Gemfile.lock
|
161
160
|
- README.md
|
162
161
|
- Rakefile
|
163
162
|
- bin/build
|
data/Gemfile.lock
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
minfra-cli (2.0.0)
|
5
|
-
activesupport (= 7.0.7.2)
|
6
|
-
erubis (~> 2.7)
|
7
|
-
hashie (~> 3.5)
|
8
|
-
hiera (= 3.9.0)
|
9
|
-
hiera-eyaml (= 3.3.0)
|
10
|
-
hiera-eyaml-gpg (= 0.7.4)
|
11
|
-
rest-client (~> 2.0)
|
12
|
-
table_print (= 1.5.6)
|
13
|
-
thor (~> 1.0, >= 1.0.0)
|
14
|
-
|
15
|
-
GEM
|
16
|
-
remote: https://rubygems.org/
|
17
|
-
specs:
|
18
|
-
activesupport (7.0.7.2)
|
19
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
|
-
i18n (>= 1.6, < 2)
|
21
|
-
minitest (>= 5.1)
|
22
|
-
tzinfo (~> 2.0)
|
23
|
-
concurrent-ruby (1.2.2)
|
24
|
-
diff-lcs (1.5.0)
|
25
|
-
domain_name (0.6.20231109)
|
26
|
-
erubis (2.7.0)
|
27
|
-
hashie (3.6.0)
|
28
|
-
hiera (3.9.0)
|
29
|
-
hiera-eyaml (3.3.0)
|
30
|
-
highline
|
31
|
-
optimist
|
32
|
-
hiera-eyaml-gpg (0.7.4)
|
33
|
-
hiera-eyaml (>= 1.3.8)
|
34
|
-
highline (2.1.0)
|
35
|
-
http-accept (1.7.0)
|
36
|
-
http-cookie (1.0.5)
|
37
|
-
domain_name (~> 0.5)
|
38
|
-
i18n (1.14.1)
|
39
|
-
concurrent-ruby (~> 1.0)
|
40
|
-
mime-types (3.5.1)
|
41
|
-
mime-types-data (~> 3.2015)
|
42
|
-
mime-types-data (3.2023.1205)
|
43
|
-
minitest (5.20.0)
|
44
|
-
netrc (0.11.0)
|
45
|
-
optimist (3.1.0)
|
46
|
-
rake (12.3.3)
|
47
|
-
rest-client (2.1.0)
|
48
|
-
http-accept (>= 1.7.0, < 2.0)
|
49
|
-
http-cookie (>= 1.0.2, < 2.0)
|
50
|
-
mime-types (>= 1.16, < 4.0)
|
51
|
-
netrc (~> 0.8)
|
52
|
-
rspec (3.12.0)
|
53
|
-
rspec-core (~> 3.12.0)
|
54
|
-
rspec-expectations (~> 3.12.0)
|
55
|
-
rspec-mocks (~> 3.12.0)
|
56
|
-
rspec-core (3.12.2)
|
57
|
-
rspec-support (~> 3.12.0)
|
58
|
-
rspec-expectations (3.12.3)
|
59
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
-
rspec-support (~> 3.12.0)
|
61
|
-
rspec-mocks (3.12.6)
|
62
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
-
rspec-support (~> 3.12.0)
|
64
|
-
rspec-support (3.12.1)
|
65
|
-
table_print (1.5.6)
|
66
|
-
thor (1.3.0)
|
67
|
-
timecop (0.9.8)
|
68
|
-
tzinfo (2.0.6)
|
69
|
-
concurrent-ruby (~> 1.0)
|
70
|
-
|
71
|
-
PLATFORMS
|
72
|
-
ruby
|
73
|
-
|
74
|
-
DEPENDENCIES
|
75
|
-
minfra-cli!
|
76
|
-
rake (~> 12.0)
|
77
|
-
rspec (~> 3.0)
|
78
|
-
timecop (~> 0.9.5)
|
79
|
-
|
80
|
-
BUNDLED WITH
|
81
|
-
2.1.4
|