lita-consul 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +20 -0
- data/README.md +5 -1
- data/lib/lita/handlers/consul.rb +20 -19
- data/lita-consul.gemspec +1 -1
- data/spec/lita/handlers/consul_spec.rb +21 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9232658952f1f4983470a1482317b32aec9fe6cd
|
4
|
+
data.tar.gz: 37ec31b1e22031b9ec645d644185aa7517f47d7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2184ec1fe24738df0955e50b470b5cdb993edd2e7e829684505243a28e12948018fda06398e55e538f55675334c1c5fdcf3d884db5d5f37431306ce7f983bb7
|
7
|
+
data.tar.gz: ebbbb868792a0505b9a4d535d0b9b8c0d4d6a5e3d3e759f344de0447139255cbcba07fb1a4d0663f4fcbddf2e6e8973df4eb9ccfac8a49c2595da0260e6f9c42
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 David Pires
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/dpires/lita-consul.png?branch=master)](https://travis-ci.org/dpires/lita-consul)
|
4
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
|
+
[![Gem Version](https://badge.fury.io/rb/lita-consul.svg)](https://badge.fury.io/rb/lita-consul)
|
5
6
|
|
6
7
|
**lita-consul** is a handler for [Lita](https://github.com/litaio/lita) for interacting with [Consul](https://github.com/hashicorp/consul).
|
7
8
|
|
@@ -28,8 +29,11 @@ gem "lita-consul"
|
|
28
29
|
[Lita]: foo = bar
|
29
30
|
[You]: lita consul set mykey myvalue
|
30
31
|
[Lita]: mykey = myvalue
|
32
|
+
[You]: lita consul members
|
33
|
+
[Lita]: node1.node.consul - 192.168.0.33
|
34
|
+
node2.node.consul - 192.168.0.34
|
31
35
|
```
|
32
36
|
|
33
37
|
## License
|
34
38
|
|
35
|
-
[MIT](
|
39
|
+
[MIT](LICENSE)
|
data/lib/lita/handlers/consul.rb
CHANGED
@@ -20,19 +20,26 @@ module Lita
|
|
20
20
|
}
|
21
21
|
|
22
22
|
def consul_members(response)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
begin
|
24
|
+
resp = http.get("#{api_url}/catalog/nodes")
|
25
|
+
replies = []
|
26
|
+
MultiJson.load(resp.body).each do | node |
|
27
|
+
replies << "#{node['Node']} - #{node['Address']}"
|
28
|
+
end
|
29
|
+
response.reply replies.join("\n")
|
30
|
+
rescue Faraday::ConnectionFailed => e
|
31
|
+
response.reply e.message
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def consul_get(response)
|
32
36
|
key = response.matches.first.first
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
begin
|
38
|
+
value = get_key_value(key)
|
39
|
+
response.reply "#{key} = #{value}"
|
40
|
+
rescue Faraday::ConnectionFailed => e
|
41
|
+
response.reply e.message
|
42
|
+
end
|
36
43
|
end
|
37
44
|
|
38
45
|
def consul_set(response)
|
@@ -40,19 +47,16 @@ module Lita
|
|
40
47
|
value = response.matches.first.last
|
41
48
|
begin
|
42
49
|
resp = http.put("#{api_url}/kv/#{key}", value)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
response.reply resp.body
|
48
|
-
end
|
50
|
+
value = get_key_value(key)
|
51
|
+
response.reply "#{key} = #{value}"
|
52
|
+
rescue Faraday::ConnectionFailed => e
|
53
|
+
response.reply e.message
|
49
54
|
end
|
50
55
|
end
|
51
56
|
|
52
57
|
private
|
53
58
|
|
54
59
|
def get_key_value(key)
|
55
|
-
begin
|
56
60
|
resp = http.get("#{api_url}/kv/#{key}")
|
57
61
|
obj = MultiJson.load(resp.body)
|
58
62
|
unless obj[0]["Value"].nil?
|
@@ -61,9 +65,6 @@ module Lita
|
|
61
65
|
else
|
62
66
|
"null"
|
63
67
|
end
|
64
|
-
rescue Faraday::ConnectionFailed=> e
|
65
|
-
e.to_s
|
66
|
-
end
|
67
68
|
end
|
68
69
|
|
69
70
|
def api_url
|
data/lita-consul.gemspec
CHANGED
@@ -68,6 +68,12 @@ describe Lita::Handlers::Consul, lita_handler: true do
|
|
68
68
|
}
|
69
69
|
|
70
70
|
describe '#consul members' do
|
71
|
+
it 'should catch connection error' do
|
72
|
+
allow_any_instance_of(Faraday::Connection).to receive(:get).and_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
|
73
|
+
send_command('consul members')
|
74
|
+
expect(replies.last).to eq('Connection refused - connect(2)');
|
75
|
+
end
|
76
|
+
|
71
77
|
it 'should list member nodes' do
|
72
78
|
allow(response).to receive(:body).and_return(members_response)
|
73
79
|
send_command('consul members')
|
@@ -76,13 +82,19 @@ describe Lita::Handlers::Consul, lita_handler: true do
|
|
76
82
|
end
|
77
83
|
|
78
84
|
describe '#consul get' do
|
79
|
-
it '
|
85
|
+
it 'should catch error when exception occurs' do
|
86
|
+
allow_any_instance_of(Lita::Handlers::Consul).to receive(:get_key_value).and_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
|
87
|
+
send_command('consul get mykey')
|
88
|
+
expect(replies.last).to eq('Connection refused - connect(2)');
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should return value for key' do
|
80
92
|
allow(response).to receive(:body).and_return(single_key_response)
|
81
93
|
send_command('consul get mykey')
|
82
94
|
expect(replies.last).to eq("mykey = testing")
|
83
95
|
end
|
84
96
|
|
85
|
-
it 'return null value for key' do
|
97
|
+
it 'should return null value for key' do
|
86
98
|
allow(response).to receive(:body).and_return(null_value_response)
|
87
99
|
send_command('consul get mykey')
|
88
100
|
expect(replies.last).to eq("mykey = null")
|
@@ -90,7 +102,13 @@ describe Lita::Handlers::Consul, lita_handler: true do
|
|
90
102
|
end
|
91
103
|
|
92
104
|
describe '#consul set' do
|
93
|
-
it '
|
105
|
+
it 'should catch error when exception occurs' do
|
106
|
+
allow_any_instance_of(Lita::Handlers::Consul).to receive(:get_key_value).and_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
|
107
|
+
send_command('consul set mykey value')
|
108
|
+
expect(replies.last).to eq('Connection refused - connect(2)');
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should set and return value for key' do
|
94
112
|
allow(response).to receive(:body).and_return(new_key_response)
|
95
113
|
allow(response).to receive(:status).and_return(200)
|
96
114
|
send_command('consul set myapp/config/url www.test.com')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-consul
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Pires
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- ".gitignore"
|
133
133
|
- ".travis.yml"
|
134
134
|
- Gemfile
|
135
|
+
- LICENSE
|
135
136
|
- README.md
|
136
137
|
- Rakefile
|
137
138
|
- lib/lita-consul.rb
|