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 +4 -4
- data/lib/diplomat/configuration.rb +4 -3
- data/lib/diplomat/kv.rb +24 -11
- data/lib/diplomat/version.rb +1 -1
- 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: 29561e5c607d45e0a6339e2cead4c2721dc5d90e
|
4
|
+
data.tar.gz: b82255ac4419a411300b22b0e76cc37546065da9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
data/lib/diplomat/version.rb
CHANGED