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 +8 -8
- data/Gemfile.lock +5 -5
- data/bin/consul-template-generator +6 -0
- data/lib/consul/template/generator.rb +8 -2
- data/lib/consul/template/generator/cmd.rb +2 -1
- data/lib/consul/template/generator/configuration.rb +3 -2
- data/lib/consul/template/generator/init.rb +1 -1
- data/lib/consul/template/generator/run.rb +4 -4
- data/lib/consul/template/generator/version.rb +1 -1
- data/spec/init_spec.rb +17 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2YzMmY3Y2Y5NzhlMzY2YjZiNjgxZWQ4ZWFiYzVkOGNlOGM0ODZlZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjJjODFlNzRjM2EyNzk0MjM4ODViMWFjZGM5MGNmOTg0Mzc3YTUzMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjMyZjZkYmMzNzRiOWYwMmU2MjQwZTZhYTgxMjJkYzdhZWExZjI1MzkxYTY5
|
10
|
+
Zjg3Y2EyNzhiNDMxNjRkMzY3NzEwMGRhYzdjYjU2ZDc3MDVlNWIwMjBmMjcw
|
11
|
+
NzliYTQyMmYxYTlmNjA1NjNiNDlmZmIxYTc2ODg1ODVlMGUzMjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWVkYWEwN2ZkZDgwN2QyZTdkNzk5MzE2YjRmNjFjYWEwZjZkMTk4ZDI4ZjFh
|
14
|
+
MWNmYTBjZjkyNWVmNGMyODM5MjQyZWFiOTM4OGQ4MmMxOTYwNGJkN2FmMzQy
|
15
|
+
NWNkYzI0ZmMwMDQ3ODQ0YzgzZjQ4ZjRiY2UxMzk2ZjBhZWM0MjE=
|
data/Gemfile.lock
CHANGED
@@ -2,9 +2,9 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
consul-template-generator (0.3.4)
|
5
|
-
|
6
|
-
diplomat (~> 0.13
|
7
|
-
popen4 (~> 0.1
|
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
|
-
|
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.
|
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
|
-
|
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
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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)
|
data/spec/init_spec.rb
CHANGED
@@ -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
|
+
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:
|
11
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|