consul-templaterb 1.20.0 → 1.21.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: fdc12c65083f1f666615eec05c7b092839f28e05ad855a745271114305719a88
4
- data.tar.gz: c0d46a14a91d4622ba7819a1d0e6bda38410f9b3fde5c1c89fa7d141dd837f36
3
+ metadata.gz: 3785f26a91750c80a99a7874db8987e5bfb0bda73b3e6e7a2f959fe6ecdb7017
4
+ data.tar.gz: 5003cbc12c820ed815f5f3a691f98568d44637b39e08ac56cc4c700bbd9a49cb
5
5
  SHA512:
6
- metadata.gz: a78247bdaba4504bf6486faa24690f85fa86007ce49704def7f7dd123f2ea229c6b325c1c8e83c17d843f3c9f45a1a5708bbc48976a2bcb1b54950c07e74f3e8
7
- data.tar.gz: 44c4afb432414e4bca30e52617924e76c500bf9c5e289ba42224853f13d2ad13189d659dec310347ac3ad9e152e0fbedc8daa47a8b72db8df0014f3bbe4968cd
6
+ metadata.gz: 63646b061bc898e14de0c52c6880f8d119ca39db3a09cd35a61ccb0de80ecfff8310a0b3993c9abb5b11426a9cf79c9a69e52fa533882892b90b323bb2272873
7
+ data.tar.gz: 21e214c1c701dfd64629ea20c660f7960d4f6433c730fbf403014ea133f8bd0fbc9dc78a654ecaad82d4c7aded172cc2c0dd61202624ef502ca47b647c180e26
data/.gitignore CHANGED
@@ -12,6 +12,7 @@
12
12
  /samples/**/*.html
13
13
  /samples/**/*.txt
14
14
  /samples/**/*.cfg
15
+ samples/consul-ui/decorators.js
15
16
  /samples/hosts
16
17
  /samples/hosts_per_services
17
18
  /samples/prometheus_consul_coordinates
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## (UNRELEASED)
4
4
 
5
+ NEW FEATURES:
6
+
7
+ ## 1.21.0 (November 21, 2019)
8
+
9
+ * added function `templates` to list all templates being rendered
10
+ * added support for JS decorators in consul-ui (thanks to @Thib17)
11
+
5
12
  ## 1.20.0 (October 16, 2019)
6
13
 
7
14
  IMPROVEMENTS:
@@ -649,3 +649,26 @@ I am the file template_info.erb included from template include.erb rendered as d
649
649
 
650
650
  </div>
651
651
  </details>
652
+
653
+ ## templates
654
+
655
+ It returns list of templates evaluated by this instance of consul-templaterb.
656
+ Information returned is an array of elements where elements are `[template_name, template_destination, args]`.
657
+
658
+ <details><summary>Example</summary>
659
+ <div class="samples">
660
+
661
+ ### Display templates info
662
+
663
+ ```erb
664
+ Here are templates rendered by consul-templaterb:
665
+ <ul>
666
+ <% templates.each do |template, destination, args| %>
667
+ <li>I render <%= template %> with args <%= args.inspect %> and write the result to <%= destination %></li>
668
+ <% end %>
669
+ </ul>
670
+ ```
671
+
672
+ </div>
673
+ </details>
674
+
@@ -175,7 +175,7 @@ optparse = OptionParser.new do |opts|
175
175
  sig_term = cur_sig_term
176
176
  consul_engine.add_template_callback do |all_ready, template_manager, results|
177
177
  if all_ready
178
- modified = results.reduce(false) { |a, e| a || e.modified }
178
+ modified = results.any?(&:modified)
179
179
  if @programs[cmd].nil?
180
180
  STDERR.puts "[EXEC] Starting process: #{cmd}... on_reload=#{sig_reload ? sig_reload : 'NONE'} on_term=#{sig_term}"
181
181
  @programs[cmd] = Consul::Async::ProcessHandler.new(cmd, sig_reload: sig_reload, sig_term: sig_term)
@@ -290,7 +290,6 @@ EM.epoll
290
290
 
291
291
  consul_conf = Consul::Async::ConsulConfiguration.new(options[:consul])
292
292
  vault_conf = Consul::Async::VaultConfiguration.new(options[:vault])
293
- template_manager = Consul::Async::EndPointsManager.new(consul_conf, vault_conf, options[:erb][:trim_mode])
294
293
 
295
294
  ARGV.each do |tpl|
296
295
  dest = compute_default_output(tpl)
@@ -298,6 +297,8 @@ ARGV.each do |tpl|
298
297
  consul_engine.add_template(tpl, dest)
299
298
  end
300
299
 
300
+ template_manager = Consul::Async::EndPointsManager.new(consul_conf, vault_conf, consul_engine.templates, options[:erb][:trim_mode])
301
+
301
302
  Signal.trap('USR1', 'IGNORE') unless Gem.win_platform?
302
303
  # Ensure to kill child process if any
303
304
  ['EXIT'].each do |sig|
@@ -79,8 +79,8 @@ module Consul
79
79
  end
80
80
 
81
81
  class EndPointsManager
82
- attr_reader :consul_conf, :vault_conf, :net_info, :start_time, :coordinate, :remote_resource
83
- def initialize(consul_configuration, vault_configuration, trim_mode = nil)
82
+ attr_reader :consul_conf, :vault_conf, :net_info, :start_time, :coordinate, :remote_resource, :templates
83
+ def initialize(consul_configuration, vault_configuration, templates, trim_mode = nil)
84
84
  @consul_conf = consul_configuration
85
85
  @vault_conf = vault_configuration
86
86
  @trim_mode = trim_mode
@@ -95,6 +95,7 @@ module Consul
95
95
  changes: 0,
96
96
  network_bytes: 0
97
97
  }
98
+ @templates = templates
98
99
  @context = {
99
100
  current_erb_path: nil,
100
101
  template_info: {
@@ -10,7 +10,7 @@ require 'erb'
10
10
  module Consul
11
11
  module Async
12
12
  class ConsulTemplateEngine
13
- attr_reader :template_manager, :hot_reload_failure, :template_frequency, :debug_memory, :result
13
+ attr_reader :template_manager, :hot_reload_failure, :template_frequency, :debug_memory, :result, :templates
14
14
  attr_writer :hot_reload_failure, :template_frequency, :debug_memory
15
15
  def initialize
16
16
  @templates = []
@@ -45,7 +45,7 @@ module Consul
45
45
  # Run templating engine once
46
46
  def do_run(template_manager, template_renders)
47
47
  results = template_renders.map(&:run)
48
- all_ready = results.reduce(true) { |a, e| a && e.ready? }
48
+ all_ready = results.all?(&:ready?)
49
49
  if !@all_templates_rendered && all_ready
50
50
  @all_templates_rendered = true
51
51
  cur_time = Time.now
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.20.0'.freeze
3
+ VERSION = '1.21.0'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ <% templates.each do |erb_file, output_file, args| %>
2
+ <%= erb_file %> will be rendered as <%= output_file %>
3
+ <% end %>
@@ -64,6 +64,7 @@
64
64
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
65
65
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
66
66
  <script src="js/utils.js"></script>
67
+ <script src="decorators.js"></script>
67
68
  <script src="js/types.js"></script>
68
69
  <script src="js/service.js"></script>
69
70
  <script type="text/javascript">
@@ -0,0 +1,7 @@
1
+ function serviceInstanceDecorator(instance, element) {
2
+ return element;
3
+ }
4
+
5
+ function serviceMetaDecorator(key, value) {
6
+ return document.createTextNode(value);
7
+ }
@@ -313,7 +313,7 @@ class ServiceMainSelector extends MainSelector {
313
313
  element.appendChild(checksStatusGenerator(instance, instance.name));
314
314
  element.setAttribute("status", state);
315
315
 
316
- return element;
316
+ return serviceInstanceDecorator(instance, element);
317
317
  }
318
318
 
319
319
  getStatus(instance) {
@@ -189,7 +189,7 @@ function serviceMetaGenerator(instanceMeta) {
189
189
  container.appendChild(metaH);
190
190
  var metaVH = document.createElement('dd');
191
191
  metaVH.className = 'col-sm-8 lookup';
192
- metaVH.appendChild(document.createTextNode(instanceMeta[meta]));
192
+ metaVH.appendChild(serviceMetaDecorator(meta, instanceMeta[meta]));
193
193
  container.appendChild(metaVH);
194
194
  }
195
195
  }
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.20.0
4
+ version: 1.21.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: 2019-10-16 00:00:00.000000000 Z
11
+ date: 2019-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -192,6 +192,7 @@ files:
192
192
  - lib/consul/async/vault_endpoint.rb
193
193
  - lib/consul/async/version.rb
194
194
  - samples/all_services.txt.erb
195
+ - samples/all_templates.erb
195
196
  - samples/consul-ui/README.md
196
197
  - samples/consul-ui/common/header.html.erb
197
198
  - samples/consul-ui/consul-keys-ui.html.erb
@@ -202,6 +203,7 @@ files:
202
203
  - samples/consul-ui/consul_nodes.json.erb
203
204
  - samples/consul-ui/consul_services.json.erb
204
205
  - samples/consul-ui/css/style.css
206
+ - samples/consul-ui/decorators.js.erb
205
207
  - samples/consul-ui/images/favicon.png
206
208
  - samples/consul-ui/js/keys.js
207
209
  - samples/consul-ui/js/nodes.js