consul-templaterb 1.32.1 → 1.33.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c45366cab4f4e92c620ccd80d1263afd031b3b26163630e7969d1dd68c7136e
4
- data.tar.gz: 89c565116147e7e9ae610dad3bbfb378f0ccdfaaf0ccf1f7738f257264ee7517
3
+ metadata.gz: d8b9211a298b666e2259e3133382b4aa56bc3b3c653eb43fd39a8238059b2e44
4
+ data.tar.gz: 46fc67cacf37aa5b73742631d666c31b4ed4430d84d8cb879b817455acdf2f7d
5
5
  SHA512:
6
- metadata.gz: 322c5a2ba771c67090b06a87dcf01d9977846d665423bc5dbeda38188343d94f94b78c35fa7ebdac7936e2180eab91dc60f4c66cdf9fcd660605133ca6eca07e
7
- data.tar.gz: a08fa814f2b7b9ec2ca5e6a5ee7a18fcfbbd74602cafa6cc9ae24f1ca664621f746824dab7664fcac29f270590c7a7c8939b993c92013174eaf2c94f1117a517
6
+ metadata.gz: 9fdda46240f515afaa8a00058b7a75d5369cb7a79efcaad731fe09cc94518938acd1d0ae9d0dfbbe65169e2ee0718512266290043aa822259900ba8e3b9cff06
7
+ data.tar.gz: e8dc85835f36c5ff2c4343a5d961817f145d194070bec9394dc3500b8a5400e6e2bb39c2cc1648d59a570967794f48edd28d87e84694dfd88692d26a52180cfe
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 1.31.1 (Jan 28, 2021)
3
+ ## 1.33.0 (Nov 22, 2021)
4
+
5
+ IMPROVEMENTS:
6
+
7
+ * Validate ssl peers
8
+ * Allow to stream log lines
9
+ * [CONSUL-UI] Display services with no port definition
10
+ * Hide opts in logs by default
11
+
12
+ ## 1.32.1 (Jan 28, 2021)
4
13
 
5
14
  IMPROVEMENTS:
6
15
 
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
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.to_json
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))
@@ -187,7 +187,7 @@ module Consul
187
187
  path = "/v1/catalog/node/#{name_or_id}"
188
188
  query_params = {}
189
189
  query_params[:dc] = dc if dc
190
- create_if_missing(path, query_params, agent: agent) { ConsulTemplateNodes.new(ConsulEndpoint.new(consul_conf, path, true, query_params, '{}', 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
@@ -628,6 +628,36 @@ module Consul
628
628
  end
629
629
  end
630
630
 
631
+ # Get information about a single node
632
+ class ConsulTemplateNode < ConsulTemplateAbstractMap
633
+ def initialize(consul_endpoint)
634
+ super(consul_endpoint)
635
+ end
636
+
637
+ def exists?
638
+ !result_delegate.nil?
639
+ end
640
+
641
+ def safe_get
642
+ if exists?
643
+ result_delegate
644
+ else
645
+ {
646
+ 'Node': {},
647
+ 'Services': {}
648
+ }
649
+ end
650
+ end
651
+
652
+ def node
653
+ safe_get['Node'] || {}
654
+ end
655
+
656
+ def services
657
+ safe_get['Services'] || {}
658
+ end
659
+ end
660
+
631
661
  # List of nodes of the whole cluster
632
662
  class ConsulTemplateNodes < ConsulTemplateAbstractArray
633
663
  def initialize(consul_endpoint)
@@ -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
- STDERR.print "[DEBG] #{msg}" if level > 2
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
@@ -184,6 +184,7 @@ module Consul
184
184
 
185
185
  def fetch
186
186
  options = {
187
+ tls: { verify_peer: conf.tls_verify_peer },
187
188
  connect_timeout: 5, # default connection setup timeout
188
189
  inactivity_timeout: 60 # default connection inactivity (post-setup) timeout
189
190
  }
@@ -230,6 +230,7 @@ module Consul
230
230
 
231
231
  def fetch
232
232
  options = {
233
+ tls: { verify_peer: conf.tls_verify_peer },
233
234
  connect_timeout: 5, # default connection setup timeout
234
235
  inactivity_timeout: 1 # default connection inactivity (post-setup) timeout
235
236
  }
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.32.1'.freeze
3
+ VERSION = '1.33.0'.freeze
4
4
  end
5
5
  end
@@ -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 if snode['Service']['Port']
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.32.1
4
+ version: 1.33.0
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: 2021-01-28 00:00:00.000000000 Z
11
+ date: 2021-11-22 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.4
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