consul-templaterb 1.31.1 → 1.33.1

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: f5d188151cdf2f004d4993cc5620ad86ce8632e2de820ca6498d37ce8acbd4c9
4
- data.tar.gz: 6469c2b6d1a9032bb16fdfbe53b062a2271e3a787dcc0f52bb0e749c081081e4
3
+ metadata.gz: 18c7c1fcf9c8e0685664f79da1b48f7e15dabdaa959ad12172f64313877f9551
4
+ data.tar.gz: d54d351404c5f76d7e08b502b1f905b9709a2666a6641ad7c24aa7d9b122e6a7
5
5
  SHA512:
6
- metadata.gz: 498a5282930d98afe30840f8f167559783aafa7d17b9a902ff8950dac5727d8496c666d0dea01d10ac59cfe4e845ca5664ded482b16641d4723f3edd5fa9053a
7
- data.tar.gz: a2526b83b9083275b6d1057948d80457f8ea4aede46201b15408fe331a329430d6785f8372339b8c2e139da2f1fe96c13a699d4b6c936f98d411c26b797413c2
6
+ metadata.gz: 29b61accf646ff4fe11946f2bafc37bd6dea31e50b9d6c01a0ded3c3c1992ae394060f1e0711136492170810c6fe5f7a25e1b06a3930d6218986f0acfee5ca34
7
+ data.tar.gz: 50ab860a1eb59c0c7b99e97eb3ed95edfcfd94452917c69a462145d5d9700c16790631010c8aa7950b17d601b095bb3b799b11d852d84c3b23a1f0150ee230b7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.31.1 (Feb 281 2022)
4
+
5
+ BUG FIX:
6
+
7
+ * Correctly identify endpoints
8
+
9
+ ## 1.33.0 (Nov 22, 2021)
10
+
11
+ IMPROVEMENTS:
12
+
13
+ * Validate ssl peers
14
+ * Allow to stream log lines
15
+ * [CONSUL-UI] Display services with no port definition
16
+ * Hide opts in logs by default
17
+
18
+ ## 1.32.1 (Jan 28, 2021)
19
+
20
+ IMPROVEMENTS:
21
+
22
+ * Switched to Github Actions (build)
23
+ * No functional changes in GEM - Test release only
24
+
25
+ ## 1.32.0 (Jan 27, 2021)
26
+
27
+ IMPROVEMENTS:
28
+
29
+ * Use Ruby 2.7.2 in Travis build
30
+ * [VAULT] Do not handle missing secret as a blocking exception ([#73](https://github.com/criteo/consul-templaterb/pull/73))
31
+
3
32
  ## 1.31.1 (Jan 25, 2021)
4
33
 
5
34
  IMPROVEMENTS:
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # consul-templaterb
2
2
 
3
- [![Build Status](https://api.travis-ci.org/criteo/consul-templaterb.svg?branch=master)](https://travis-ci.org/criteo/consul-templaterb)
3
+ [![Build Status](https://github.com/criteo/consul-templaterb/workflows/Ruby/badge.svg?branch=master)](https://github.com/criteo/consul-templaterb/actions?query=branch%3Amaster)
4
4
  [![Gem Version](https://badge.fury.io/rb/consul-templaterb.svg)](http://github.com/criteo/consul-templaterb/releases)
5
5
  [![GEM Downloads](https://ruby-gem-downloads-badge.herokuapp.com/consul-templaterb?type=total&metric=true)](https://rubygems.org/gems/consul-templaterb)
6
6
  [![License](https://img.shields.io/badge/license-ApacheV2-yellowgreen.svg)](#license)
@@ -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
- $ be bin/consul-templaterb -c 'http://localhost:8500' samples/*.html.erb
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.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
@@ -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 = "#{agent}#{fqdn}&#{k}=#{v}"
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)
@@ -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
  }
@@ -245,7 +246,7 @@ module Consul
245
246
  http = connection.send(http_method.downcase, build_request) # Under the hood: c.send('get', {stuff}) === c.get({stuff})
246
247
  http.callback do
247
248
  http_result = VaultHttpResponse.new(http.dup.freeze, default_value)
248
- if enforce_json_200 && http.response_header.status != 200
249
+ if enforce_json_200 && ![200, 404].include?(http.response_header.status)
249
250
  _handle_error(http_result) { connection = EventMachine::HttpRequest.new(conf.base_url, options) }
250
251
  else
251
252
  @consecutive_errors = 0
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.31.1'.freeze
3
+ VERSION = '1.33.1'.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.31.1
4
+ version: 1.33.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: 2021-01-25 00:00:00.000000000 Z
11
+ date: 2022-02-21 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.0.8
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