consul-template-generator 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/consul/template/generator.rb +4 -2
- data/lib/consul/template/generator/cmd.rb +2 -0
- data/lib/consul/template/generator/init.rb +19 -2
- data/lib/consul/template/generator/version.rb +1 -1
- data/spec/init_spec.rb +28 -4
- data/spec/spec_helper.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaef7a186c5c1fca60d93587c591ae1784f43fc5
|
4
|
+
data.tar.gz: 2a718fbc572f86694d7baa45d3fe2fe00e6d116c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ec46a6583238a47068a2ecb2d9a248c03fcd37484c780f742eb152f79aeb639aa7526249d31384d1a1057aaae91d7b881dd2a03bf2e8fe2d87e0e06371654c1
|
7
|
+
data.tar.gz: fe1eea1260ecc10e3247ecabcf92ab1e05b4e74663c3afdfe6913ba96c36a4c48c704d8f51764df6cdf5d3b8dd0f9fefae0dc2e9399a9da38c83d15f8ce680bd
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
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
|
|
@@ -6,11 +6,28 @@ module Consul
|
|
6
6
|
|
7
7
|
def initialize(consul_session_id = nil)
|
8
8
|
if consul_session_id.nil?
|
9
|
-
|
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
|
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
|
-
|
21
|
-
expect(
|
22
|
-
|
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.
|
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-
|
11
|
+
date: 2015-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|