diplomat 2.0.1 → 2.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 +4 -4
- data/lib/diplomat/kv.rb +9 -1
- data/lib/diplomat/rest_client.rb +12 -6
- data/lib/diplomat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 821e0c50069009a97db9397d14f0c5c4eefba50c
|
4
|
+
data.tar.gz: 0204f17c74c81cc3676ef9332ed5bace9150e5ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdf627aad378afb53880105c43ad280d4eb81900f1c1ec82bed4d37abcaff34a9ea17cc7db8e022fb44ea4c4167019d32366687648d4233585645f83d8936788
|
7
|
+
data.tar.gz: 5df07529deabb282661cb8cae6ccd5939685c7a4ab86d60f93306942d562f5301fa41fbd93cbcde9ce8ca5f3630cf21c9596e75d77b492611ec198f3a4036342
|
data/lib/diplomat/kv.rb
CHANGED
@@ -14,6 +14,7 @@ module Diplomat
|
|
14
14
|
# @option options [String] :dc Target datacenter
|
15
15
|
# @option options [Boolean] :keys Only return key names.
|
16
16
|
# @option options [Boolean] :modify_index Only return ModifyIndex value.
|
17
|
+
# @option options [Boolean] :session Only return Session value.
|
17
18
|
# @option options [Boolean] :decode_values Return consul response with decoded values.
|
18
19
|
# @option options [String] :separator List only up to a given separator.
|
19
20
|
# Only applies when combined with :keys option.
|
@@ -76,8 +77,9 @@ module Diplomat
|
|
76
77
|
@raw = raw
|
77
78
|
@raw = parse_body
|
78
79
|
return @raw.first['ModifyIndex'] if @options && @options[:modify_index]
|
80
|
+
return @raw.first['Session'] if @options && @options[:session]
|
79
81
|
return decode_values if @options && @options[:decode_values]
|
80
|
-
return convert_to_hash(return_value(return_nil_values, transformation)) if @options && @options[:convert_to_hash]
|
82
|
+
return convert_to_hash(return_value(return_nil_values, transformation, true)) if @options && @options[:convert_to_hash]
|
81
83
|
return return_value(return_nil_values, transformation)
|
82
84
|
when :wait
|
83
85
|
index = raw.headers['x-consul-index']
|
@@ -103,6 +105,7 @@ module Diplomat
|
|
103
105
|
# @param options [Hash] the query params
|
104
106
|
# @option options [Integer] :cas The modify index
|
105
107
|
# @option options [String] :dc Target datacenter
|
108
|
+
# @option options [String] :acquire Session to attach to key
|
106
109
|
# @return [Bool] Success or failure of the write (can fail in c-a-s mode)
|
107
110
|
# rubocop:disable MethodLength, AbcSize
|
108
111
|
def put(key, value, options = nil)
|
@@ -112,6 +115,7 @@ module Diplomat
|
|
112
115
|
url += check_acl_token
|
113
116
|
url += use_cas(@options)
|
114
117
|
url += dc(@options)
|
118
|
+
url += acquire(@options)
|
115
119
|
req.url concat_url url
|
116
120
|
req.body = value
|
117
121
|
end
|
@@ -186,6 +190,10 @@ module Diplomat
|
|
186
190
|
options && options[:dc] ? use_named_parameter('dc', options[:dc]) : []
|
187
191
|
end
|
188
192
|
|
193
|
+
def acquire(options)
|
194
|
+
options && options[:acquire] ? use_named_parameter('acquire', options[:acquire]) : []
|
195
|
+
end
|
196
|
+
|
189
197
|
def keys(options)
|
190
198
|
options && options[:keys] ? ['keys'] : []
|
191
199
|
end
|
data/lib/diplomat/rest_client.rb
CHANGED
@@ -148,14 +148,20 @@ module Diplomat
|
|
148
148
|
end
|
149
149
|
|
150
150
|
# Get the key/value(s) from the raw output
|
151
|
-
|
151
|
+
# rubocop:disable PerceivedComplexity, MethodLength, CyclomaticComplexity, AbcSize
|
152
|
+
def return_value(nil_values = false, transformation = nil, return_hash = false)
|
152
153
|
@value = decode_values
|
153
154
|
return @value if @value.first.is_a? String
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
155
|
+
if @value.count == 1 && !return_hash
|
156
|
+
@value = @value.first['Value']
|
157
|
+
@value = transformation.call(@value) if transformation && !@value.nil?
|
158
|
+
return @value
|
159
|
+
else
|
160
|
+
@value = @value.map do |el|
|
161
|
+
el['Value'] = transformation.call(el['Value']) if transformation && !el['Value'].nil?
|
162
|
+
{ key: el['Key'], value: el['Value'] } if el['Value'] || nil_values
|
163
|
+
end.compact
|
164
|
+
end
|
159
165
|
end
|
160
166
|
# rubocop:enable PerceivedComplexity, MethodLength, CyclomaticComplexity, AbcSize
|
161
167
|
|
data/lib/diplomat/version.rb
CHANGED
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: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hamelink
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-08-
|
12
|
+
date: 2017-08-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|