lita-consul 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/.travis.yml +2 -0
- data/README.md +2 -2
- data/lib/lita/handlers/consul.rb +13 -15
- data/lita-consul.gemspec +1 -1
- data/spec/lita/handlers/consul_spec.rb +21 -0
- 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: 844421003794d177006fb04861b3bac4d30db932
|
4
|
+
data.tar.gz: d93e3f1d03baf6ad5c1b05eae68ec71707ab4193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a42a1bf02b78009ecdc219c1cc75a34d6f5110b6acf30e035893aca154279f12f08bbe23568e4c203f2bcf05bbbdce19fa6982854d90f58f335375471d17a38e
|
7
|
+
data.tar.gz: 8d9c85237ff3efa1ac2c3238bd9f70692043496a713ec980932792cd69a8d36f3a93234fb361e245c3d30a34af6a5d568f41892da7a5c49151a810e733647b97
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# lita-consul
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/dpires/lita-consul.png?branch=master)](https://travis-ci.org/dpires/lita-consul)
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/dpires/lita-consul/badge.
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/dpires/lita-consul/badge.svg?branch=master&service=github)](https://coveralls.io/github/dpires/lita-consul?branch=master)
|
5
5
|
|
6
|
-
|
6
|
+
**lita-consul** is a handler for [Lita](https://github.com/litaio/lita) for interacting with [Consul](https://github.com/hashicorp/consul).
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
data/lib/lita/handlers/consul.rb
CHANGED
@@ -14,6 +14,19 @@ module Lita
|
|
14
14
|
route /^consul set ([a-zA-Z0-9\-\/_]+) ([a-zA-Z0-9\-\/_]+)/, :consul_set, command: true, help: {
|
15
15
|
"consul set <key> <value>" => "Set <value> for <key>"
|
16
16
|
}
|
17
|
+
|
18
|
+
route /^consul members/, :consul_members, command: true, help: {
|
19
|
+
"consul members" => "Return consul nodes"
|
20
|
+
}
|
21
|
+
|
22
|
+
def consul_members(response)
|
23
|
+
resp = http.get("#{api_url}/catalog/nodes/")
|
24
|
+
replies = []
|
25
|
+
MultiJson.load(resp.body).each do | node |
|
26
|
+
replies << "#{node['Node']} - #{node['Address']}"
|
27
|
+
end
|
28
|
+
response.reply replies.join("\n")
|
29
|
+
end
|
17
30
|
|
18
31
|
def consul_get(response)
|
19
32
|
key = response.matches.first.first
|
@@ -21,21 +34,6 @@ module Lita
|
|
21
34
|
value = get_key_value(key)
|
22
35
|
response.reply "#{key} = #{value}"
|
23
36
|
end
|
24
|
-
=begin
|
25
|
-
begin
|
26
|
-
resp = http.get("#{api_url}/kv/#{key}")
|
27
|
-
obj = MultiJson.load(resp.body)
|
28
|
-
unless obj[0]["Value"].nil?
|
29
|
-
value = Base64.decode64(obj[0]["Value"])
|
30
|
-
response.reply "#{key} = #{value}"
|
31
|
-
else
|
32
|
-
response.reply "#{key} = null"
|
33
|
-
end
|
34
|
-
rescue Faraday::ConnectionFailed=> e
|
35
|
-
response.reply e.to_s
|
36
|
-
end
|
37
|
-
end
|
38
|
-
=end
|
39
37
|
|
40
38
|
def consul_set(response)
|
41
39
|
key = response.matches.first.first
|
data/lita-consul.gemspec
CHANGED
@@ -4,10 +4,12 @@ describe Lita::Handlers::Consul, lita_handler: true do
|
|
4
4
|
describe 'lita routes' do
|
5
5
|
it { is_expected.to route_command('consul get mykey').to(:consul_get) }
|
6
6
|
it { is_expected.to route_command('consul set mykey myvalue').to(:consul_set) }
|
7
|
+
it { is_expected.to route_command('consul members').to(:consul_members) }
|
7
8
|
end
|
8
9
|
|
9
10
|
before do
|
10
11
|
allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
|
12
|
+
allow_any_instance_of(Faraday::Connection).to receive(:put).and_return(response)
|
11
13
|
end
|
12
14
|
|
13
15
|
let(:response) { double("Faraday::Response") }
|
@@ -56,12 +58,30 @@ describe Lita::Handlers::Consul, lita_handler: true do
|
|
56
58
|
}
|
57
59
|
}
|
58
60
|
|
61
|
+
let(:members_response) {
|
62
|
+
%{
|
63
|
+
[
|
64
|
+
{"Node":"node1.node.consul","Address":"192.168.0.33"},
|
65
|
+
{"Node":"node2.node.consul","Address":"192.168.0.34"}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
describe '#consul members' do
|
71
|
+
it 'should list member nodes' do
|
72
|
+
allow(response).to receive(:body).and_return(members_response)
|
73
|
+
send_command('consul members')
|
74
|
+
expect(replies.last).to eq("node1.node.consul - 192.168.0.33\nnode2.node.consul - 192.168.0.34")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
59
78
|
describe '#consul get' do
|
60
79
|
it 'return value for key' do
|
61
80
|
allow(response).to receive(:body).and_return(single_key_response)
|
62
81
|
send_command('consul get mykey')
|
63
82
|
expect(replies.last).to eq("mykey = testing")
|
64
83
|
end
|
84
|
+
|
65
85
|
it 'return null value for key' do
|
66
86
|
allow(response).to receive(:body).and_return(null_value_response)
|
67
87
|
send_command('consul get mykey')
|
@@ -72,6 +92,7 @@ describe Lita::Handlers::Consul, lita_handler: true do
|
|
72
92
|
describe '#consul set' do
|
73
93
|
it 'set and return value for key' do
|
74
94
|
allow(response).to receive(:body).and_return(new_key_response)
|
95
|
+
allow(response).to receive(:status).and_return(200)
|
75
96
|
send_command('consul set myapp/config/url www.test.com')
|
76
97
|
expect(replies.last).to eq("myapp/config/url = www.test.com")
|
77
98
|
end
|