consul_watcher 0.0.7 → 0.0.8
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 +4 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/docker-entrypoint.sh +2 -0
- data/lib/consul_watcher.rb +2 -1
- data/lib/consul_watcher/destination/amqp.rb +24 -24
- data/lib/consul_watcher/watch_type/key.rb +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 229edb91677150898553354f076ef07e1789d2adfe3b1a648a48d61778d474a2
|
4
|
+
data.tar.gz: 665d041e916790682cb375795302f448c55dcf74b5e411a851b2d7e5e3962fb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e82d5923dab083db57f3d7c1a71641e8420ac0f52cd166d6acb06fc33b7149e3780c88b291996ff61f6e02982720800e36d7f4cbf7133826d1577ce5a3f05c03
|
7
|
+
data.tar.gz: 5ff07f4b9ff6b5d5644db74acb4d9b72b864bf38db98a1e1130cc4e3faa992eb8323569a7b6a64df1aa494de40e2dea92a777017c801abe0a0a5f7272f691fbc
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/docker-entrypoint.sh
CHANGED
@@ -8,6 +8,8 @@ echo "CLI_ARGS: \"${@}\""
|
|
8
8
|
echo "WATCH_ARGS: \"${WATCH_ARGS}\""
|
9
9
|
echo "WATCH_SCRIPT: \"${WATCH_SCRIPT}\""
|
10
10
|
echo "CONSUL_HTTP_ADDR: \"${CONSUL_HTTP_ADDR}\""
|
11
|
+
export CONSUL_DC="$(curl ${CONSUL_HTTP_ADDR}/v1/agent/self | jq -r '.Config.Datacenter')"
|
12
|
+
echo "CONSUL_DC: \"${CONSUL_DC}\""
|
11
13
|
echo "RUN_ONCE: \"${RUN_ONCE}\""
|
12
14
|
if [[ ${#} != 0 ]]; then
|
13
15
|
exec $@
|
data/lib/consul_watcher.rb
CHANGED
@@ -9,12 +9,13 @@ require 'consul_watcher/filters'
|
|
9
9
|
# Top Level module to run watch logic
|
10
10
|
module ConsulWatcher
|
11
11
|
def self.watch(config)
|
12
|
+
dc = ENV['CONSUL_DC']
|
12
13
|
logger = Logger.new(STDOUT)
|
13
14
|
logger.level = Logger::INFO
|
14
15
|
assemble(config)
|
15
16
|
current_watch_json = $stdin.read
|
16
17
|
previous_watch_json = @storage.fetch
|
17
|
-
changes = @watch_type.get_changes(previous_watch_json, current_watch_json)
|
18
|
+
changes = @watch_type.get_changes(previous_watch_json, current_watch_json, dc)
|
18
19
|
changes.each do |change|
|
19
20
|
@destination.send(change)
|
20
21
|
end
|
@@ -12,32 +12,32 @@ module ConsulWatcher
|
|
12
12
|
|
13
13
|
def initialize(destination_config)
|
14
14
|
initialize_variables(destination_config)
|
15
|
-
|
15
|
+
setup_amqp
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
@conn = Bunny.new(
|
18
|
+
def setup_amqp
|
19
|
+
@conn = Bunny.new(amqp_opts)
|
20
20
|
@conn.start
|
21
21
|
@ch = @conn.create_channel
|
22
22
|
@ex = Bunny::Exchange.new(@ch,
|
23
23
|
:topic,
|
24
|
-
@
|
24
|
+
@amqp_exchange,
|
25
25
|
durable: true)
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def amqp_opts
|
29
29
|
opts = {}
|
30
|
-
opts[:vhost] = @
|
31
|
-
opts[:username] = @
|
32
|
-
opts[:password] = @
|
33
|
-
if @
|
34
|
-
opts[:addresses] = @
|
35
|
-
elsif @
|
36
|
-
opts[:hosts] = @
|
37
|
-
opts[:port] = @
|
38
|
-
elsif @
|
39
|
-
opts[:host] = @
|
40
|
-
opts[:port] = @
|
30
|
+
opts[:vhost] = @amqp_vhost
|
31
|
+
opts[:username] = @amqp_username
|
32
|
+
opts[:password] = @amqp_password
|
33
|
+
if @amqp_addresses
|
34
|
+
opts[:addresses] = @amqp_addresses
|
35
|
+
elsif @amqp_hosts
|
36
|
+
opts[:hosts] = @amqp_hosts
|
37
|
+
opts[:port] = @amqp_port if @amqp_port
|
38
|
+
elsif @amqp_host
|
39
|
+
opts[:host] = @amqp_host
|
40
|
+
opts[:port] = @amqp_port if @amqp_port
|
41
41
|
end
|
42
42
|
opts
|
43
43
|
end
|
@@ -60,14 +60,14 @@ module ConsulWatcher
|
|
60
60
|
logger.level = Logger::DEBUG
|
61
61
|
{
|
62
62
|
logger: logger,
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
63
|
+
amqp_host: nil,
|
64
|
+
amqp_hosts: nil,
|
65
|
+
amqp_addresses: nil,
|
66
|
+
amqp_port: '5672',
|
67
|
+
amqp_vhost: '/',
|
68
|
+
amqp_username: 'guest',
|
69
|
+
amqp_password: 'guest',
|
70
|
+
amqp_exchange: 'amq.topic'
|
71
71
|
}
|
72
72
|
end
|
73
73
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'base64'
|
4
4
|
require 'flazm_ruby_helpers/class'
|
5
|
+
require 'diplomat'
|
5
6
|
|
6
7
|
module ConsulWatcher
|
7
8
|
module WatchType
|
@@ -13,11 +14,11 @@ module ConsulWatcher
|
|
13
14
|
initialize_variables(watch_config)
|
14
15
|
end
|
15
16
|
|
16
|
-
def get_changes(previous_watch_json, current_watch_json)
|
17
|
+
def get_changes(previous_watch_json, current_watch_json, dc)
|
17
18
|
json_diff = get_diff(previous_watch_json, current_watch_json)
|
18
19
|
|
19
20
|
changes = json_diff.each.collect do |change|
|
20
|
-
formatted_change = format_change('key', change)
|
21
|
+
formatted_change = format_change('key', change, dc)
|
21
22
|
decode(formatted_change) if @decode_values
|
22
23
|
formatted_change
|
23
24
|
end.compact
|
@@ -52,10 +53,11 @@ module ConsulWatcher
|
|
52
53
|
end.reduce({}, :merge)
|
53
54
|
end
|
54
55
|
|
55
|
-
def format_change(watch_type, change)
|
56
|
+
def format_change(watch_type, change, dc)
|
56
57
|
old_value, new_value = change_values(change)
|
57
58
|
{
|
58
59
|
'id' => "consul_watcher.key.#{change[1][0].tr('/', '.')}",
|
60
|
+
'consul_dc' => dc,
|
59
61
|
'watch_type' => watch_type,
|
60
62
|
'key_path' => change[1][0],
|
61
63
|
'key_property' => change[1][1],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul_watcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Fortman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|