etcd-discovery 0.0.3 → 0.0.4
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/etcd-discovery/host.rb +17 -21
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 163c6cc3af01710f2998906408bcc4b90e88820c
|
4
|
+
data.tar.gz: 149f5d852f18ccdeec8660049083e5b5fc532765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5af9928c529cdf705473a1dcf650e0286343456546a5cb55c6ad23f1c0210b349f5f2b0305550c8c491dfe383c8e76e00faea5dbf28fbda332d0ea489d21575
|
7
|
+
data.tar.gz: fbfcfce924f3ec3b739134128dfa987698209fbb52adce68cd32a7340d56981f10ce5e0195f6ab557892a5a43365e5f182ddf436ca1a9bc3e2200a7acf85db20
|
data/lib/etcd-discovery/host.rb
CHANGED
@@ -1,41 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
new_hash = {}
|
4
|
-
self.each do |k,v|
|
5
|
-
new_hash[k.to_s.capitalize] = v
|
6
|
-
end
|
7
|
-
return new_hash
|
1
|
+
module EtcdDiscovery
|
2
|
+
class InvalidHost < RuntimeError
|
8
3
|
end
|
9
|
-
end
|
10
4
|
|
11
|
-
module EtcdDiscovery
|
12
5
|
class Host
|
13
|
-
attr_accessor :
|
6
|
+
attr_accessor :attributes
|
14
7
|
|
15
8
|
def initialize(arg)
|
16
9
|
if arg.is_a? Etcd::Node
|
17
|
-
|
10
|
+
@attributes = JSON.parse arg.value
|
18
11
|
elsif arg.is_a? Hash
|
19
|
-
|
12
|
+
@attributes = arg
|
20
13
|
else
|
21
14
|
raise TypeError, "requires a Etcd::Node or a Hash, not a #{arg.class}"
|
22
15
|
end
|
23
|
-
|
24
|
-
|
25
|
-
@user = params['User']
|
26
|
-
@password = params['Password']
|
27
|
-
|
28
|
-
if @hostname.nil? or @hostname.empty?
|
29
|
-
@hostname = Socket.gethostname
|
16
|
+
if !attributes.has_key? 'name' or !attributes.has_key? 'port'
|
17
|
+
raise InvalidHost, "attributes 'name' and 'port' should be defined"
|
30
18
|
end
|
19
|
+
@user = params['user'] || ""
|
20
|
+
@password = params['password'] || ""
|
21
|
+
@scheme = params['scheme'] || "http"
|
31
22
|
end
|
32
23
|
|
33
24
|
def to_json
|
34
|
-
|
25
|
+
attributes.to_json
|
35
26
|
end
|
36
27
|
|
37
28
|
def to_uri
|
38
|
-
|
29
|
+
a = attributes # Shorten name
|
30
|
+
URI("#{a['scheme']}://#{a['user']}:#{a['password']}@#{a['name']}:#{a['port']}")
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
self.to_uri.to_s
|
39
35
|
end
|
40
36
|
end
|
41
37
|
end
|