diplomat 0.16.2 → 0.17.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: 0ba37ba0f0744c7b424c81b524cd86c6c14d3284
4
- data.tar.gz: a61b033018328f55d8c4ce894c10fe675fbab896
3
+ metadata.gz: 62862f6656ae4dd60092e29e884c722b22179b01
4
+ data.tar.gz: 6414b0363e8213a40d4b247b25a301fca3635de4
5
5
  SHA512:
6
- metadata.gz: 3155ef8a9a9eaad49cfacc57fc2beffc603f73213aa0212576a5b3d77fdc0c73a5722414939a6b82824b7210f06aa3cfa1c531895b2e5565f9c3b7a8811a5599
7
- data.tar.gz: d0ec12eb626632ae3135cf795fed79317202820884f1064a74d6c15d065c5af402c31a7d2a8f1436d460b3532c7647c4df5eac7d1f4209f8f88d89561f16228e
6
+ metadata.gz: d0b382b7644788c012d204e5c666efb53fe493b456234b3f42cc7bfeb72d004b2c54e4f16afc58b176d114278c50973c489fa2e0795608f7dbc8acf17a6cc342
7
+ data.tar.gz: f6230d83e8c5547eb20e173ceb43de5e6a42ecf6094c49898b51e3b5ada275dfee34f0dc9c671a9d1cec51f775acd3ae647ab18554e77681a962ad4f6b9f78b4
data/lib/diplomat/acl.rb CHANGED
@@ -21,7 +21,7 @@ module Diplomat
21
21
  url += use_consistency(@options)
22
22
 
23
23
  raw = @conn_no_err.get concat_url url
24
- if raw.status == 200 and raw.body
24
+ if raw.status == 200 and raw.body != "null"
25
25
  case found
26
26
  when :reject
27
27
  raise Diplomat::AclAlreadyExists, @id
@@ -29,7 +29,7 @@ module Diplomat
29
29
  @raw = raw
30
30
  return parse_body
31
31
  end
32
- elsif raw.status == 200 and !raw.body
32
+ elsif raw.status == 200 and raw.body == "null"
33
33
  case not_found
34
34
  when :reject
35
35
  raise Diplomat::AclNotFound, @id
data/lib/diplomat/kv.rb CHANGED
@@ -20,6 +20,7 @@ module Diplomat
20
20
  # @option options [Boolean] :decode_values Return consul response with decoded values.
21
21
  # @option options [String] :separator List only up to a given separator. Only applies when combined with :keys option.
22
22
  # @option options [Boolean] :nil_values If to return keys/dirs with nil values
23
+ # @option options [Callable] :transformation funnction to invoke on keys values
23
24
  # @param not_found [Symbol] behaviour if the key doesn't exist;
24
25
  # :reject with exception, :return degenerate value, or :wait for it to appear
25
26
  # @param found [Symbol] behaviour if the key does exist;
@@ -54,6 +55,7 @@ module Diplomat
54
55
  url += separator(@options)
55
56
 
56
57
  return_nil_values = (@options and @options[:nil_values])
58
+ transformation = (@options and @options[:transformation] and @options[:transformation].methods.find_index(:call)) ? @options[:transformation] : nil
57
59
 
58
60
  # 404s OK using this connection
59
61
  raw = @conn_no_err.get concat_url url
@@ -79,7 +81,7 @@ module Diplomat
79
81
  if @options and @options[:decode_values]
80
82
  return decode_values
81
83
  end
82
- return return_value(return_nil_values)
84
+ return return_value(return_nil_values, transformation)
83
85
  when :wait
84
86
  index = raw.headers["x-consul-index"]
85
87
  end
@@ -94,7 +96,7 @@ module Diplomat
94
96
  req.options.timeout = 86400
95
97
  end
96
98
  parse_body
97
- return_value(return_nil_values)
99
+ return_value(return_nil_values, transformation)
98
100
  end
99
101
 
100
102
  # Associate a value with a key
data/lib/diplomat/lock.rb CHANGED
@@ -3,6 +3,8 @@ require 'faraday'
3
3
  module Diplomat
4
4
  class Lock < Diplomat::RestClient
5
5
 
6
+ include ApiOptions
7
+
6
8
  @access_methods = [ :acquire, :wait_to_acquire, :release ]
7
9
 
8
10
  # Acquire a lock
@@ -12,7 +14,11 @@ module Diplomat
12
14
  # @return [Boolean] If the lock was acquired
13
15
  def acquire key, session, value=nil
14
16
  raw = @conn.put do |req|
15
- req.url "/v1/kv/#{key}?acquire=#{session}"
17
+ url = ["/v1/kv/#{key}"]
18
+ url += use_named_parameter('acquire', session)
19
+ url += check_acl_token
20
+
21
+ req.url concat_url url
16
22
  req.body = value unless value.nil?
17
23
  end
18
24
  raw.body == 'true'
@@ -40,7 +46,11 @@ module Diplomat
40
46
  # @return [nil]
41
47
  def release key, session
42
48
  raw = @conn.put do |req|
43
- req.url "/v1/kv/#{key}?release=#{session}"
49
+ url = ["/v1/kv/#{key}"]
50
+ url += use_named_parameter('release', session)
51
+ url += check_acl_token
52
+
53
+ req.url concat_url url
44
54
  end
45
55
  return raw.body
46
56
  end
@@ -86,14 +86,17 @@ module Diplomat
86
86
  end
87
87
 
88
88
  # Get the key/value(s) from the raw output
89
- def return_value(nil_values=false)
89
+ def return_value(nil_values=false, transformation=nil)
90
90
  @value = decode_values
91
91
  if @value.first.is_a? String
92
92
  return @value
93
93
  elsif @value.count == 1
94
- @value.first["Value"]
94
+ @value = @value.first["Value"]
95
+ @value = transformation.call(@value) if transformation and not @value.nil?
96
+ return @value
95
97
  else
96
98
  @value = @value.map do |el|
99
+ el["Value"] = transformation.call(el["Value"]) if transformation and not el["Value"].nil?
97
100
  { :key => el["Key"], :value => el["Value"] } if el["Value"] or nil_values
98
101
  end.compact
99
102
  end
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.16.2"
2
+ VERSION = "0.17.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.16.2
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink