consul_watcher 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/docs/TODO.md +2 -0
- data/lib/consul_watcher.rb +3 -3
- data/lib/consul_watcher/destination/amqp.rb +3 -3
- data/lib/consul_watcher/destination/jq.rb +2 -1
- data/lib/consul_watcher/filters.rb +5 -4
- data/lib/consul_watcher/storage/consul.rb +6 -6
- data/lib/consul_watcher/storage/disk.rb +33 -8
- data/lib/consul_watcher/watch_type/key.rb +4 -5
- metadata +2 -3
- data/lib/consul_watcher/class_helper.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c64ab6b82a3f373abf2f361dcf43fc08331d013abfb88d8d59c6f24599067197
|
4
|
+
data.tar.gz: 8ed45c066f4f81956edde455dee7a6885d6ee46fe50944e1331ed0914f6907ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d8af09da58ddf8865dc5b76a4e6db03ef39fb110356bc7e45c45c5f416b78870d0e0cb64204af65adf4c1b42a212e04ec71eb6b5f563aa4b76963d24becea94
|
7
|
+
data.tar.gz: 6b5d329ea148bc2ffa2e6d16cb460d0ea07d427536235fe56dec7135c3ed29845e0f027c530783d83588d87f2c9a9da9f2d629abf9f44229b1d79ba9c3939020
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# NOTICE
|
2
|
-
This gem is a work in progress. Please see the [TODO](https://github.com/fortman/consul_watcher/blob/master/docs/TODO.md) documentation
|
2
|
+
This gem is a work in progress. 0.0.x versions are considered to be in ALPHA state where functionality will vary greatly between versions. 0.1.0 will be the first BETA relese and will come with better backwards compatibility guarentees. Please see the [TODO](https://github.com/fortman/consul_watcher/blob/master/docs/TODO.md) documentation
|
3
3
|
|
4
4
|
## First 0.0.1 release. Partial functionality
|
5
5
|
- [ruby gem](https://rubygems.org/gems/consul_watcher)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/docs/TODO.md
CHANGED
data/lib/consul_watcher.rb
CHANGED
@@ -9,16 +9,16 @@ require 'consul_watcher/filters'
|
|
9
9
|
# Top Level module to run watch logic
|
10
10
|
module ConsulWatcher
|
11
11
|
def self.watch(config)
|
12
|
-
|
13
|
-
|
12
|
+
logger = Logger.new(STDOUT)
|
13
|
+
logger.level = Logger::INFO
|
14
14
|
assemble(config)
|
15
15
|
current_watch_json = $stdin.read
|
16
16
|
previous_watch_json = @storage.fetch
|
17
17
|
changes = @watch_type.get_changes(previous_watch_json, current_watch_json)
|
18
|
-
# @watch_type.filters.print_filters
|
19
18
|
changes.each do |change|
|
20
19
|
@destination.send(change)
|
21
20
|
end
|
21
|
+
logger.info("Processed #{changes.size} change#{'s' unless changes.size == 1}")
|
22
22
|
@storage.push(current_watch_json) unless changes.empty?
|
23
23
|
end
|
24
24
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bunny'
|
4
|
-
require 'consul_watcher/class_helper'
|
5
4
|
require 'json'
|
5
|
+
require 'flazm_ruby_helpers/class'
|
6
6
|
|
7
7
|
module ConsulWatcher
|
8
8
|
module Destination
|
9
9
|
# Send diff output to jq command line
|
10
10
|
class Amqp
|
11
|
-
include
|
11
|
+
include FlazmRubyHelpers::Class
|
12
12
|
|
13
13
|
def initialize(destination_config)
|
14
|
-
|
14
|
+
initialize_variables(destination_config)
|
15
15
|
setup_rabbitmq
|
16
16
|
end
|
17
17
|
|
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'open3'
|
4
4
|
require 'logger'
|
5
|
+
require 'flazm_ruby_helpers/class'
|
5
6
|
|
6
7
|
module ConsulWatcher
|
7
8
|
module Destination
|
8
9
|
# Send diff output to jq command line
|
9
10
|
class Jq
|
10
11
|
def initialize(destination_config)
|
11
|
-
|
12
|
+
initialize_variables(destination_config)
|
12
13
|
end
|
13
14
|
|
14
15
|
def send(change)
|
@@ -1,17 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'flazm_ruby_helpers/class'
|
4
|
+
require 'flazm_ruby_helpers/data_structures'
|
4
5
|
|
5
6
|
module ConsulWatcher
|
6
7
|
class Filters
|
7
|
-
include
|
8
|
+
include FlazmRubyHelpers::Class
|
8
9
|
|
9
10
|
def initialize(filter_config)
|
10
|
-
|
11
|
+
initialize_variables(filter_config)
|
11
12
|
end
|
12
13
|
|
13
14
|
def add_filters(filters_to_add)
|
14
|
-
@filters = @filters.deep_merge(filters_to_add)
|
15
|
+
@filters = @filters.deep_merge(filters_to_add) unless filters_to_add.nil?
|
15
16
|
end
|
16
17
|
|
17
18
|
def filter?(change)
|
@@ -1,25 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'diplomat'
|
4
|
-
require 'consul_watcher/class_helper'
|
5
4
|
require 'zlib'
|
5
|
+
require 'flazm_ruby_helpers/class'
|
6
6
|
|
7
7
|
# This will be a module to store previous consul watch json to compare with previous watch data
|
8
8
|
module ConsulWatcher
|
9
9
|
module Storage
|
10
10
|
# Consul storage for previous watch data
|
11
11
|
class Consul
|
12
|
-
include
|
12
|
+
include FlazmRubyHelpers::Class
|
13
13
|
|
14
14
|
def initialize(storage_config)
|
15
|
-
|
15
|
+
initialize_variables(storage_config)
|
16
16
|
config_diplomat
|
17
17
|
end
|
18
18
|
|
19
19
|
def fetch
|
20
20
|
@logger.debug('fetching state from consul')
|
21
21
|
data = Diplomat::Kv.get(cache_file_name)
|
22
|
-
data = Zlib::Inflate.inflate(data) if @
|
22
|
+
data = Zlib::Inflate.inflate(data) if @compress
|
23
23
|
data
|
24
24
|
rescue Diplomat::KeyNotFound
|
25
25
|
'{}'
|
@@ -27,7 +27,7 @@ module ConsulWatcher
|
|
27
27
|
|
28
28
|
def push(data)
|
29
29
|
@logger.debug('pushing state to consul')
|
30
|
-
Diplomat::Kv.put(cache_file_name, @
|
30
|
+
Diplomat::Kv.put(cache_file_name, @compress ? Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION) : data)
|
31
31
|
end
|
32
32
|
|
33
33
|
def get_filters
|
@@ -58,7 +58,7 @@ module ConsulWatcher
|
|
58
58
|
parent_dir: 'watch/json-store',
|
59
59
|
consul_http_addr: 'http://localhost:8500',
|
60
60
|
consul_token: nil,
|
61
|
-
|
61
|
+
compress: false
|
62
62
|
}
|
63
63
|
end
|
64
64
|
end
|
@@ -1,32 +1,57 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'fileutils'
|
4
|
+
require 'zlib'
|
5
|
+
require 'flazm_ruby_helpers/class'
|
6
|
+
|
3
7
|
module ConsulWatcher
|
4
8
|
module Storage
|
5
9
|
# Disk storage for previous watch data
|
6
10
|
class Disk
|
11
|
+
include FlazmRubyHelpers::Class
|
12
|
+
|
7
13
|
def initialize(storage_config)
|
8
|
-
|
14
|
+
initialize_variables(storage_config)
|
15
|
+
FileUtils.mkdir_p(@cache_dir) unless File.directory?(@cache_dir)
|
9
16
|
end
|
10
17
|
|
11
|
-
def fetch
|
12
|
-
file = File.open(cache_file_name
|
18
|
+
def fetch
|
19
|
+
file = File.open(cache_file_name, mode: 'r')
|
13
20
|
data = file.read
|
14
21
|
file.close
|
22
|
+
data = Zlib::Inflate.inflate(data) if @compress
|
15
23
|
data
|
16
24
|
rescue Errno::ENOENT
|
17
25
|
'{}'
|
18
26
|
end
|
19
27
|
|
20
|
-
def push(
|
21
|
-
file = File.open(cache_file_name
|
22
|
-
file.write(data)
|
28
|
+
def push(data)
|
29
|
+
file = File.open(cache_file_name, mode: 'w')
|
30
|
+
file.write(@compress ? Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION) : data)
|
23
31
|
file.close
|
24
32
|
end
|
25
33
|
|
34
|
+
def get_filters
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
26
38
|
private
|
27
39
|
|
28
|
-
def cache_file_name
|
29
|
-
"#{@
|
40
|
+
def cache_file_name
|
41
|
+
"#{@cache_dir}/#{@storage_name}.json"
|
42
|
+
end
|
43
|
+
|
44
|
+
def defaults
|
45
|
+
logger = Logger.new(STDOUT)
|
46
|
+
logger.level = Logger::WARN
|
47
|
+
{
|
48
|
+
logger: logger,
|
49
|
+
storage_name: 'disk',
|
50
|
+
cache_dir: 'watch/json-store',
|
51
|
+
consul_http_addr: 'http://localhost:8500',
|
52
|
+
consul_token: nil,
|
53
|
+
compress: false
|
54
|
+
}
|
30
55
|
end
|
31
56
|
end
|
32
57
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'base64'
|
4
|
-
require '
|
4
|
+
require 'flazm_ruby_helpers/class'
|
5
5
|
|
6
6
|
module ConsulWatcher
|
7
7
|
module WatchType
|
8
8
|
class Key
|
9
|
-
include
|
9
|
+
include FlazmRubyHelpers::Class
|
10
10
|
|
11
11
|
attr_accessor :filters
|
12
12
|
def initialize(watch_config)
|
13
|
-
|
13
|
+
initialize_variables(watch_config)
|
14
14
|
end
|
15
15
|
|
16
16
|
def get_changes(previous_watch_json, current_watch_json)
|
@@ -22,7 +22,6 @@ module ConsulWatcher
|
|
22
22
|
formatted_change
|
23
23
|
end.compact
|
24
24
|
changes = changes.each.collect.reject {|change| @filters.filter?(change)}
|
25
|
-
puts "size: #{changes.size}"
|
26
25
|
changes
|
27
26
|
end
|
28
27
|
|
@@ -38,7 +37,7 @@ module ConsulWatcher
|
|
38
37
|
end
|
39
38
|
|
40
39
|
def decode(change)
|
41
|
-
return unless change['
|
40
|
+
return unless change['key_property'] == 'Value'
|
42
41
|
|
43
42
|
change['old_value'] = Base64.decode64(change['old_value']) if change['old_value'].is_a? String
|
44
43
|
change['new_value'] = Base64.decode64(change['new_value']) if change['new_value'].is_a? String
|
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.6
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,7 +143,6 @@ files:
|
|
143
143
|
- docs/watch_type/watch_type.md
|
144
144
|
- exe/consul_watcher
|
145
145
|
- lib/consul_watcher.rb
|
146
|
-
- lib/consul_watcher/class_helper.rb
|
147
146
|
- lib/consul_watcher/destination/amqp.rb
|
148
147
|
- lib/consul_watcher/destination/jq.rb
|
149
148
|
- lib/consul_watcher/diff.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ConsulWatcher
|
4
|
-
# Define methods to handle default initialization behavior
|
5
|
-
module ClassHelper
|
6
|
-
def populate_variables(config = {})
|
7
|
-
defaults.each_pair do |key, default_value|
|
8
|
-
key = key.to_s
|
9
|
-
if config[key]
|
10
|
-
instance_variable_set("@#{key}", config[key])
|
11
|
-
elsif ENV[key.upcase.to_s]
|
12
|
-
instance_variable_set("@#{key}", ENV[key.upcase.to_s])
|
13
|
-
else
|
14
|
-
instance_variable_set("@#{key}", default_value)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|