consul-template-generator 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2ZiNGE1Yzc5NGZhMTMwYWJmNDhmMjg0NDRhODM4MDU4N2UxYzcwOA==
4
+ N2YzMmY3Y2Y5NzhlMzY2YjZiNjgxZWQ4ZWFiYzVkOGNlOGM0ODZlZA==
5
5
  data.tar.gz: !binary |-
6
- MmU1ODM0M2QyYjlkYzlhMzIzY2JiMThkZDE3OTQ0ODE1M2MxZDVmMQ==
6
+ MjJjODFlNzRjM2EyNzk0MjM4ODViMWFjZGM5MGNmOTg0Mzc3YTUzMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGMwYmI1YTI3YTVkMzQ0OTcxZDkxM2Y5NTIzMTkzYmM0YzE5NjA3YjU2NmIz
10
- Mjk5ZmJiOWFhYjIwZjFjNDUxMDAyNWYwMmJjMGVjNjRiOTM2YmMyYzc5YjZh
11
- OWIyN2U3ZWNkMmY2NWY1ZTkyNTkzNjY2NTg0NmM4MzRmYTkxZWY=
9
+ YjMyZjZkYmMzNzRiOWYwMmU2MjQwZTZhYTgxMjJkYzdhZWExZjI1MzkxYTY5
10
+ Zjg3Y2EyNzhiNDMxNjRkMzY3NzEwMGRhYzdjYjU2ZDc3MDVlNWIwMjBmMjcw
11
+ NzliYTQyMmYxYTlmNjA1NjNiNDlmZmIxYTc2ODg1ODVlMGUzMjI=
12
12
  data.tar.gz: !binary |-
13
- ZDA1MmI3M2QxZGJmODU1MmMwYmEzZTBjMThkMjc2Y2FlMGNjM2IyZjNjYTFi
14
- ODkyZDMxY2JmNWQ4MjI2YWQxZTdmNWY0ZTdmYmYwYWU4OGQzNTZjYmZlYTFh
15
- Yjg0ZjBlNDI3NGQzNjM3NTAzYTA4YmZmMDRmNTYzZmExZjBhZmE=
13
+ YWVkYWEwN2ZkZDgwN2QyZTdkNzk5MzE2YjRmNjFjYWEwZjZkMTk4ZDI4ZjFh
14
+ MWNmYTBjZjkyNWVmNGMyODM5MjQyZWFiOTM4OGQ4MmMxOTYwNGJkN2FmMzQy
15
+ NWNkYzI0ZmMwMDQ3ODQ0YzgzZjQ4ZjRiY2UxMzk2ZjBhZWM0MjE=
@@ -2,9 +2,9 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  consul-template-generator (0.3.4)
5
- differ (~> 0.1.2)
6
- diplomat (~> 0.13.0)
7
- popen4 (~> 0.1.2)
5
+ diffy (~> 3.0)
6
+ diplomat (~> 0.13)
7
+ popen4 (~> 0.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -15,12 +15,12 @@ GEM
15
15
  crack (0.4.2)
16
16
  safe_yaml (~> 1.0.0)
17
17
  diff-lcs (1.2.5)
18
- differ (0.1.2)
18
+ diffy (3.0.7)
19
19
  diplomat (0.13.1)
20
20
  faraday (~> 0.9)
21
21
  json (~> 1.8)
22
22
  docile (1.1.5)
23
- faraday (0.9.1)
23
+ faraday (0.9.2)
24
24
  multipart-post (>= 1.2, < 3)
25
25
  hirb (0.7.3)
26
26
  json (1.8.3)
@@ -62,6 +62,11 @@ EOC
62
62
  options[:session_key] = l
63
63
  end
64
64
 
65
+ options[:session_ttl] = 30
66
+ opts.on(nil, '--session-ttl SESSION_TTL', "Set a TTL for consul sessions (sets an implicit ttl on locks created by consul-template-generator [default: 30]") do |ttl|
67
+ options[:session_ttl] = ttl.to_i
68
+ end
69
+
65
70
  options[:unset_proxy] = false
66
71
  opts.on(nil, '--unset-proxy', "Use if 'http_proxy' is set in your environment, but you don't want to use it...") do |u|
67
72
  options[:unset_proxy] = true
@@ -123,6 +128,7 @@ CMD.configure(
123
128
  options[:graphite_host],
124
129
  options[:graphite_paths],
125
130
  options[:diff_changes],
131
+ options[:session_ttl]
126
132
  )
127
133
 
128
134
  ec = 1
@@ -42,8 +42,14 @@ module Consul
42
42
  end
43
43
  end
44
44
 
45
- def create_session(name)
46
- Diplomat::Session.create({:Node => self.config.node, :Name => name, :Behavior => 'release'})
45
+ def create_session(name, ttl_seconds = 30)
46
+ opts = {
47
+ :Node => self.config.node,
48
+ :Name => name,
49
+ :Behavior => 'release',
50
+ :TTL => "#{ttl_seconds}s"
51
+ }
52
+ Diplomat::Session.create(opts)
47
53
  end
48
54
 
49
55
  def renew_session(sess_id)
@@ -7,11 +7,12 @@ 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, diff_changes = false)
10
+ def configure(consul_host, templates, session_key, log_level, graphite_host = nil, graphite_paths = nil, diff_changes = false, session_ttl = nil)
11
11
  Consul::Template::Generator.configure do |config|
12
12
  config.log_level = log_level
13
13
  config.templates = templates
14
14
  config.session_key = session_key
15
+ config.session_ttl = session_ttl || 30
15
16
  config.consul_host = consul_host
16
17
  config.graphite_host = graphite_host
17
18
  config.graphite_paths = graphite_paths || {}
@@ -39,8 +39,8 @@ 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, :diff_changes
43
- attr_accessor :consul_host, :node, :client_options
42
+ attr_accessor :templates, :session_key, :session_ttl, :consul_template_binary, :logger, :log_level, :graphite_host
43
+ attr_accessor :consul_host, :node, :client_options, :diff_changes, :graphite_paths
44
44
 
45
45
  def initialize
46
46
  @log_level = :debug
@@ -49,6 +49,7 @@ module Consul
49
49
  @templates = {}
50
50
  @graphite_paths = {}
51
51
  @session_key = 'consul-template-generator'
52
+ @session_ttl = 30
52
53
  @client_options = {}
53
54
  @logger = Consul::Template::Generator::STDLogger
54
55
  @graphite_host = nil
@@ -17,7 +17,7 @@ module Consul
17
17
  unless @session.nil?
18
18
  destroy_session
19
19
  end
20
- @session = Consul::Template::Generator.create_session @config.session_name
20
+ @session = Consul::Template::Generator.create_session @config.session_name, @config.session_ttl
21
21
  end
22
22
 
23
23
  def destroy_session
@@ -22,10 +22,10 @@ module Consul
22
22
  @config.logger.debug "Existing hash: #{comp_hash || 'nil'}, new hash: #{hash}"
23
23
 
24
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
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
29
  end
30
30
 
31
31
  uploaded = upload_template(template_key, body)
@@ -1,7 +1,7 @@
1
1
  module Consul
2
2
  module Template
3
3
  module Generator
4
- VERSION = '0.3.4'
4
+ VERSION = '0.3.5'
5
5
  end
6
6
  end
7
7
  end
@@ -21,7 +21,7 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
21
21
  runner = Consul::Template::Generator::CTRunner.new
22
22
  expect(runner.session).to eql('test-session-id')
23
23
  runner.destroy_session
24
- expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release"}')
24
+ expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release","TTL":"30s"}')
25
25
  expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/test-session-id')
26
26
  expect(runner.session).to be_nil
27
27
  end
@@ -31,7 +31,7 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
31
31
  expect(runner.session).to eql('destroyed-session')
32
32
  runner.create_session
33
33
  runner.destroy_session
34
- expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release"}')
34
+ expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release","TTL":"30s"}')
35
35
  expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/destroyed-session')
36
36
  expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/test-session-id')
37
37
  expect(runner.session).to be_nil
@@ -41,7 +41,7 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
41
41
  runner = Consul::Template::Generator::CTRunner.new 'failed-destroyed-session'
42
42
  expect(runner.session).to eql('failed-destroyed-session')
43
43
  runner.create_session
44
- expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release"}')
44
+ expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release","TTL":"30s"}')
45
45
  expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/failed-destroyed-session').times(5)
46
46
  expect(runner.session).to eql('test-session-id')
47
47
  end
@@ -53,5 +53,19 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
53
53
  runner.destroy_session
54
54
  expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/').times(0)
55
55
  end
56
+
57
+ it "allows setting session ttl" do
58
+ Consul::Template::Generator.configure do |config|
59
+ config.templates = {'test-session-template.ctmpl' => 'test-session-template' }
60
+ config.node = 'test-node'
61
+ config.log_level = :off
62
+ config.session_key = '/session/consul-template-generator'
63
+ config.session_ttl = 10
64
+ config.consul_template_binary = 'consul-template'
65
+ end
66
+ runner = Consul::Template::Generator::CTRunner.new 'ttl-session'
67
+ runner.create_session
68
+ expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release","TTL":"10s"}')
69
+ end
56
70
  end
57
71
  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.4
4
+ version: 0.3.5
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-14 00:00:00.000000000 Z
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler