consult 0.8.2 → 0.9.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: 46ea3e316eba29453ae4fd2b33bf73e38112b21a14cc4f87c2ce906c0d139309
4
- data.tar.gz: 96ba993d95a8ef6ab6f315856a943b11fada8eacb2bddf618fb372f15a08643a
3
+ metadata.gz: 36965e0fbed738e72487cda4371047459b67bcc980b2926fc74e604feadbc712
4
+ data.tar.gz: 6922f60403c25f25b944648319a3ad1dc3fb680c850688399559c34e0e0afaac
5
5
  SHA512:
6
- metadata.gz: f47bc8fccf91f7efcd5ae3b9042e1c22d93a8c5a2f375a934ea5aaddae7eb0b8ecb7c63384367abf5428453f5bad98a2513b7b75ebf421ac15ba3a9c353ed05a
7
- data.tar.gz: 8500c4dd097cfbc4c82cd3f9054c006214a4d51cf0ca0e79ae77655c2392581f341c031dfbdb66d1804d418148489411f164c46a7c58f0e055c2d70d18f22993
6
+ metadata.gz: f1690e8cd6ae71d813e26c77e71ae37916c1b6e15c142f2c4cc34975e18e38c5622f006d9d1c840e98b35476c4b9c6b503fd73f482f495cc962c215eda7a0247
7
+ data.tar.gz: e5013584ee2e288d2c75cb21ae746bb1409e598eeb2aba8499e58ea50d3a1c5db5ebb0b6389f94926df5e27ebab9fa9f0966e5c9073f331f2937717e8d8b063a
data/README.md CHANGED
@@ -40,6 +40,16 @@ Pre-existing copies of files generated by Consult (such as `secrets.yml`, `datab
40
40
 
41
41
  If this gem is included in a Rails, the templates will render on Rails boot. Configuration or credential changes can be picked up by restarting your app.
42
42
 
43
+ ### CLI
44
+
45
+ Render templates on demand with the CLI. By default, this will bypass template TTLs to force rendering and provide verbose output. See `consult --help` for options.
46
+
47
+ ```bash
48
+ $ bundle exec consult
49
+ Consult: Rendered my_config
50
+ Consult: Rendered secrets
51
+ ```
52
+
43
53
  ### Configuration
44
54
 
45
55
  ```yaml
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/consult/cli'
4
+
5
+ cli = Consult::CLI.instance
6
+ cli.parse
7
+ cli.render
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
21
  f.match(%r{^(test|spec|features)/})
22
22
  end
23
- spec.bindir = 'exe'
24
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.bindir = 'bin'
24
+ spec.executables = ['consult']
25
25
  spec.require_paths = ['lib']
26
26
 
27
27
  spec.add_dependency 'activesupport', '> 4', '< 6'
@@ -29,10 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency 'vault', '>= 0.10.0', '< 1.0.0'
30
30
 
31
31
  spec.add_development_dependency 'bundler', '~> 1.16'
32
- spec.add_development_dependency 'byebug'
33
32
  spec.add_development_dependency 'guard'
34
33
  spec.add_development_dependency 'guard-rspec'
35
- spec.add_development_dependency 'pry'
34
+ spec.add_development_dependency 'pry-byebug'
36
35
  spec.add_development_dependency 'rake', '~> 10.0'
37
36
  spec.add_development_dependency 'rspec', '~> 3.0'
38
37
  spec.add_development_dependency 'simplecov'
@@ -18,8 +18,9 @@ module Consult
18
18
  CONSUL_DISK_TOKEN = Pathname.new("#{Dir.home}/.consul-token").freeze
19
19
 
20
20
  class << self
21
- attr_reader :config, :templates
22
- def load(config_dir: nil)
21
+ attr_reader :config, :templates, :force_render
22
+
23
+ def load(config_dir: nil, force_render: false, verbose: nil)
23
24
  root directory: config_dir
24
25
  yaml = root.join('config', 'consult.yml')
25
26
 
@@ -27,7 +28,9 @@ module Consult
27
28
  @all_config.deep_symbolize_keys!
28
29
 
29
30
  @config = @all_config[:shared].to_h.deep_merge @all_config[env&.to_sym].to_h
30
- @templates = @config[:templates]&.map { |name, config| Template.new(name, config) } || []
31
+ @templates = @config[:templates]&.map { |name, config| Template.new(name, config.merge(verbose: verbose)) } || []
32
+
33
+ @force_render = force_render
31
34
 
32
35
  configure_consul
33
36
  configure_vault
@@ -71,7 +74,7 @@ module Consult
71
74
 
72
75
  # Return only the templates that are relevant for the current environment
73
76
  def active_templates
74
- templates.select(&:should_render?)
77
+ force_render ? templates : templates.select(&:should_render?)
75
78
  end
76
79
 
77
80
  # Render templates.
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ $stdout.sync = true
4
+
5
+ require 'singleton'
6
+ require 'optparse'
7
+
8
+ require_relative '../consult'
9
+
10
+ module Consult
11
+ class CLI
12
+ include Singleton
13
+
14
+ attr_reader :opts
15
+
16
+ def parse(args = ARGV)
17
+ @opts = parse_options(args)
18
+ Consult.load @opts
19
+ end
20
+
21
+ def render
22
+ Consult.render!
23
+ end
24
+
25
+ def parse_options(argv)
26
+ opts = {
27
+ config_dir: Dir.pwd,
28
+ force_render: true,
29
+ verbose: true
30
+ }
31
+
32
+ @parser = OptionParser.new do |o|
33
+ o.on '-d', '--directory=DIR', 'Path to directory containing the config directory' do |arg|
34
+ opts[:config_dir] = arg
35
+ end
36
+
37
+ o.on '-f', '--[no-]force', TrueClass, 'Ignore template TTLs and force rendering' do |arg|
38
+ opts[:force_render] = arg
39
+ end
40
+
41
+ o.on '-v', '--quiet', FalseClass, 'Silence output' do |arg|
42
+ opts[:verbose] = arg
43
+ end
44
+ end
45
+
46
+ @parser.on_tail "-h", "--help", "Show help" do
47
+ puts @parser
48
+ exit 1
49
+ end
50
+
51
+ @parser.parse! argv
52
+ opts
53
+ end
54
+ end
55
+ end
@@ -22,6 +22,7 @@ module Consult
22
22
  result = renderer.result(binding)
23
23
 
24
24
  File.open(dest, 'w') { |f| f << result } if save
25
+ puts "Consult: Rendered #{name}" if verbose?
25
26
  result
26
27
  rescue StandardError => e
27
28
  STDERR.puts "Error rendering template: #{name}"
@@ -55,6 +56,10 @@ module Consult
55
56
  dest.mtime < (Time.now - @config[:ttl].to_i)
56
57
  end
57
58
 
59
+ def verbose?
60
+ @config[:verbose]
61
+ end
62
+
58
63
  def ordered_locations
59
64
  @config.keys & LOCATIONS
60
65
  end
@@ -1,3 +1,3 @@
1
1
  module Consult
2
- VERSION = '0.8.2'
2
+ VERSION = '0.9.0'
3
3
  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.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Fraser
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2019-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -78,20 +78,6 @@ dependencies:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
80
  version: '1.16'
81
- - !ruby/object:Gem::Dependency
82
- name: byebug
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- type: :development
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- version: '0'
95
81
  - !ruby/object:Gem::Dependency
96
82
  name: guard
97
83
  requirement: !ruby/object:Gem::Requirement
@@ -121,7 +107,7 @@ dependencies:
121
107
  - !ruby/object:Gem::Version
122
108
  version: '0'
123
109
  - !ruby/object:Gem::Dependency
124
- name: pry
110
+ name: pry-byebug
125
111
  requirement: !ruby/object:Gem::Requirement
126
112
  requirements:
127
113
  - - ">="
@@ -179,7 +165,8 @@ dependencies:
179
165
  description: Manage consul/vault backed template files in Ruby.
180
166
  email:
181
167
  - jeff.fraser@veracross.com
182
- executables: []
168
+ executables:
169
+ - consult
183
170
  extensions: []
184
171
  extra_rdoc_files: []
185
172
  files:
@@ -195,10 +182,12 @@ files:
195
182
  - README.md
196
183
  - Rakefile
197
184
  - bin/console
185
+ - bin/consult
198
186
  - bin/setup
199
187
  - consult.gemspec
200
188
  - docker-compose.yml
201
189
  - lib/consult.rb
190
+ - lib/consult/cli.rb
202
191
  - lib/consult/rails/engine.rb
203
192
  - lib/consult/template.rb
204
193
  - lib/consult/template_functions.rb