consul-template-generator 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8bc42e4ac6ae599136ce6b8c458d8a72bc1db9c2
4
- data.tar.gz: eaa801befcdbc1196ad2bc753c7ec5e0ff3960e1
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2ZiNGE1Yzc5NGZhMTMwYWJmNDhmMjg0NDRhODM4MDU4N2UxYzcwOA==
5
+ data.tar.gz: !binary |-
6
+ MmU1ODM0M2QyYjlkYzlhMzIzY2JiMThkZDE3OTQ0ODE1M2MxZDVmMQ==
5
7
  SHA512:
6
- metadata.gz: 5f036b92be9660f0478e4c6dd514fffa2ce65bb89f25e3ebd8818d3d4bcb5982d333d9a6fab02dc7fb8cb7dc9488278f1298c082479b72a2a1b9b1b45cb350be
7
- data.tar.gz: ed9399d2f4c696d89b7e30a69dfd7280066517ea7fabf578c3b35615967116468e556aff9e8814f4d5a2c0a3ff3fad5790443b8a33c3f54412997e97405dce7e
8
+ metadata.gz: !binary |-
9
+ ZGMwYmI1YTI3YTVkMzQ0OTcxZDkxM2Y5NTIzMTkzYmM0YzE5NjA3YjU2NmIz
10
+ Mjk5ZmJiOWFhYjIwZjFjNDUxMDAyNWYwMmJjMGVjNjRiOTM2YmMyYzc5YjZh
11
+ OWIyN2U3ZWNkMmY2NWY1ZTkyNTkzNjY2NTg0NmM4MzRmYTkxZWY=
12
+ data.tar.gz: !binary |-
13
+ ZDA1MmI3M2QxZGJmODU1MmMwYmEzZTBjMThkMjc2Y2FlMGNjM2IyZjNjYTFi
14
+ ODkyZDMxY2JmNWQ4MjI2YWQxZTdmNWY0ZTdmYmYwYWU4OGQzNTZjYmZlYTFh
15
+ Yjg0ZjBlNDI3NGQzNjM3NTAzYTA4YmZmMDRmNTYzZmExZjBhZmE=
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- consul-template-generator (0.3.3)
5
- diplomat (~> 0.12.0)
4
+ consul-template-generator (0.3.4)
5
+ differ (~> 0.1.2)
6
+ diplomat (~> 0.13.0)
6
7
  popen4 (~> 0.1.2)
7
8
 
8
9
  GEM
@@ -14,7 +15,8 @@ GEM
14
15
  crack (0.4.2)
15
16
  safe_yaml (~> 1.0.0)
16
17
  diff-lcs (1.2.5)
17
- diplomat (0.12.0)
18
+ differ (0.1.2)
19
+ diplomat (0.13.1)
18
20
  faraday (~> 0.9)
19
21
  json (~> 1.8)
20
22
  docile (1.1.5)
@@ -67,6 +67,11 @@ EOC
67
67
  options[:unset_proxy] = true
68
68
  end
69
69
 
70
+ options[:diff_changes] = false
71
+ opts.on(nil, '--diff-changes', "Print diff'ed template prior to upload") do |u|
72
+ options[:diff_changes] = true
73
+ end
74
+
70
75
  options[:log_level] = :info
71
76
  opts.on('-l LOG_LEVEL', '--log-level LOG_LEVEL', "Log level, options are 'debug', 'info', 'error' [default: info]") do |l|
72
77
  options[:log_level] = l.to_sym
@@ -110,7 +115,15 @@ if options[:unset_proxy]
110
115
  ENV['http_proxy'] = nil
111
116
  end
112
117
 
113
- CMD.configure(options[:consul], options[:templates], options[:session_key], options[:log_level], options[:graphite_host], options[:graphite_paths])
118
+ CMD.configure(
119
+ options[:consul],
120
+ options[:templates],
121
+ options[:session_key],
122
+ options[:log_level],
123
+ options[:graphite_host],
124
+ options[:graphite_paths],
125
+ options[:diff_changes],
126
+ )
114
127
 
115
128
  ec = 1
116
129
  cmd = ARGV[0]
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'simplecov-console', '~> 0.2'
26
26
  spec.add_development_dependency 'webmock', '~> 1.21'
27
27
  spec.add_development_dependency 'rack', '~> 1.6'
28
- spec.add_dependency 'diplomat', '~> 0.12.0'
29
- spec.add_dependency 'popen4', '~> 0.1.2'
28
+ spec.add_dependency 'diffy', '~> 3.0'
29
+ spec.add_dependency 'diplomat', '~> 0.13'
30
+ spec.add_dependency 'popen4', '~> 0.1'
30
31
  end
@@ -7,7 +7,7 @@ module Consul
7
7
  include Consul::Template::Generator
8
8
  class << self
9
9
 
10
- def configure(consul_host, templates, session_key, log_level, graphite_host = nil, graphite_paths = nil)
10
+ def configure(consul_host, templates, session_key, log_level, graphite_host = nil, graphite_paths = nil, diff_changes = false)
11
11
  Consul::Template::Generator.configure do |config|
12
12
  config.log_level = log_level
13
13
  config.templates = templates
@@ -15,6 +15,7 @@ module Consul
15
15
  config.consul_host = consul_host
16
16
  config.graphite_host = graphite_host
17
17
  config.graphite_paths = graphite_paths || {}
18
+ config.diff_changes = diff_changes
18
19
  end
19
20
  @config = Consul::Template::Generator.config
20
21
  end
@@ -46,7 +47,7 @@ module Consul
46
47
  @config.logger.info "Session lock acquired..."
47
48
  begin
48
49
  @config.templates.each do |template,template_key|
49
- new_hash = runner.run(template, template_key, uploaded_hashes[template])
50
+ new_hash = runner.run(template, template_key, uploaded_hashes[template], @config.diff_changes)
50
51
  unless new_hash.nil?
51
52
  uploaded_hashes[template] = new_hash
52
53
  if @config.graphite_paths.include? template
@@ -79,7 +80,7 @@ module Consul
79
80
  begin
80
81
  @config.templates.each do |template,template_key|
81
82
  runner = CTRunner.new
82
- result = runner.run(template, template_key)
83
+ result = runner.run(template, template_key, nil, @config.diff_changes)
83
84
  unless result.nil?
84
85
  if @config.graphite_paths.include? template
85
86
  runner.post_graphite_event @config.graphite_paths[template]
@@ -39,7 +39,7 @@ module Consul
39
39
  end
40
40
 
41
41
  class Configuration
42
- attr_accessor :templates, :session_key, :consul_template_binary, :logger, :log_level, :graphite_host, :graphite_paths
42
+ attr_accessor :templates, :session_key, :consul_template_binary, :logger, :log_level, :graphite_host, :graphite_paths, :diff_changes
43
43
  attr_accessor :consul_host, :node, :client_options
44
44
 
45
45
  def initialize
@@ -52,6 +52,7 @@ module Consul
52
52
  @client_options = {}
53
53
  @logger = Consul::Template::Generator::STDLogger
54
54
  @graphite_host = nil
55
+ @diff_changes = false
55
56
  end
56
57
 
57
58
  def lock_key(key)
@@ -35,6 +35,15 @@ module Consul
35
35
  raise TemplateUploadError, "Encountered an unexpected error while uploading template: #{e.message}"
36
36
  end
37
37
  end
38
+
39
+ def retrieve_template(template_key)
40
+ @config.logger.info "Downloading key: #{template_key}"
41
+ begin
42
+ Diplomat::Kv.get(template_key, nil, :return, :return)
43
+ rescue Exception => e
44
+ raise TemplateUploadError, "Encountered an unexpected error while uploading template: #{e.message}"
45
+ end
46
+ end
38
47
  end
39
48
  end
40
49
  end
@@ -1,10 +1,11 @@
1
+ require 'diffy'
1
2
  require 'consul/template/generator/ct'
2
3
 
3
4
  module Consul
4
5
  module Template
5
6
  module Generator
6
7
  class CTRunner
7
- def run(template, template_key, comp_hash = nil)
8
+ def run(template, template_key, comp_hash = nil, diff_changes = false)
8
9
  status, body, hash, uploaded_hash = nil, nil, nil, nil
9
10
  acquire_lock template_key do
10
11
  @config.logger.debug "Attempting to render template: #{template}"
@@ -19,6 +20,14 @@ module Consul
19
20
  if comp_hash.nil? || comp_hash != hash
20
21
  @config.logger.info "Change in template discovered, attempting to upload to key #{template_key}"
21
22
  @config.logger.debug "Existing hash: #{comp_hash || 'nil'}, new hash: #{hash}"
23
+
24
+ if diff_changes
25
+ @config.logger.info "Diffing templates..."
26
+ curr_template = retrieve_template template_key
27
+ diff = Diffy::Diff.new(curr_template, body, :include_diff_info => true, :context => 5).to_s(:text)
28
+ @config.logger.info diff
29
+ end
30
+
22
31
  uploaded = upload_template(template_key, body)
23
32
  if uploaded
24
33
  @config.logger.info "New template uploaded..."
@@ -1,7 +1,7 @@
1
1
  module Consul
2
2
  module Template
3
3
  module Generator
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.4'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consul-template-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Oldfield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-04 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,34 +108,48 @@ dependencies:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: diffy
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: diplomat
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ~>
116
130
  - !ruby/object:Gem::Version
117
- version: 0.12.0
131
+ version: '0.13'
118
132
  type: :runtime
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - ~>
123
137
  - !ruby/object:Gem::Version
124
- version: 0.12.0
138
+ version: '0.13'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: popen4
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - ~>
130
144
  - !ruby/object:Gem::Version
131
- version: 0.1.2
145
+ version: '0.1'
132
146
  type: :runtime
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - ~>
137
151
  - !ruby/object:Gem::Version
138
- version: 0.1.2
152
+ version: '0.1'
139
153
  description: When using complex consul-template templates or distributing them across
140
154
  many hosts, you run the risk of DoSing your consul cluster. Using consul-template-generator
141
155
  you can instead delegate the watching/rendering of templates to a single host and
@@ -181,12 +195,12 @@ require_paths:
181
195
  - lib
182
196
  required_ruby_version: !ruby/object:Gem::Requirement
183
197
  requirements:
184
- - - '>='
198
+ - - ! '>='
185
199
  - !ruby/object:Gem::Version
186
200
  version: '0'
187
201
  required_rubygems_version: !ruby/object:Gem::Requirement
188
202
  requirements:
189
- - - '>='
203
+ - - ! '>='
190
204
  - !ruby/object:Gem::Version
191
205
  version: '0'
192
206
  requirements: []
@@ -202,4 +216,3 @@ test_files:
202
216
  - spec/key_value_spec.rb
203
217
  - spec/run_spec.rb
204
218
  - spec/spec_helper.rb
205
- has_rdoc: