consult 0.11.0 → 1.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +14 -0
- data/lib/consult/cli.rb +6 -1
- data/lib/consult/template.rb +33 -7
- data/lib/consult/version.rb +1 -1
- data/lib/consult.rb +15 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c7a54f7fb838f2f50a3553e2f798b75d569cf227c4c9d927d2185d4b597f882
|
4
|
+
data.tar.gz: be503dd900d460f14d8ae2ecaddd6eec05193859b2668d32762dd62e3e2f4cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f736a61ae78df99d70d778ec0a61bbaf6b702cc2e7d7b5e10f4a4c40682dd21cb72975cb49d6db28b502334b3027c793b17caa2b3a818f20fb05e52389a84a55
|
7
|
+
data.tar.gz: e786886e41c2a6c81b169c4d781465e422bae03b059b65dd6b156c8d30c2530c773157d752a150d569e514a56e6ccfa05b537f498d9bcc8c1078bdb336109688
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
#### Unreleased
|
2
2
|
|
3
|
+
#### 1.0.0
|
4
|
+
|
5
|
+
* Stop with error when force rendering and no template is found
|
6
|
+
* Remove non-functional short verbosity argument
|
7
|
+
* Add `--version` option to show the version
|
8
|
+
* Better logging for template rendering status, errors, and config (verbose mode)
|
9
|
+
* Development: adjust require's to be able to run CLI from any folder
|
10
|
+
* Enable defining vars at the env block level, rather than only on template blocks
|
11
|
+
* Create directories for rendered files as needed
|
12
|
+
* Add the `skip_missing_template` config for templates
|
13
|
+
|
3
14
|
#### 0.11.0
|
4
15
|
|
5
16
|
* Enable support for Ruby 3.1 ([#36](https://github.com/veracross/consult/pull/36))
|
data/README.md
CHANGED
@@ -94,8 +94,22 @@ test:
|
|
94
94
|
secrets:
|
95
95
|
path: config/templates/secrets.yml
|
96
96
|
dest: config/secrets.yml
|
97
|
+
# vars can be defined on a per-template basis
|
98
|
+
vars:
|
99
|
+
test_specific_key: and_the_value
|
100
|
+
|
101
|
+
extra_test_config:
|
102
|
+
# normally there's an error for missing templates, but this can be allowed via config
|
103
|
+
skip_missing_template: true
|
104
|
+
# config files are also processed through ERB, so paths can be made dynamic
|
105
|
+
path: config/templates/<%= ENV['extra_test_file'] %>.yml
|
106
|
+
dest: config/extra_test_config.yml
|
97
107
|
|
98
108
|
production:
|
109
|
+
# vars can be defined at the environment level, which are available to these templates
|
110
|
+
vars:
|
111
|
+
hello: world
|
112
|
+
|
99
113
|
templates:
|
100
114
|
# You can concatenate multiple files together
|
101
115
|
my_config:
|
data/lib/consult/cli.rb
CHANGED
@@ -38,9 +38,14 @@ module Consult
|
|
38
38
|
opts[:force_render] = arg
|
39
39
|
end
|
40
40
|
|
41
|
-
o.on '
|
41
|
+
o.on '--quiet', FalseClass, 'Silence output' do |arg|
|
42
42
|
opts[:verbose] = arg
|
43
43
|
end
|
44
|
+
|
45
|
+
o.on '--version', 'Show version' do
|
46
|
+
puts "Consult #{Consult::VERSION}"
|
47
|
+
exit 0
|
48
|
+
end
|
44
49
|
end
|
45
50
|
|
46
51
|
@parser.on_tail "-h", "--help", "Show help" do
|
data/lib/consult/template.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'fileutils'
|
4
|
+
require_relative 'template_functions'
|
5
|
+
require_relative '../support/hash_extensions'
|
4
6
|
|
5
7
|
module Consult
|
6
8
|
class Template
|
@@ -17,16 +19,26 @@ module Consult
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def render(save: true)
|
22
|
+
if contents.empty? && @config[:skip_missing_template]
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
20
26
|
# Attempt to render
|
21
27
|
renderer = ERB.new(contents, nil, '-')
|
22
28
|
result = renderer.result(binding)
|
23
29
|
|
24
|
-
|
25
|
-
|
30
|
+
puts "Consult: Rendering #{name}" + (save ? " to #{dest} ..." : "...") if verbose?
|
31
|
+
|
32
|
+
if save
|
33
|
+
FileUtils.mkdir_p(dest.dirname) unless dest.dirname.exist?
|
34
|
+
File.open(dest, 'wb') { |f| f << result }
|
35
|
+
end
|
36
|
+
|
26
37
|
result
|
27
38
|
rescue StandardError => e
|
28
39
|
STDERR.puts "Error rendering template: #{name}"
|
29
40
|
STDERR.puts e
|
41
|
+
STDERR.puts e.backtrace if verbose?
|
30
42
|
nil
|
31
43
|
end
|
32
44
|
|
@@ -39,7 +51,7 @@ module Consult
|
|
39
51
|
end
|
40
52
|
|
41
53
|
def vars
|
42
|
-
@config[:vars]
|
54
|
+
@config[:env_vars].to_h.deep_merge @config[:vars].to_h
|
43
55
|
end
|
44
56
|
|
45
57
|
def dest
|
@@ -68,20 +80,34 @@ module Consult
|
|
68
80
|
|
69
81
|
# Concatenate all the source templates together, in the order provided
|
70
82
|
def contents
|
71
|
-
ordered_locations.map do |location|
|
83
|
+
@_contents ||= ordered_locations.map do |location|
|
72
84
|
location.to_s.start_with?('consul') ? consul_contents(location) : disk_contents(location)
|
73
|
-
end.join
|
85
|
+
end.compact.join
|
74
86
|
end
|
75
87
|
|
76
88
|
def consul_contents(location)
|
77
89
|
[@config[location]].compact.flatten.map do |key|
|
78
|
-
Diplomat::Kv.get(key,
|
90
|
+
Diplomat::Kv.get(key, {}, :reject, :return).force_encoding 'utf-8'
|
91
|
+
rescue Diplomat::KeyNotFound
|
92
|
+
if @config[:skip_missing_template]
|
93
|
+
STDERR.puts "Consult: Skipping missing template: #{name}"
|
94
|
+
next
|
95
|
+
end
|
96
|
+
|
97
|
+
raise
|
79
98
|
end.join
|
80
99
|
end
|
81
100
|
|
82
101
|
def disk_contents(location)
|
83
102
|
[public_send(location)].compact.flatten.map do |file_path|
|
84
103
|
File.read file_path, encoding: 'utf-8'
|
104
|
+
rescue Errno::ENOENT
|
105
|
+
if @config[:skip_missing_template]
|
106
|
+
STDERR.puts "Consult: Skipping missing template: #{name}"
|
107
|
+
next
|
108
|
+
end
|
109
|
+
|
110
|
+
raise
|
85
111
|
end.join
|
86
112
|
end
|
87
113
|
end
|
data/lib/consult/version.rb
CHANGED
data/lib/consult.rb
CHANGED
@@ -6,9 +6,9 @@ require 'erb'
|
|
6
6
|
require 'vault'
|
7
7
|
require 'diplomat'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
require_relative './consult/version'
|
10
|
+
require_relative './consult/utilities'
|
11
|
+
require_relative './consult/template'
|
12
12
|
require_relative './support/hash_extensions'
|
13
13
|
|
14
14
|
module Consult
|
@@ -24,21 +24,32 @@ module Consult
|
|
24
24
|
root directory: config_dir
|
25
25
|
yaml = root.join('config', 'consult.yml')
|
26
26
|
|
27
|
+
if verbose
|
28
|
+
puts "Consult: Loading config from #{yaml}"
|
29
|
+
end
|
30
|
+
|
27
31
|
@all_config = if yaml.exist?
|
28
32
|
if Gem::Version.new(YAML::VERSION) < Gem::Version.new('4.0')
|
29
33
|
YAML.safe_load(ERB.new(yaml.read).result, [], [], true, symbolize_names: true).to_h
|
30
34
|
else
|
31
35
|
YAML.safe_load(ERB.new(yaml.read).result, aliases: true, symbolize_names: true).to_h
|
32
36
|
end
|
37
|
+
else
|
38
|
+
STDERR.puts "Consult: No config file found at #{root} -> #{yaml}"
|
33
39
|
end
|
34
40
|
|
35
41
|
@all_config ||= {}
|
36
42
|
|
37
43
|
@config = @all_config[:shared].to_h.deep_merge @all_config[env&.to_sym].to_h
|
38
|
-
@templates = @config[:templates]&.map { |name, config| Template.new(name, config.merge(verbose: verbose)) } || []
|
44
|
+
@templates = @config[:templates]&.map { |name, config| Template.new(name, config.merge(verbose: verbose).merge(env_vars: @config[:vars])) } || []
|
39
45
|
|
40
46
|
@force_render = force_render
|
41
47
|
|
48
|
+
if @templates.empty? && @force_render
|
49
|
+
STDERR.puts "Consult: No template was found for env #{env.inspect} with forced rendering (re-run with `--no-force` if this is acceptable)"
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
|
42
53
|
configure_consul
|
43
54
|
configure_vault
|
44
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consult
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Fraser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diplomat
|
@@ -205,9 +205,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
205
|
version: '0'
|
206
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
207
|
requirements:
|
208
|
-
- - "
|
208
|
+
- - ">"
|
209
209
|
- !ruby/object:Gem::Version
|
210
|
-
version:
|
210
|
+
version: 1.3.1
|
211
211
|
requirements: []
|
212
212
|
rubygems_version: 3.1.6
|
213
213
|
signing_key:
|