consul_syncer 1.2.2 → 2.0.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/version.rb +1 -1
- data/lib/consul_syncer/wrapper.rb +4 -2
- data/lib/consul_syncer.rb +8 -7
- metadata +4 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf3d5a6f2bfd0484e3290d7483ea078d8eafcd66e8a177149af746b63f40e812
|
|
4
|
+
data.tar.gz: 26c0ade8975a7a84f8c28662c5052795699dfa3d54680c060961f169f1b1adbf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c828440bd91ee16d46f7d887672daa024d741125ca36e58d224a94abaa512b7cf6bc7ef38c69c52d4dc1a9b26f31d65952c66e5dc6504a86100d1f6670b989a7
|
|
7
|
+
data.tar.gz: e7f25d5fcdc072aaa4476502003eaba6019580da7ed3fade69011a8f178e6bb3a43374a16184e359308bcde983ac1d2b650d90b396eee3a0e5a8956d9e416b0d
|
|
@@ -13,7 +13,9 @@ class ConsulSyncer
|
|
|
13
13
|
|
|
14
14
|
def initialize(consul_url, params:, logger:)
|
|
15
15
|
consul_url = "http://#{consul_url}" unless consul_url.include?("://")
|
|
16
|
-
@consul = Faraday.new(consul_url)
|
|
16
|
+
@consul = Faraday.new(consul_url) do |f|
|
|
17
|
+
f.request :json
|
|
18
|
+
end
|
|
17
19
|
@params = params
|
|
18
20
|
@logger = logger
|
|
19
21
|
end
|
|
@@ -24,7 +26,7 @@ class ConsulSyncer
|
|
|
24
26
|
path += "#{separator}#{URI.encode_www_form(@params)}"
|
|
25
27
|
end
|
|
26
28
|
args = [path]
|
|
27
|
-
args << payload
|
|
29
|
+
args << payload if payload
|
|
28
30
|
|
|
29
31
|
retry_on_error do
|
|
30
32
|
response = @consul.send(method, *args)
|
data/lib/consul_syncer.rb
CHANGED
|
@@ -10,24 +10,23 @@ require 'consul_syncer/wrapper'
|
|
|
10
10
|
# - updates changed
|
|
11
11
|
# - removes deprecated
|
|
12
12
|
class ConsulSyncer
|
|
13
|
-
def initialize(url, logger: Logger.new(STDOUT), params: {})
|
|
13
|
+
def initialize(url, logger: Logger.new(STDOUT), params: {}, services_params: nil)
|
|
14
14
|
@logger = logger
|
|
15
15
|
@consul = Wrapper.new(url, params: params, logger: @logger)
|
|
16
|
+
@services_params = services_params
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
# changing tags means all previous services need to be removed manually since
|
|
19
20
|
# they can no longer be found
|
|
20
|
-
def sync(expected_definitions, tags
|
|
21
|
-
|
|
22
|
-
execute planned unless dry
|
|
23
|
-
planned.size # let users know what we did and keep legacy api working
|
|
21
|
+
def sync(expected_definitions, tags)
|
|
22
|
+
execute plan(expected_definitions, tags)
|
|
24
23
|
end
|
|
25
24
|
|
|
26
25
|
def plan(expected_definitions, tags)
|
|
27
26
|
raise ArgumentError, "Need at least 1 tag to reliably update endpoints" if tags.empty?
|
|
28
27
|
|
|
29
28
|
# ensure consistent tags to find the endpoints after adding
|
|
30
|
-
expected_definitions = expected_definitions.dup
|
|
29
|
+
expected_definitions = expected_definitions.map(&:dup)
|
|
31
30
|
expected_definitions.each do |d|
|
|
32
31
|
d[:tags] += tags
|
|
33
32
|
d[:tags].sort!
|
|
@@ -86,7 +85,9 @@ class ConsulSyncer
|
|
|
86
85
|
private
|
|
87
86
|
|
|
88
87
|
def consul_endpoints(requested_tags)
|
|
89
|
-
|
|
88
|
+
path = "/v1/catalog/services"
|
|
89
|
+
path += "?#{@services_params}" if @services_params
|
|
90
|
+
services = @consul.request(:get, path)
|
|
90
91
|
services.each_with_object([]) do |(name, tags), all|
|
|
91
92
|
# cannot query for multiple tags via query, so handle multi-matching manually
|
|
92
93
|
next if (requested_tags - tags).any?
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: consul_syncer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Grosser
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: faraday
|
|
@@ -24,7 +23,6 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
27
|
-
description:
|
|
28
26
|
email: michael@grosser.it
|
|
29
27
|
executables: []
|
|
30
28
|
extensions: []
|
|
@@ -39,7 +37,6 @@ homepage: https://github.com/grosser/consul_syncer
|
|
|
39
37
|
licenses:
|
|
40
38
|
- MIT
|
|
41
39
|
metadata: {}
|
|
42
|
-
post_install_message:
|
|
43
40
|
rdoc_options: []
|
|
44
41
|
require_paths:
|
|
45
42
|
- lib
|
|
@@ -47,15 +44,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
47
44
|
requirements:
|
|
48
45
|
- - ">="
|
|
49
46
|
- !ruby/object:Gem::Version
|
|
50
|
-
version:
|
|
47
|
+
version: 3.3.0
|
|
51
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
49
|
requirements:
|
|
53
50
|
- - ">="
|
|
54
51
|
- !ruby/object:Gem::Version
|
|
55
52
|
version: '0'
|
|
56
53
|
requirements: []
|
|
57
|
-
rubygems_version:
|
|
58
|
-
signing_key:
|
|
54
|
+
rubygems_version: 4.0.3
|
|
59
55
|
specification_version: 4
|
|
60
56
|
summary: Sync remote services into consul
|
|
61
57
|
test_files: []
|