consul-templaterb 1.13.0 → 1.13.1
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/.gitignore +6 -10
- data/CHANGELOG.md +6 -0
- data/TemplateAPI.md +3 -0
- data/lib/consul/async/consul_template.rb +12 -0
- data/lib/consul/async/version.rb +1 -1
- data/samples/kv_yaml_to_json.json.erb +14 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81fe8ace61e417a86ebcc40579f9d7601c624e1f
|
4
|
+
data.tar.gz: 743e935937d5b0a23a7e1f2586e89d98142311a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7de540a1a265c175d71d9509425ccf1c4bc70f07d63dda83e31fe7046542d6ffbb877e674426d257754d95b00902697c91f4a77e72bb9cfdfdcdbd6762111bcd
|
7
|
+
data.tar.gz: 54a1adec053fd1da90a3de4f7bbdbc5654f7bc1f641c47d91a469e26d3bad6b749be661a3061516f734c9c30ccf2334a12589fdb3f4c94081eb446bac225df21
|
data/.gitignore
CHANGED
@@ -7,21 +7,17 @@
|
|
7
7
|
/pkg/
|
8
8
|
/spec/reports/
|
9
9
|
/tmp/
|
10
|
+
/samples/**/*.json
|
11
|
+
/samples/**/*.xml
|
12
|
+
/samples/**/*.html
|
13
|
+
/samples/**/*.txt
|
14
|
+
/samples/**/*.cfg
|
10
15
|
/samples/ready
|
11
|
-
/samples
|
12
|
-
/samples/*.xml
|
13
|
-
/samples/*.html
|
14
|
-
/samples/*.txt
|
15
|
-
/samples/*.cfg
|
16
|
-
samples/consul-ui/*.html
|
17
|
-
samples/consul-ui/*.json
|
18
|
-
samples/consul-ui/common/*.html
|
19
|
-
/samples/criteo/haproxy.cfg
|
16
|
+
/samples/render_template_from_kv
|
20
17
|
/samples/consul_template
|
21
18
|
/samples/metrics
|
22
19
|
/samples/service_checks_metrics
|
23
20
|
/samples/find_blocked_choregraphies
|
24
|
-
/samples/tools/*.txt
|
25
21
|
/spec/consul/async/resources/templates/*.txt
|
26
22
|
/spec/consul/async/resources/templates/*.result
|
27
23
|
/out.txt
|
data/CHANGELOG.md
CHANGED
data/TemplateAPI.md
CHANGED
@@ -225,6 +225,7 @@ and the call is retrieving several keys, it allows to select a specific one.The
|
|
225
225
|
if will not throw an error during rendering of template and return nil. Otherwise
|
226
226
|
an Error will be thrown and have to be catch if you are unsure if the value is valid
|
227
227
|
JSON
|
228
|
+
* `get_value_yaml( [path], [catch_errors: true] )` : same as above, but for yml
|
228
229
|
|
229
230
|
#### Get the result of a single value
|
230
231
|
|
@@ -234,6 +235,8 @@ The easiest, use the helpers to retrieve the values in the following formats:
|
|
234
235
|
* `kv('/my/path/to/value').get_decoded` : get the decoded value of a single key in KV
|
235
236
|
* `kv('/my/path/to/value').get_value_json` : get the base64 decoded value and try decoding it as JSON
|
236
237
|
|
238
|
+
* `kv('/my/path/to/value').get_value_yaml` : get the base64 decoded value and try decoding it as YAML
|
239
|
+
|
237
240
|
#### Iterate over values
|
238
241
|
|
239
242
|
If you want to iterate amongst all values, you might to it that way:
|
@@ -471,6 +471,18 @@ module Consul
|
|
471
471
|
raise StandardError.new(e), "get_value_json() cannot deserialize kv(#{name}) as JSON: #{e.message}", e.backtrace
|
472
472
|
end
|
473
473
|
end
|
474
|
+
|
475
|
+
# Helper to get the value decoded as YAML
|
476
|
+
def get_value_yaml(name = root, catch_errors: true)
|
477
|
+
x = get_value_decoded(name)
|
478
|
+
return nil unless x
|
479
|
+
begin
|
480
|
+
YAML.safe_load(x)
|
481
|
+
rescue YAML::ParserError => e
|
482
|
+
return nil if catch_errors
|
483
|
+
raise StandardError.new(e), "get_value_yaml() cannot deserialize kv(#{name}) as YAML: #{e.message}", e.backtrace
|
484
|
+
end
|
485
|
+
end
|
474
486
|
end
|
475
487
|
|
476
488
|
class ConsulTemplateVaultSecret < ConsulTemplateAbstractMap
|
data/lib/consul/async/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
<%
|
2
|
+
# This template read a YAML KV value and render it as JSON
|
3
|
+
kv_path = param('kv_path', ENV['KV_YAML_PATH'])
|
4
|
+
if kv_path
|
5
|
+
obj = kv(kv_path).get_value_yaml()
|
6
|
+
if obj
|
7
|
+
%><%= JSON.pretty_generate(obj)%><%
|
8
|
+
else
|
9
|
+
%><%= kv_path %> is not a valid YAML<%
|
10
|
+
end
|
11
|
+
else
|
12
|
+
%>Please specify environment variable KV_YAML_PATH<%
|
13
|
+
end
|
14
|
+
%>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul-templaterb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.13.
|
4
|
+
version: 1.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SRE Core Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|
@@ -209,6 +209,7 @@ files:
|
|
209
209
|
- samples/debug/compare_connect_services.txt.erb
|
210
210
|
- samples/ha_proxy.cfg.erb
|
211
211
|
- samples/keys.html.erb
|
212
|
+
- samples/kv_yaml_to_json.json.erb
|
212
213
|
- samples/metrics.erb
|
213
214
|
- samples/nodes.html.erb
|
214
215
|
- samples/render_template_from_kv.erb
|