lita-consul 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 778ac4f430433ce8ce6973475bf75d6c51d0c5da
4
- data.tar.gz: 17c3c4867612b5042ee6733fa3c5f14680c6f09b
3
+ metadata.gz: 4d9d08f566174b54aff99adc47f1b5ed4005f3ae
4
+ data.tar.gz: 7c38b9852453a70228a1883847ef46f442733ba9
5
5
  SHA512:
6
- metadata.gz: a29567b595d8099c9bd0722391f671d763abdd98740476a461006f3121afd38b6251e1d9984df5fe0135bbf4eba24013383c7ebcfeb6d175d16fa96766b7699a
7
- data.tar.gz: d5d5e2d5081443ab691f40637a9b38d4ae3c98e8b10a9514b172c60f11ba7fc0ee0b9143232d4ea5d7b2320f8803c35e6b8672b28c226e507b6984c0473178fb
6
+ metadata.gz: 0742652f2f71c7b74fc220251efc2d28a1300799399f41fd7fef900c1f2b68ba71f9504e4ad6f443a3db7ac836b06567c2ea580f4d0576a001396087b9c072fb
7
+ data.tar.gz: 8cdfe7ec5ffb5bd7f851a2ff7e0de3771ef6716541407b62918ab8d69434b2c35678ecb29ff69f2111423635b9857ad373b02da91237996ac16aa1015c5ae63f
@@ -11,9 +11,17 @@ module Lita
11
11
  "consul get <key>" => "Return value for <key>"
12
12
  }
13
13
 
14
+ route /^consul set ([a-zA-Z0-9\-\/_]+) ([a-zA-Z0-9\-\/_]+)/, :consul_set, command: true, help: {
15
+ "consul set <key> <value>" => "Set <value> for <key>"
16
+ }
17
+
14
18
  def consul_get(response)
15
19
  key = response.matches.first.first
16
20
 
21
+ value = get_key_value(key)
22
+ response.reply "#{key} = #{value}"
23
+ end
24
+ =begin
17
25
  begin
18
26
  resp = http.get("#{api_url}/kv/#{key}")
19
27
  obj = MultiJson.load(resp.body)
@@ -27,8 +35,38 @@ module Lita
27
35
  response.reply e.to_s
28
36
  end
29
37
  end
38
+ =end
39
+
40
+ def consul_set(response)
41
+ key = response.matches.first.first
42
+ value = response.matches.first.last
43
+ begin
44
+ resp = http.put("#{api_url}/kv/#{key}", value)
45
+ if resp.status == 200
46
+ value = get_key_value(key)
47
+ response.reply "#{key} = #{value}"
48
+ else
49
+ response.reply resp.body
50
+ end
51
+ end
52
+ end
30
53
 
31
54
  private
55
+
56
+ def get_key_value(key)
57
+ begin
58
+ resp = http.get("#{api_url}/kv/#{key}")
59
+ obj = MultiJson.load(resp.body)
60
+ unless obj[0]["Value"].nil?
61
+ value = Base64.decode64(obj[0]["Value"])
62
+ "#{value}"
63
+ else
64
+ "null"
65
+ end
66
+ rescue Faraday::ConnectionFailed=> e
67
+ e.to_s
68
+ end
69
+ end
32
70
 
33
71
  def api_url
34
72
  host = "http://127.0.0.1"
data/lita-consul.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-consul"
3
- spec.version = "0.0.1"
3
+ spec.version = "0.0.2"
4
4
  spec.authors = ["David Pires"]
5
5
  spec.email = ["david.pires@gmail.com"]
6
6
  spec.description = "Lita handler for Consul"
@@ -3,6 +3,7 @@ require "spec_helper"
3
3
  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
+ it { is_expected.to route_command('consul set mykey myvalue').to(:consul_set) }
6
7
  end
7
8
 
8
9
  before do
@@ -40,6 +41,21 @@ describe Lita::Handlers::Consul, lita_handler: true do
40
41
  }
41
42
  }
42
43
 
44
+ let(:new_key_response) {
45
+ %{
46
+ [
47
+ {
48
+ "CreateIndex":67,
49
+ "ModifyIndex":67,
50
+ "LockIndex":0,
51
+ "Key":"myapp/config/url",
52
+ "Flags":0,
53
+ "Value":"d3d3LnRlc3QuY29t"
54
+ }
55
+ ]
56
+ }
57
+ }
58
+
43
59
  describe '#consul get' do
44
60
  it 'return value for key' do
45
61
  allow(response).to receive(:body).and_return(single_key_response)
@@ -52,4 +68,12 @@ describe Lita::Handlers::Consul, lita_handler: true do
52
68
  expect(replies.last).to eq("mykey = null")
53
69
  end
54
70
  end
71
+
72
+ describe '#consul set' do
73
+ it 'set and return value for key' do
74
+ allow(response).to receive(:body).and_return(new_key_response)
75
+ send_command('consul set myapp/config/url www.test.com')
76
+ expect(replies.last).to eq("myapp/config/url = www.test.com")
77
+ end
78
+ end
55
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-consul
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Pires