diplomat 0.2.3 → 0.3.0

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: 9bae583f9421ac7bbb79234002855e0d8c88c322
4
- data.tar.gz: 2dbabe8e600b42ab651a81f34d72430e27c8818f
3
+ metadata.gz: 29561e5c607d45e0a6339e2cead4c2721dc5d90e
4
+ data.tar.gz: b82255ac4419a411300b22b0e76cc37546065da9
5
5
  SHA512:
6
- metadata.gz: 161b7548c9caf5354480dafad55110a15a7fa07afb4d3d58b41681eb12b1e22780a67259d3eee17c9308cae5466b8f9a69eca6cc1bbfb989f07d1977acb8ba66
7
- data.tar.gz: b08de784d1e1b3a81a3f5f89d4554ffb38ca45642fc4e2ed39242730492daec6c729176b6047a1213d4b3b86d2317cc624b05916f55b532f1390460ff61370db
6
+ metadata.gz: e9e71c7eb3886233575aa00184f13179c190fa86d6ae34b1896e453ab354783132bdbbb6940f32aa3c388e53f123ada0aa258e2a5b97e7f76220ad4be413d7ba
7
+ data.tar.gz: b12d5ee9ac1ded146904fea9594e7736dc4ba3233dd521c9067c20cd15d4aebf8436814c156ef616aac4f7b014bca1aef048d884f12230ac567c611a9c90eb18
@@ -1,11 +1,12 @@
1
1
  module Diplomat
2
2
  class Configuration
3
3
  attr_accessor :middleware
4
- attr_accessor :url
4
+ attr_accessor :url, :acl_token
5
5
 
6
- def initialize
6
+ def initialize(url="http://localhost:8500", acl_token=nil)
7
7
  @middleware = []
8
- @url = "http://localhost:8500"
8
+ @url = url
9
+ @acl_token = acl_token
9
10
  end
10
11
 
11
12
  def middleware=(middleware)
data/lib/diplomat/kv.rb CHANGED
@@ -11,7 +11,9 @@ module Diplomat
11
11
  # @return [String] The base64-decoded value associated with the key
12
12
  def get key
13
13
  @key = key
14
- @raw = @conn.get "/v1/kv/#{@key}"
14
+ args = ["/v1/kv/#{@key}"]
15
+ args += check_acl_token unless check_acl_token.nil?
16
+ @raw = @conn.get args.join
15
17
  parse_body
16
18
  return_value
17
19
  end
@@ -24,18 +26,20 @@ module Diplomat
24
26
  # @return [String] The base64-decoded value associated with the key
25
27
  def put key, value, options=nil
26
28
  qs = ""
27
-
28
- if options and options[:cas]
29
- qs = "?cas=#{options[:cas]}"
29
+ @options = options
30
+ @raw = @conn.put do |req|
31
+ args = ["/v1/kv/#{key}"]
32
+ args += check_acl_token unless check_acl_token.nil?
33
+ args += use_cas(@options) unless use_cas(@options).nil?
34
+ req.url args.join
35
+ req.body = value
30
36
  end
31
-
32
- @raw = @conn.put("/v1/kv/#{key}#{qs}", value)
33
-
34
37
  if @raw.body == "true\n"
35
38
  @key = key
36
39
  @value = value
40
+ else
41
+ @raw.body
37
42
  end
38
- return @value
39
43
  end
40
44
 
41
45
  # Delete a value by it's key
@@ -43,9 +47,11 @@ module Diplomat
43
47
  # @return [nil]
44
48
  def delete key
45
49
  @key = key
46
- @raw = @conn.delete "/v1/kv/#{@key}"
47
- return_key
48
- return_value
50
+ args = ["/v1/kv/#{@key}"]
51
+ args += check_acl_token unless check_acl_token.nil?
52
+ @raw = @conn.delete args.join
53
+ # return_key
54
+ # return_value
49
55
  end
50
56
 
51
57
  # @note This is sugar, see (#get)
@@ -81,5 +87,12 @@ module Diplomat
81
87
  @value = Base64.decode64(@value) unless @value.nil?
82
88
  end
83
89
 
90
+ def check_acl_token
91
+ ["?token=#{Diplomat.configuration.acl_token}"] if Diplomat.configuration.acl_token
92
+ end
93
+
94
+ def use_cas(options)
95
+ ["&cas=#{options[:cas]}"] if options && options[:cas]
96
+ end
84
97
  end
85
98
  end
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink