consul-template-generator 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8be4b2612c0cdde3c4ddc78e08af58fddae3fb12
4
- data.tar.gz: 594615f00d8f7f8ee0c97923d78666b600fd8755
3
+ metadata.gz: aaef7a186c5c1fca60d93587c591ae1784f43fc5
4
+ data.tar.gz: 2a718fbc572f86694d7baa45d3fe2fe00e6d116c
5
5
  SHA512:
6
- metadata.gz: c7aeee64cbdfe213d140a5f2a3c13d2cbfed1988a5e4bcf8fb1522abfc5ae68f755cde2156bafa5a6d8c3baef426f419b58f989562dce00b618a61e688e20396
7
- data.tar.gz: e449b39989b443d9f19a0f1405658c50ed96163cfc1fcf271a151e3dc0841d4ccb0256204768286e50f3a01d9a37daffd7c583b351b15077842b6506a123752b
6
+ metadata.gz: 0ec46a6583238a47068a2ecb2d9a248c03fcd37484c780f742eb152f79aeb639aa7526249d31384d1a1057aaae91d7b881dd2a03bf2e8fe2d87e0e06371654c1
7
+ data.tar.gz: fe1eea1260ecc10e3247ecabcf92ab1e05b4e74663c3afdfe6913ba96c36a4c48c704d8f51764df6cdf5d3b8dd0f9fefae0dc2e9399a9da38c83d15f8ce680bd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- consul-template-generator (0.1.0)
4
+ consul-template-generator (0.1.2)
5
5
  diplomat (~> 0.12.0)
6
6
  popen4 (~> 0.1.2)
7
7
 
@@ -52,11 +52,13 @@ module Consul
52
52
  def renew_session(sess_id)
53
53
  # There is an outstanding bug in Diplomat::Session.renew with a PR to fix
54
54
  # https://github.com/WeAreFarmGeek/diplomat/issues/43
55
- # Until it's merged and release, we have to skip renewing sessions...
56
55
  begin
57
- #Diplomat::Session.renew sess_id
56
+ Diplomat::Session.renew sess_id
58
57
  rescue Faraday::ResourceNotFound
59
58
  raise ConsulSessionExpired
59
+ rescue Exception => e
60
+ # Letting this go for the time being, until the above issue is fixed
61
+ self.config.logger.error "Unknown error occoured: #{e.message}"
60
62
  end
61
63
  end
62
64
 
@@ -51,6 +51,8 @@ module Consul
51
51
  config.logger.error "Received interrupt signal, exiting..."
52
52
  break
53
53
  end
54
+ ensure
55
+ runner.destroy_session
54
56
  end until false
55
57
  0
56
58
  end
@@ -6,11 +6,28 @@ module Consul
6
6
 
7
7
  def initialize(consul_session_id = nil)
8
8
  if consul_session_id.nil?
9
- consul_session_id = Consul::Template::Generator.create_session 'consul-template-generator'
9
+ create_session
10
+ else
11
+ @session = consul_session_id
10
12
  end
11
- @session = consul_session_id
12
13
  @config = Consul::Template::Generator.config
13
14
  end
15
+
16
+ def create_session
17
+ unless @session.nil?
18
+ destroy_session
19
+ end
20
+ @session = Consul::Template::Generator.create_session 'consul-template-generator'
21
+ end
22
+
23
+ def destroy_session
24
+ begin
25
+ Consul::Template::Generator.destroy_session @session
26
+ rescue
27
+ Consul::Template::Generator.config.logger.info "Failed to destroy session: #{@session}"
28
+ end
29
+ @session = nil
30
+ end
14
31
  end
15
32
  end
16
33
  end
@@ -1,7 +1,7 @@
1
1
  module Consul
2
2
  module Template
3
3
  module Generator
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
6
6
  end
7
7
  end
data/spec/init_spec.rb CHANGED
@@ -6,20 +6,44 @@ require 'consul/template/generator'
6
6
  include Consul::Template::Generator
7
7
 
8
8
  describe 'Consul::Template::Generator::CTRunner' '#initialize' do
9
- before do
9
+ before(:each) do
10
10
  Consul::Template::Generator.configure do |config|
11
11
  config.template = 'test-session-template.ctmpl'
12
12
  config.template_key = 'test-session-template'
13
13
  config.node = 'test-node'
14
+ config.log_level = :off
14
15
  config.consul_template_binary = 'consul-template'
15
16
  end
16
17
  end
17
18
 
18
19
  context 'initialization of Consul::Template::Generator::CTRunner' do
19
20
  it "creates session if token isn't passed" do
20
- @runner = Consul::Template::Generator::CTRunner.new
21
- expect(WebMock).to_not have_requested(:put, 'http://127.0.0.1:8500/v1/kv/session/create').with(:body => "{\"Node\": \"test-node\", \"Name\": \"consul-template-generator\"}")
22
- expect(@runner.session).to eql('test-session-id')
21
+ runner = Consul::Template::Generator::CTRunner.new
22
+ expect(runner.session).to eql('test-session-id')
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"}')
25
+ expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/test-session-id')
26
+ expect(runner.session).to be_nil
27
+ end
28
+
29
+ it "destroys previous session on create" do
30
+ runner = Consul::Template::Generator::CTRunner.new 'destroyed-session'
31
+ expect(runner.session).to eql('destroyed-session')
32
+ runner.create_session
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"}')
35
+ expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/destroyed-session')
36
+ expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/test-session-id')
37
+ expect(runner.session).to be_nil
38
+ end
39
+
40
+ it "handles filed session destroys" do
41
+ runner = Consul::Template::Generator::CTRunner.new 'failed-destroyed-session'
42
+ expect(runner.session).to eql('failed-destroyed-session')
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"}')
45
+ expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/failed-destroyed-session')
46
+ expect(runner.session).to eql('test-session-id')
23
47
  end
24
48
  end
25
49
  end
data/spec/spec_helper.rb CHANGED
@@ -30,6 +30,10 @@ class ConsulApiRack
30
30
  case env['PATH_INFO']
31
31
  when /\/v1\/session\/create/
32
32
  code, ret = 200, "{\"ID\": \"test-session-id\"}"
33
+ when /\/v1\/session\/destroy\/failed-destroyed-session/
34
+ code, ret = 500, 'false'
35
+ when /\/v1\/session\/destroy/
36
+ code, ret = 200, 'true'
33
37
  when /\/v1\/kv\/lock\//
34
38
  code, ret = process_lock(env['QUERY_STRING'])
35
39
  when /\/v1\/kv\//
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.1.1
4
+ version: 0.1.2
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-07-24 00:00:00.000000000 Z
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler