etcd-discovery 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/etcd-discovery/registrar.rb +6 -1
- data/lib/etcd-discovery/service.rb +13 -15
- data/spec/spec_helper.rb +8 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 17118bb040e02a6a81848eb96bc6eab9490a2ed3c3f1c9718073580add409ebd
|
4
|
+
data.tar.gz: 8524c1cd5eee0558e12abadaa8478e95c418c92878328aa890d2ab2aad6a2781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1eb7a2fda116458395f0502ffcc44fd1e65083321b4eff7dc10ca3413b11d5ec5d0bac13df8b213228bc37482f09980f21267a70b04d871c1639c35b71f3fca
|
7
|
+
data.tar.gz: cfd3a9cae7bf06ebe471e8269f8f82f925d0aa59bd07cebd935e8b48bdabc0f7effa961cecb206c1509415557882d0546aac4a089f775fa596dba6aee5ea6616
|
@@ -54,7 +54,12 @@ module EtcdDiscovery
|
|
54
54
|
@logger.warn "Watcher #{@service.attributes['name']} started"
|
55
55
|
index = 0
|
56
56
|
while @state == :started
|
57
|
-
|
57
|
+
begin
|
58
|
+
resp = client.watch service_key, { index: index }
|
59
|
+
rescue => e
|
60
|
+
@logger.warn "Fail to watch #{service_key}: #{e}, #{e.message}, #{e.class}"
|
61
|
+
next
|
62
|
+
end
|
58
63
|
value = JSON.parse resp.node.value
|
59
64
|
@user = value['user']
|
60
65
|
@password = value['password']
|
@@ -21,9 +21,9 @@ module EtcdDiscovery
|
|
21
21
|
client = EtcdDiscovery.config.client
|
22
22
|
begin
|
23
23
|
service = client.get("/services_infos/#{service}")
|
24
|
-
return
|
24
|
+
return new service.node
|
25
25
|
rescue Etcd::KeyNotFound
|
26
|
-
return
|
26
|
+
return new('name' => service)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -34,35 +34,33 @@ module EtcdDiscovery
|
|
34
34
|
rescue Etcd::KeyNotFound
|
35
35
|
raise ServiceNotFound, attributes['name']
|
36
36
|
end
|
37
|
-
if node.children.
|
38
|
-
|
39
|
-
end
|
40
|
-
hosts = []
|
41
|
-
node.children.each do |c|
|
42
|
-
hosts << Host.new(c)
|
43
|
-
end
|
44
|
-
return hosts
|
37
|
+
raise ServiceNotFound, attributes['name'] if node.children.empty?
|
38
|
+
return node.children.map { |c| Host.new(c) }
|
45
39
|
end
|
46
40
|
|
47
41
|
def one
|
48
42
|
all.sample
|
49
43
|
end
|
50
44
|
|
51
|
-
def to_uri(schemes = [
|
45
|
+
def to_uri(schemes = ['https', 'http'])
|
52
46
|
a = attributes
|
53
47
|
return one.to_uri(schemes) unless a['public']
|
54
48
|
|
55
49
|
schemes = [schemes] if !schemes.is_a?(Array)
|
56
|
-
scheme = schemes.
|
57
|
-
|
58
|
-
|
59
|
-
if a['user'].nil? || a['user'] ==
|
50
|
+
scheme = schemes.reject do |s|
|
51
|
+
a['ports'][s].nil?
|
52
|
+
end.first
|
53
|
+
if a['user'].nil? || a['user'] == ''
|
60
54
|
URI("#{scheme}://#{a['hostname']}:#{a['ports'][scheme]}")
|
61
55
|
else
|
62
56
|
URI("#{scheme}://#{a['user']}:#{a['password']}@#{a['hostname']}:#{a['ports'][scheme]}")
|
63
57
|
end
|
64
58
|
end
|
65
59
|
|
60
|
+
def to_s
|
61
|
+
to_uri.to_s
|
62
|
+
end
|
63
|
+
|
66
64
|
def to_json
|
67
65
|
attributes.to_json
|
68
66
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,3 +6,11 @@ Bundler.require(:default, :development, :test)
|
|
6
6
|
|
7
7
|
EtcdDiscovery.config.register_renew = 0.1
|
8
8
|
|
9
|
+
require 'webmock/rspec'
|
10
|
+
WebMock.disable_net_connect!(allow_localhost: false)
|
11
|
+
|
12
|
+
require_relative "./etcd_helper"
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.include(EtcdHelper)
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etcd-discovery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Léo Unbekandt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: etcd
|
@@ -58,8 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
|
-
|
62
|
-
rubygems_version: 2.6.13
|
61
|
+
rubygems_version: 3.0.3
|
63
62
|
signing_key:
|
64
63
|
specification_version: 4
|
65
64
|
summary: Service discovery based on etcd
|