consult 0.7.3 → 0.8.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: 1d0e9e0e2f63b060fe1fae95c3a95c93d7cf89654dcf18c5cd7c7928a346db2b
4
- data.tar.gz: 6c5316a1093c3806deb091aa74f38a1f65101f8fcc1d4525f4f60a50731737f9
3
+ metadata.gz: 371b66af8be47b598b8ee428856c17d35864b5ba93b3bff8ad0852c4d403d2fe
4
+ data.tar.gz: ce70cfa1f22a21d6255ae2fd1a867b2950765ca5c3b8b3c4f8090aab8f0c28d1
5
5
  SHA512:
6
- metadata.gz: fc4a191a7b1b362b9655cecbfcb83b63354f10659d4a84d899bb271ce0013b82f2c1a9e08f008cbade94ac4132e47438bd3dd3f3fd7ce40cad4c5d54a26d4702
7
- data.tar.gz: 05c1543f7f774dae4c7fdeb25e2dbc51f732ea63d09b276e663b29aca2f40b88df80a6e6c83fb4a10b51e2e91217f5c3c0e52ef0d8b9630669f032aa386fade2
6
+ metadata.gz: f72c7410f792f22c1bdc4d095b9f2fb122943625f2be6876461f692acd378fbd4bce6ce14797fe387d59d8ffaaf827612b3a7fb908d880a07b2933dddf294d03
7
+ data.tar.gz: f19a08e8ec11f404c82c6344885c36cc9346d04fbdaa7de8fdb9ddb3fe7059d1cc4c7d4c472a2a2ad41a642a87e338b5aa49a4eff36b0a19cd795dc29b48ee9f
data/.gitignore CHANGED
@@ -5,7 +5,7 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
- /spec/support/rendered/*.yml
8
+ /spec/support/rendered/*
9
9
  /tmp/
10
10
 
11
11
  # rspec failure tracking
@@ -1,3 +1,9 @@
1
+ #### 0.8.0
2
+
3
+ * Add support for multiple sources for a single template ([#14](https://github.com/veracross/consult/pull/14))
4
+ * Add support for Consul-sourced templates ([#15](https://github.com/veracross/consult/pull/15))
5
+ * Don't crash on rendering errors ([#16](https://github.com/veracross/consult/pull/16))
6
+
1
7
  #### 0.7.3
2
8
 
3
9
  * Add `key` function to templates to pull kv data from Consul
data/README.md CHANGED
@@ -88,14 +88,20 @@ test:
88
88
  dest: config/secrets.yml
89
89
 
90
90
  production:
91
- # example: override vault token in production
92
- vault:
93
- token: 1397af7aede2-8923-412d-3eb9-8fcd5aed
94
91
  templates:
95
- # excluded from non-production environments
96
- should_be_excluded:
97
- path: config/templates/fake.yml
98
- dest: config/fake.yml
92
+ # You can concatenate multiple files together
93
+ my_config:
94
+ paths:
95
+ - config/templates/one.yml
96
+ - config/templates/two.yml
97
+ dest: config/my_config.yml
98
+
99
+ # Templates can come from Consul
100
+ your_config:
101
+ consul_keys:
102
+ - some/consul/key
103
+ - another/consul/key
104
+ dest: config/your_config.txt
99
105
  ```
100
106
 
101
107
  ### Templates
@@ -1,11 +1,11 @@
1
1
  version: '3'
2
2
  services:
3
3
  consul:
4
- image: consul:1.2.0
4
+ image: consul:1.2.3
5
5
  ports:
6
6
  - "8500:8500"
7
7
  vault:
8
- image: vault:0.10.3
8
+ image: vault:0.11.1
9
9
  environment:
10
10
  - VAULT_DEV_ROOT_TOKEN_ID=94e1a9ed-5d72-5677-27ab-ebc485cca368
11
11
  cap_add:
@@ -19,7 +19,6 @@ module Consult
19
19
 
20
20
  class << self
21
21
  attr_reader :config, :templates
22
-
23
22
  def load(config_dir: nil)
24
23
  root directory: config_dir
25
24
  yaml = root.join('config', 'consult.yml')
@@ -15,18 +15,28 @@ module Consult
15
15
  end
16
16
 
17
17
  def render(save: true)
18
- renderer = ERB.new(File.read(path, encoding: 'utf-8'), nil, '-')
18
+ # Attempt to render
19
+ renderer = ERB.new(contents, nil, '-')
19
20
  result = renderer.result(binding)
20
21
 
21
22
  File.open(dest, 'w') { |f| f << result } if save
22
23
  result
23
24
  rescue StandardError => e
24
- puts "Error rendering template: #{name}"
25
- raise e
25
+ STDERR.puts "Error rendering template: #{name}"
26
+ STDERR.puts e
27
+ nil
26
28
  end
27
29
 
28
30
  def path
29
- resolve @config.fetch(:path)
31
+ resolve @config[:path]
32
+ end
33
+
34
+ def paths
35
+ @config.fetch(:paths, []).map { |path| resolve(path) }
36
+ end
37
+
38
+ def vars
39
+ @config[:vars]
30
40
  end
31
41
 
32
42
  def dest
@@ -42,5 +52,26 @@ module Consult
42
52
  return true if !config.key?(:ttl) || !dest.exist?
43
53
  dest.mtime < (Time.now - @config[:ttl].to_i)
44
54
  end
55
+
56
+ private
57
+
58
+ # Concatenate all the source templates together, in the order provided
59
+ # Disk contents go first
60
+ def contents
61
+ disk_contents + consul_contents
62
+ end
63
+
64
+ def consul_contents
65
+ [@config[:consul_key], @config[:consul_keys]].compact.flatten.map do |key|
66
+ Diplomat::Kv.get(key, options: nil, not_found: :return, found: :return)
67
+ end.join
68
+ end
69
+
70
+ # Concatenate all the source templates together, in the order provided
71
+ def disk_contents
72
+ [path, paths].compact.flatten.map do |file_path|
73
+ File.read file_path, encoding: 'utf-8'
74
+ end.join
75
+ end
45
76
  end
46
77
  end
@@ -3,6 +3,7 @@
3
3
  module Consult
4
4
  module Utilities
5
5
  def resolve(path)
6
+ return unless path
6
7
  pathname = Pathname.new(path)
7
8
  pathname.relative? ? Consult.root.join(pathname) : pathname
8
9
  end
@@ -1,3 +1,3 @@
1
1
  module Consult
2
- VERSION = '0.7.3'
2
+ VERSION = '0.8.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.7.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Fraser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-27 00:00:00.000000000 Z
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport