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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34b83e20565f0858e1918b7ca93c1c6d41c9a2b2777a32937bb5169345175142
4
- data.tar.gz: bf0ff33dd92696b851ca21537dd53bf7b06b8076572418149f91e47d34f8921d
3
+ metadata.gz: bf3d5a6f2bfd0484e3290d7483ea078d8eafcd66e8a177149af746b63f40e812
4
+ data.tar.gz: 26c0ade8975a7a84f8c28662c5052795699dfa3d54680c060961f169f1b1adbf
5
5
  SHA512:
6
- metadata.gz: 35f338525c66aea26f700d3b6931ab05676acb24e711428858326b237cf73f1d8874fadb95f51a2eabb0b9a085bf21c1192cae1bbc7f8113e2cf03173e5572c0
7
- data.tar.gz: e41f084b247a579ca030419c1f01b1695829291cd63b6b1feedd0af3822f22f3974a2101ac46c68b062f1fd54340b8cd5e8a1a6425beaa0f285b6a55946aecf4
6
+ metadata.gz: c828440bd91ee16d46f7d887672daa024d741125ca36e58d224a94abaa512b7cf6bc7ef38c69c52d4dc1a9b26f31d65952c66e5dc6504a86100d1f6670b989a7
7
+ data.tar.gz: e7f25d5fcdc072aaa4476502003eaba6019580da7ed3fade69011a8f178e6bb3a43374a16184e359308bcde983ac1d2b650d90b396eee3a0e5a8956d9e416b0d
@@ -1,3 +1,3 @@
1
1
  class ConsulSyncer
2
- VERSION = "1.2.2"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -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.to_json if 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, dry: false)
21
- planned = plan(expected_definitions, tags)
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
- services = @consul.request(:get, "/v1/catalog/services?cached&stale")
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: 1.2.2
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: 2021-09-18 00:00:00.000000000 Z
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: 2.4.0
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: 3.2.16
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: []