consul_api 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/consul_api/common.rb +5 -6
- data/lib/consul_api/version.rb +1 -1
- data/spec/agent_spec.rb +2 -2
- data/spec/catalog_spec.rb +33 -0
- data/spec/vcr/consul_api/agent_service_register/registers_a_service_on_consul.yml +2 -2
- data/spec/vcr/consul_api/agent_services/gets_services_running_on_an_agent.yml +2 -2
- data/spec/vcr/consul_api/catalog_datacenters/returns_an_array_of_the_data.yml +34 -0
- data/spec/vcr/consul_api/catalog_node/returns_an_array_of_the_data.yml +40 -0
- data/spec/vcr/consul_api/catalog_nodes/returns_an_array_of_the_data.yml +40 -0
- data/spec/vcr/consul_api/catalog_service/returns_an_array_of_the_data.yml +40 -0
- data/spec/vcr/consul_api/catalog_services/returns_an_array_of_the_data.yml +40 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f22e8fdb3be7edafca3fbc65932cf460ba5a8e25
|
4
|
+
data.tar.gz: 5b867560da1f1446001bf4762a868980b895b799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef4049f4576df68f9d6986a89fbc5a30de19c9e942e4cba6514be04e05e363225a14618314bf937dfe3b17b6d3b3c2ce0a19f7a23df615a98de4334041188741
|
7
|
+
data.tar.gz: 0b671d652a0060ecda80fbcceaaeda43984b1f2456c30512bab147c2aacc127236bd6817bc1e0c3412b7292a89124b2d2f9487bede6feb8bb29fea3dcabf01d1
|
data/lib/consul_api/common.rb
CHANGED
@@ -11,18 +11,17 @@ module ConsulApi
|
|
11
11
|
# gets and puts will fail with an http status code in the 4xx and 5xx range
|
12
12
|
fail "http status #{response.status} returned from consul" if response.status >= 400
|
13
13
|
|
14
|
-
#
|
15
|
-
|
16
|
-
|
14
|
+
# return a nil of the response is 'null'
|
15
|
+
return nil if response.body == nil || response.body == 'null'
|
17
16
|
begin
|
17
|
+
# if the response is empty, return an empty hash
|
18
|
+
body = response.body == '' ? '{}' : response.body
|
18
19
|
parsed_response = JSON.parse(body)
|
19
20
|
rescue => e
|
20
21
|
fail "unable to parse the json returned by Consul. Returned data: #{response.body}"
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
-
# assume array otherwise, and return a collection of Mashes
|
25
|
-
parsed_response.map { |node| Hashie::Mash.new(node) }
|
24
|
+
parsed_response
|
26
25
|
end
|
27
26
|
|
28
27
|
def consul_ip
|
data/lib/consul_api/version.rb
CHANGED
data/spec/agent_spec.rb
CHANGED
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe ConsulApi::Agent, :vcr do
|
4
4
|
describe '#services' do
|
5
5
|
it 'gets services running on an agent' do
|
6
|
-
expect(ConsulApi::Agent.services).to be_a(
|
6
|
+
expect(ConsulApi::Agent.services).to be_a(Hash)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '#service_register' do
|
11
11
|
it 'registers a service on consul' do
|
12
|
-
expect(ConsulApi::Agent.service_register({'ID' => '123', 'Name' => 'abc'})).to be_a(
|
12
|
+
expect(ConsulApi::Agent.service_register({'ID' => '123', 'Name' => 'abc'})).to be_a(Hash)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ConsulApi::Catalog, :vcr do
|
4
|
+
describe '#datacenters' do
|
5
|
+
it 'returns an array of the data' do
|
6
|
+
expect(ConsulApi::Catalog.datacenters).to be_a(Array)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#nodes' do
|
11
|
+
it 'returns an array of the data' do
|
12
|
+
expect(ConsulApi::Catalog.nodes).to be_a(Array)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#services' do
|
17
|
+
it 'returns an array of the data' do
|
18
|
+
expect(ConsulApi::Catalog.services).to be_a(Hash)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#node' do
|
23
|
+
it 'returns an array of the data' do
|
24
|
+
expect(ConsulApi::Catalog.node('488221c29862')).to be_a(Hash)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#service' do
|
29
|
+
it 'returns an array of the data' do
|
30
|
+
expect(ConsulApi::Catalog.service('abc')).to be_a(Array)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -21,7 +21,7 @@ http_interactions:
|
|
21
21
|
message: OK
|
22
22
|
headers:
|
23
23
|
Date:
|
24
|
-
- Wed, 17 Sep 2014
|
24
|
+
- Wed, 17 Sep 2014 23:48:17 GMT
|
25
25
|
Content-Length:
|
26
26
|
- '0'
|
27
27
|
Content-Type:
|
@@ -30,5 +30,5 @@ http_interactions:
|
|
30
30
|
encoding: UTF-8
|
31
31
|
string: ''
|
32
32
|
http_version:
|
33
|
-
recorded_at: Wed, 17 Sep 2014
|
33
|
+
recorded_at: Wed, 17 Sep 2014 23:48:17 GMT
|
34
34
|
recorded_with: VCR 2.9.2
|
@@ -23,12 +23,12 @@ http_interactions:
|
|
23
23
|
Content-Type:
|
24
24
|
- application/json
|
25
25
|
Date:
|
26
|
-
- Wed, 17 Sep 2014
|
26
|
+
- Wed, 17 Sep 2014 23:48:17 GMT
|
27
27
|
Content-Length:
|
28
28
|
- '162'
|
29
29
|
body:
|
30
30
|
encoding: UTF-8
|
31
31
|
string: '{"123":{"ID":"123","Service":"abc","Tags":null,"Port":0},"jockey_consul_update":{"ID":"jockey_consul_update","Service":"docker_consul_update","Tags":[],"Port":0}}'
|
32
32
|
http_version:
|
33
|
-
recorded_at: Wed, 17 Sep 2014
|
33
|
+
recorded_at: Wed, 17 Sep 2014 23:48:17 GMT
|
34
34
|
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://127.0.0.1:8500/v1/catalog/datacenters
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: 'null'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Date:
|
26
|
+
- Wed, 17 Sep 2014 23:48:17 GMT
|
27
|
+
Content-Length:
|
28
|
+
- '7'
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: '["dc1"]'
|
32
|
+
http_version:
|
33
|
+
recorded_at: Wed, 17 Sep 2014 23:48:17 GMT
|
34
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://127.0.0.1:8500/v1/catalog/node/488221c29862
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: 'null'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
X-Consul-Index:
|
26
|
+
- '290'
|
27
|
+
X-Consul-Knownleader:
|
28
|
+
- 'true'
|
29
|
+
X-Consul-Lastcontact:
|
30
|
+
- '0'
|
31
|
+
Date:
|
32
|
+
- Wed, 17 Sep 2014 23:48:17 GMT
|
33
|
+
Content-Length:
|
34
|
+
- '294'
|
35
|
+
body:
|
36
|
+
encoding: UTF-8
|
37
|
+
string: '{"Node":{"Node":"488221c29862","Address":"172.17.42.1"},"Services":{"123":{"ID":"123","Service":"abc","Tags":[],"Port":0},"consul":{"ID":"consul","Service":"consul","Tags":[],"Port":8300},"jockey_consul_update":{"ID":"jockey_consul_update","Service":"docker_consul_update","Tags":[],"Port":0}}}'
|
38
|
+
http_version:
|
39
|
+
recorded_at: Wed, 17 Sep 2014 23:48:17 GMT
|
40
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://127.0.0.1:8500/v1/catalog/nodes
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: 'null'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
X-Consul-Index:
|
26
|
+
- '290'
|
27
|
+
X-Consul-Knownleader:
|
28
|
+
- 'true'
|
29
|
+
X-Consul-Lastcontact:
|
30
|
+
- '0'
|
31
|
+
Date:
|
32
|
+
- Wed, 17 Sep 2014 23:48:17 GMT
|
33
|
+
Content-Length:
|
34
|
+
- '49'
|
35
|
+
body:
|
36
|
+
encoding: UTF-8
|
37
|
+
string: '[{"Node":"488221c29862","Address":"172.17.42.1"}]'
|
38
|
+
http_version:
|
39
|
+
recorded_at: Wed, 17 Sep 2014 23:48:17 GMT
|
40
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://127.0.0.1:8500/v1/catalog/service/abc
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: 'null'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
X-Consul-Index:
|
26
|
+
- '290'
|
27
|
+
X-Consul-Knownleader:
|
28
|
+
- 'true'
|
29
|
+
X-Consul-Lastcontact:
|
30
|
+
- '0'
|
31
|
+
Date:
|
32
|
+
- Wed, 17 Sep 2014 23:48:17 GMT
|
33
|
+
Content-Length:
|
34
|
+
- '120'
|
35
|
+
body:
|
36
|
+
encoding: UTF-8
|
37
|
+
string: '[{"Node":"488221c29862","Address":"172.17.42.1","ServiceID":"123","ServiceName":"abc","ServiceTags":[],"ServicePort":0}]'
|
38
|
+
http_version:
|
39
|
+
recorded_at: Wed, 17 Sep 2014 23:48:17 GMT
|
40
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://127.0.0.1:8500/v1/catalog/services
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: 'null'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
X-Consul-Index:
|
26
|
+
- '290'
|
27
|
+
X-Consul-Knownleader:
|
28
|
+
- 'true'
|
29
|
+
X-Consul-Lastcontact:
|
30
|
+
- '0'
|
31
|
+
Date:
|
32
|
+
- Wed, 17 Sep 2014 23:48:17 GMT
|
33
|
+
Content-Length:
|
34
|
+
- '48'
|
35
|
+
body:
|
36
|
+
encoding: UTF-8
|
37
|
+
string: '{"abc":[],"consul":[],"docker_consul_update":[]}'
|
38
|
+
http_version:
|
39
|
+
recorded_at: Wed, 17 Sep 2014 23:48:17 GMT
|
40
|
+
recorded_with: VCR 2.9.2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay OConnor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -156,10 +156,16 @@ files:
|
|
156
156
|
- lib/consul_api/dns.rb
|
157
157
|
- lib/consul_api/version.rb
|
158
158
|
- spec/agent_spec.rb
|
159
|
+
- spec/catalog_spec.rb
|
159
160
|
- spec/spec_helper.rb
|
160
161
|
- spec/support/vcr.rb
|
161
162
|
- spec/vcr/consul_api/agent_service_register/registers_a_service_on_consul.yml
|
162
163
|
- spec/vcr/consul_api/agent_services/gets_services_running_on_an_agent.yml
|
164
|
+
- spec/vcr/consul_api/catalog_datacenters/returns_an_array_of_the_data.yml
|
165
|
+
- spec/vcr/consul_api/catalog_node/returns_an_array_of_the_data.yml
|
166
|
+
- spec/vcr/consul_api/catalog_nodes/returns_an_array_of_the_data.yml
|
167
|
+
- spec/vcr/consul_api/catalog_service/returns_an_array_of_the_data.yml
|
168
|
+
- spec/vcr/consul_api/catalog_services/returns_an_array_of_the_data.yml
|
163
169
|
homepage: ''
|
164
170
|
licenses:
|
165
171
|
- MIT
|
@@ -186,7 +192,13 @@ specification_version: 4
|
|
186
192
|
summary: Ruby wrapper for Consul V1 API
|
187
193
|
test_files:
|
188
194
|
- spec/agent_spec.rb
|
195
|
+
- spec/catalog_spec.rb
|
189
196
|
- spec/spec_helper.rb
|
190
197
|
- spec/support/vcr.rb
|
191
198
|
- spec/vcr/consul_api/agent_service_register/registers_a_service_on_consul.yml
|
192
199
|
- spec/vcr/consul_api/agent_services/gets_services_running_on_an_agent.yml
|
200
|
+
- spec/vcr/consul_api/catalog_datacenters/returns_an_array_of_the_data.yml
|
201
|
+
- spec/vcr/consul_api/catalog_node/returns_an_array_of_the_data.yml
|
202
|
+
- spec/vcr/consul_api/catalog_nodes/returns_an_array_of_the_data.yml
|
203
|
+
- spec/vcr/consul_api/catalog_service/returns_an_array_of_the_data.yml
|
204
|
+
- spec/vcr/consul_api/catalog_services/returns_an_array_of_the_data.yml
|