consul-templaterb 1.32.1 → 1.33.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -1
- data/README.md +6 -1
- data/TemplateAPI.md +9 -0
- data/lib/consul/async/consul_endpoint.rb +2 -1
- data/lib/consul/async/consul_template.rb +39 -8
- data/lib/consul/async/debug.rb +7 -1
- data/lib/consul/async/json_endpoint.rb +1 -0
- data/lib/consul/async/vault_endpoint.rb +1 -0
- data/lib/consul/async/version.rb +1 -1
- data/samples/consul-ui/consul_services.json.erb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f55651aacf74759dde1f529be4cb482568b0272067b5b208ff4268828cbfce6b
|
4
|
+
data.tar.gz: f22a2c679bcaf2a79a1d70f2d375d1707a5a2e58ae99f9186f10d97615b24303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b10810197fc2c882d09723203d47c62f6aaed2a94cd463a939e4b9ab34b75c0e3c2f8b2c702bc999dd5e37bd86d1b727f17268f7029b66f0ac75211843340ba
|
7
|
+
data.tar.gz: cbbec34b47aa8230846ff21dbeb247928519d65f058cded7cf29f76df225fa8148bcb99d3d842e1951a782c992e355b37628b83505c5dd705831d1b7ce49ac6f
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 1.31.
|
3
|
+
## 1.31.2 (Aug 04 2022)
|
4
|
+
|
5
|
+
BUG FIX:
|
6
|
+
|
7
|
+
* URL encode service and KV names when calling the http API
|
8
|
+
|
9
|
+
## 1.31.1 (Feb 281 2022)
|
10
|
+
|
11
|
+
BUG FIX:
|
12
|
+
|
13
|
+
* Correctly identify endpoints
|
14
|
+
|
15
|
+
## 1.33.0 (Nov 22, 2021)
|
16
|
+
|
17
|
+
IMPROVEMENTS:
|
18
|
+
|
19
|
+
* Validate ssl peers
|
20
|
+
* Allow to stream log lines
|
21
|
+
* [CONSUL-UI] Display services with no port definition
|
22
|
+
* Hide opts in logs by default
|
23
|
+
|
24
|
+
## 1.32.1 (Jan 28, 2021)
|
4
25
|
|
5
26
|
IMPROVEMENTS:
|
6
27
|
|
data/README.md
CHANGED
@@ -207,6 +207,11 @@ It means that you can call consul-templaterb with `*.erb` arguments, the shell
|
|
207
207
|
will then substitute all files and render it by removing the `.erb` extension as
|
208
208
|
if the `--template my_file.ext.erb:myfile.ext` was used.
|
209
209
|
|
210
|
+
If the program is run in an automatic context, it could be useful to stream
|
211
|
+
logs instead of the default interactive log version which erase last log line.
|
212
|
+
To configure this behavior, set the `STREAM_LOG` environment variable to any
|
213
|
+
value.
|
214
|
+
|
210
215
|
### Generate multiple templates
|
211
216
|
|
212
217
|
In the same way as consul-template, consul-templaterb supports multiple templates and executing
|
@@ -287,7 +292,7 @@ If you want to test it quickly, you might try with (assuming your consul agent i
|
|
287
292
|
`http://localhost:8500`):
|
288
293
|
|
289
294
|
```shell
|
290
|
-
$
|
295
|
+
$ bundle exec bin/consul-templaterb -c 'http://localhost:8500' samples/*.html.erb
|
291
296
|
[...]
|
292
297
|
```
|
293
298
|
|
data/TemplateAPI.md
CHANGED
@@ -380,6 +380,15 @@ Full example: [samples/consul_template.txt.erb](samples/consul_template.txt.erb)
|
|
380
380
|
[List all the services of a given Node](https://www.consul.io/api/catalog.html#list-services-for-node) using its
|
381
381
|
name or its ID. If DC is specified, will lookup for given node in another datacenter.
|
382
382
|
|
383
|
+
The value returned might be nil (because the node does not exists).
|
384
|
+
Thus, it might be safer to use the helper methods on the result:
|
385
|
+
|
386
|
+
* node('mynode').exists? -> true if node exists and result is not nil
|
387
|
+
* node('mynode').services() -> to get the hash of services defined for this node (return empty map if nodes does not exists)
|
388
|
+
* node('mynode').node() -> to get node information (empty map if node does not exists)
|
389
|
+
|
390
|
+
See also: https://github.com/criteo/consul-templaterb/issues/74
|
391
|
+
|
383
392
|
## checks_for_node(name, dc: nil, passing: false, tag: nil, [agent: consul_agent_address])
|
384
393
|
|
385
394
|
[Find all the checks](https://www.consul.io/api/health.html#list-checks-for-node) of a given node name.
|
@@ -265,7 +265,8 @@ module Consul
|
|
265
265
|
def fetch
|
266
266
|
options = {
|
267
267
|
connect_timeout: 5, # default connection setup timeout
|
268
|
-
inactivity_timeout: conf.wait_duration + 1 + (conf.wait_duration / 16) # default connection inactivity (post-setup) timeout
|
268
|
+
inactivity_timeout: conf.wait_duration + 1 + (conf.wait_duration / 16), # default connection inactivity (post-setup) timeout
|
269
|
+
tls: { verify_peer: conf.tls_verify_peer }
|
269
270
|
}
|
270
271
|
unless conf.tls_cert_chain.nil?
|
271
272
|
options[:tls] = {
|
@@ -31,7 +31,7 @@ module Consul
|
|
31
31
|
|
32
32
|
def as_json(url, default_value, refresh_delay_secs: 10, **opts)
|
33
33
|
conf = JSONConfiguration.new(url: url, min_duration: refresh_delay_secs, retry_on_non_diff: refresh_delay_secs, **opts)
|
34
|
-
endpoint_id = url + opts.
|
34
|
+
endpoint_id = url + opts.hash.to_s
|
35
35
|
@endp_manager.create_if_missing(url, {}, endpoint_id: endpoint_id) do
|
36
36
|
if default_value.is_a?(Array)
|
37
37
|
ConsulTemplateJSONArray.new(JSONEndpoint.new(conf, url, default_value))
|
@@ -132,7 +132,7 @@ module Consul
|
|
132
132
|
def service(name, dc: nil, passing: false, tag: nil, agent: nil)
|
133
133
|
raise 'You must specify a name for a service' if name.nil?
|
134
134
|
|
135
|
-
path =
|
135
|
+
path = '/v1/health/service/' + ERB::Util.url_encode(name.to_s)
|
136
136
|
query_params = {}
|
137
137
|
query_params[:dc] = dc if dc
|
138
138
|
query_params[:passing] = passing if passing
|
@@ -144,7 +144,7 @@ module Consul
|
|
144
144
|
def checks_for_service(name, dc: nil, passing: false, agent: nil)
|
145
145
|
raise 'You must specify a name for a service' if name.nil?
|
146
146
|
|
147
|
-
path =
|
147
|
+
path = '/v1/health/checks/' + ERB::Util.url_encode(name.to_s)
|
148
148
|
query_params = {}
|
149
149
|
query_params[:dc] = dc if dc
|
150
150
|
query_params[:passing] = passing if passing
|
@@ -155,7 +155,7 @@ module Consul
|
|
155
155
|
def checks_for_node(name, dc: nil, passing: false, agent: nil)
|
156
156
|
raise 'You must specify a name for a service' if name.nil?
|
157
157
|
|
158
|
-
path =
|
158
|
+
path = '/v1/health/node/' + ERB::Util.url_encode(name.to_s)
|
159
159
|
query_params = {}
|
160
160
|
query_params[:dc] = dc if dc
|
161
161
|
query_params[:passing] = passing if passing
|
@@ -184,10 +184,10 @@ module Consul
|
|
184
184
|
|
185
185
|
# https://www.consul.io/api/catalog.html#list-services-for-node
|
186
186
|
def node(name_or_id, dc: nil, agent: nil)
|
187
|
-
path =
|
187
|
+
path = '/v1/catalog/node/' + ERB::Util.url_encode(name_or_id.to_s)
|
188
188
|
query_params = {}
|
189
189
|
query_params[:dc] = dc if dc
|
190
|
-
create_if_missing(path, query_params, agent: agent) {
|
190
|
+
create_if_missing(path, query_params, agent: agent) { ConsulTemplateNode.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '{}', agent)) }
|
191
191
|
end
|
192
192
|
|
193
193
|
# https://www.consul.io/api/agent.html#read-configuration
|
@@ -247,7 +247,7 @@ module Consul
|
|
247
247
|
|
248
248
|
# https://www.consul.io/api/kv.html#read-key
|
249
249
|
def kv(name = nil, dc: nil, keys: nil, recurse: false, agent: nil)
|
250
|
-
path =
|
250
|
+
path = '/v1/kv/' + ERB::Util.url_encode(name.to_s)
|
251
251
|
query_params = {}
|
252
252
|
query_params[:dc] = dc if dc
|
253
253
|
query_params[:recurse] = recurse if recurse
|
@@ -400,8 +400,9 @@ module Consul
|
|
400
400
|
agent: nil, endpoint_id: nil)
|
401
401
|
endpoint_id ||= begin
|
402
402
|
fqdn = path.dup
|
403
|
+
fqdn = "#{agent}#{fqdn}"
|
403
404
|
query_params.each_pair do |k, v|
|
404
|
-
fqdn
|
405
|
+
fqdn += "&#{k}=#{v}"
|
405
406
|
end
|
406
407
|
fqdn
|
407
408
|
end
|
@@ -628,6 +629,36 @@ module Consul
|
|
628
629
|
end
|
629
630
|
end
|
630
631
|
|
632
|
+
# Get information about a single node
|
633
|
+
class ConsulTemplateNode < ConsulTemplateAbstractMap
|
634
|
+
def initialize(consul_endpoint)
|
635
|
+
super(consul_endpoint)
|
636
|
+
end
|
637
|
+
|
638
|
+
def exists?
|
639
|
+
!result_delegate.nil?
|
640
|
+
end
|
641
|
+
|
642
|
+
def safe_get
|
643
|
+
if exists?
|
644
|
+
result_delegate
|
645
|
+
else
|
646
|
+
{
|
647
|
+
'Node': {},
|
648
|
+
'Services': {}
|
649
|
+
}
|
650
|
+
end
|
651
|
+
end
|
652
|
+
|
653
|
+
def node
|
654
|
+
safe_get['Node'] || {}
|
655
|
+
end
|
656
|
+
|
657
|
+
def services
|
658
|
+
safe_get['Services'] || {}
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
631
662
|
# List of nodes of the whole cluster
|
632
663
|
class ConsulTemplateNodes < ConsulTemplateAbstractArray
|
633
664
|
def initialize(consul_endpoint)
|
data/lib/consul/async/debug.rb
CHANGED
@@ -26,7 +26,10 @@ module Consul
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.print_info(msg)
|
29
|
+
return unless level > 1
|
30
|
+
|
29
31
|
STDERR.print "[INFO] #{msg}" if level > 1
|
32
|
+
warn '' if ENV['LOG_STREAM']
|
30
33
|
end
|
31
34
|
|
32
35
|
def self.puts_debug(msg)
|
@@ -34,7 +37,10 @@ module Consul
|
|
34
37
|
end
|
35
38
|
|
36
39
|
def self.print_debug(msg)
|
37
|
-
|
40
|
+
return unless level > 2
|
41
|
+
|
42
|
+
STDERR.print "[DEBG] #{msg}"
|
43
|
+
warn '' if ENV['LOG_STREAM']
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
data/lib/consul/async/version.rb
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
@sort_consul_service_nodes.call(service(service_name)).each do |snode|
|
37
37
|
tags_of_instance = snode['Service']['Tags'].sort
|
38
38
|
if (instance_must_tag.nil? || tags_of_instance.include?(instance_must_tag)) && !tags_of_instance.include?(instance_exclude_tag)
|
39
|
-
the_backends << snode
|
39
|
+
the_backends << snode
|
40
40
|
end
|
41
41
|
end
|
42
42
|
# We add the backend ONLY if at least one valid instance does exists
|
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.
|
4
|
+
version: 1.33.2
|
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:
|
11
|
+
date: 2022-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|
@@ -256,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
256
256
|
- !ruby/object:Gem::Version
|
257
257
|
version: '0'
|
258
258
|
requirements: []
|
259
|
-
rubygems_version: 3.1.
|
259
|
+
rubygems_version: 3.1.6
|
260
260
|
signing_key:
|
261
261
|
specification_version: 4
|
262
262
|
summary: Implementation of Consul template using Ruby and .erb templating language
|