consul_syncer 0.6.1 → 1.1.0
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/lib/consul_syncer.rb +8 -6
- data/lib/consul_syncer/version.rb +1 -1
- data/lib/consul_syncer/wrapper.rb +3 -2
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59b87094f77b404c59b018035020eab02be5075c3b3d9dc3e68f28a64d8f70c0
|
4
|
+
data.tar.gz: c61781655c3a8a67e266da1e97578b9e996d7c4b43248c777ef43e35608ba8ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f164174999daa718fe237edbff4a0b1ca3389ab56db5af2ce57cfd7876c20b0d5563de016b649677e0bd14b3d7e7c544c8857a27bb271eae1291fe6a43f02da
|
7
|
+
data.tar.gz: bfd88ffae1281a70b942fb6f766fbabcc20f4ec49aca1df311a5cf79e4f6c08dc4dbd13f77110b8f38be4260e3e7a4daba8431d5996279739f475d1d0a71de6f
|
data/lib/consul_syncer.rb
CHANGED
@@ -5,18 +5,19 @@ require 'consul_syncer/endpoint'
|
|
5
5
|
require 'consul_syncer/wrapper'
|
6
6
|
|
7
7
|
# syncs a given list of endpoints into consul
|
8
|
+
# - sorts tags
|
8
9
|
# - adds missing
|
9
10
|
# - updates changed
|
10
11
|
# - removes deprecated
|
11
12
|
class ConsulSyncer
|
12
13
|
def initialize(url, logger: Logger.new(STDOUT), params: {})
|
13
14
|
@logger = logger
|
14
|
-
@consul = Wrapper.new(
|
15
|
+
@consul = Wrapper.new(url, params: params, logger: @logger)
|
15
16
|
end
|
16
17
|
|
17
18
|
# changing tags means all previous services need to be removed manually since
|
18
19
|
# they can no longer be found
|
19
|
-
def sync(expected_definitions, tags)
|
20
|
+
def sync(expected_definitions, tags, dry: false)
|
20
21
|
raise ArgumentError, "Need at least 1 tag to reliably update endpoints" if tags.empty?
|
21
22
|
|
22
23
|
modified = 0
|
@@ -26,6 +27,7 @@ class ConsulSyncer
|
|
26
27
|
expected_definitions.each do |d|
|
27
28
|
d[:tags] += tags
|
28
29
|
d[:tags].sort!
|
30
|
+
d[:tags].uniq!
|
29
31
|
end
|
30
32
|
|
31
33
|
actual_definitions = consul_endpoints(tags).map do |consul_endpoint|
|
@@ -59,11 +61,11 @@ class ConsulSyncer
|
|
59
61
|
elsif remove_matching_service!(actual_definitions, expected, identifying)
|
60
62
|
@logger.info "Updating #{description}"
|
61
63
|
modified += 1
|
62
|
-
register expected
|
64
|
+
register **expected unless dry
|
63
65
|
else
|
64
66
|
@logger.info "Adding #{description}"
|
65
67
|
modified += 1
|
66
|
-
register expected
|
68
|
+
register **expected unless dry
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
@@ -71,7 +73,7 @@ class ConsulSyncer
|
|
71
73
|
actual_definitions.each do |actual|
|
72
74
|
@logger.info "Removing #{actual.fetch(:service)} / #{actual.fetch(:service_id)} on #{actual.fetch(:node)} in Consul"
|
73
75
|
modified += 1
|
74
|
-
deregister actual.fetch(:node), actual.fetch(:service_id)
|
76
|
+
deregister actual.fetch(:node), actual.fetch(:service_id) unless dry
|
75
77
|
end
|
76
78
|
|
77
79
|
modified
|
@@ -80,7 +82,7 @@ class ConsulSyncer
|
|
80
82
|
private
|
81
83
|
|
82
84
|
def consul_endpoints(requested_tags)
|
83
|
-
services = @consul.request(:get, "/v1/catalog/services?tag=#{requested_tags.first}")
|
85
|
+
services = @consul.request(:get, "/v1/catalog/services?cached&stale&tag=#{requested_tags.first}")
|
84
86
|
services.each_with_object([]) do |(name, tags), all|
|
85
87
|
# cannot query for multiple tags via query, so handle multi-matching manually
|
86
88
|
next if (requested_tags - tags).any?
|
@@ -11,8 +11,9 @@ class ConsulSyncer
|
|
11
11
|
class ConsulError < StandardError
|
12
12
|
end
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
|
14
|
+
def initialize(consul_url, params:, logger:)
|
15
|
+
consul_url = "http://#{consul_url}" unless consul_url.include?("://")
|
16
|
+
@consul = Faraday.new(consul_url)
|
16
17
|
@params = params
|
17
18
|
@logger = logger
|
18
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul_syncer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -47,15 +47,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 2.
|
50
|
+
version: 2.4.0
|
51
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
|
58
|
-
rubygems_version: 2.7.6
|
57
|
+
rubygems_version: 3.2.16
|
59
58
|
signing_key:
|
60
59
|
specification_version: 4
|
61
60
|
summary: Sync remote services into consul
|