diplomat 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 821e0c50069009a97db9397d14f0c5c4eefba50c
4
- data.tar.gz: 0204f17c74c81cc3676ef9332ed5bace9150e5ab
2
+ SHA256:
3
+ metadata.gz: df1251c77ca0e65f2e2b046a8f5c9c596a165fe08f382051f4b71646cd455f10
4
+ data.tar.gz: 5f53957806d93db43c1d8c0fae7497a07c8f62e1fcb2cc07d1608274b52436f4
5
5
  SHA512:
6
- metadata.gz: fdf627aad378afb53880105c43ad280d4eb81900f1c1ec82bed4d37abcaff34a9ea17cc7db8e022fb44ea4c4167019d32366687648d4233585645f83d8936788
7
- data.tar.gz: 5df07529deabb282661cb8cae6ccd5939685c7a4ab86d60f93306942d562f5301fa41fbd93cbcde9ce8ca5f3630cf21c9596e75d77b492611ec198f3a4036342
6
+ metadata.gz: 02d8ac73def0d239a67bb809870689f22708bac587b4820583d6bff0d0bc8c82326667cf9e9b1f2a496d4930a777e53cc80d9395c1e7198f62ce9bce0366011e
7
+ data.tar.gz: 6b5736c9f3d33df4686356e2baadebb41caf51cce148442f6a94a2440478fae0400de6f961e1a9b282736845cec6b97b3fa13ac6d2c90a6557d3ee40e6c6f8b3
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Diplomat
2
- [![Gem Version](https://badge.fury.io/rb/diplomat.svg)](http://badge.fury.io/rb/diplomat) [![Gem](https://img.shields.io/gem/dt/diplomat.svg)](https://rubygems.org/gems/diplomat/versions/2.0.0) [![Build Status](https://travis-ci.org/WeAreFarmGeek/diplomat.svg?branch=master)](https://travis-ci.org/WeAreFarmGeek/diplomat) [![Code Climate](https://codeclimate.com/github/johnhamelink/diplomat.png)](https://codeclimate.com/github/WeAreFarmGeek/diplomat) [![Dependency Status](https://gemnasium.com/WeAreFarmGeek/diplomat.svg)](https://gemnasium.com/WeAreFarmGeek/diplomat) [![Inline docs](http://inch-ci.org/github/wearefarmgeek/diplomat.svg?branch=master)](http://inch-ci.org/github/wearefarmgeek/diplomat)
2
+ [![Gem Version](https://badge.fury.io/rb/diplomat.svg)](http://badge.fury.io/rb/diplomat) [![Gem](https://img.shields.io/gem/dt/diplomat.svg)](https://rubygems.org/gems/diplomat/versions/2.0.0) [![Build Status](https://travis-ci.org/WeAreFarmGeek/diplomat.svg?branch=master)](https://travis-ci.org/WeAreFarmGeek/diplomat) [![Code Climate](https://codeclimate.com/github/johnhamelink/diplomat.svg)](https://codeclimate.com/github/WeAreFarmGeek/diplomat) [![Inline docs](http://inch-ci.org/github/wearefarmgeek/diplomat.svg?branch=master)](http://inch-ci.org/github/wearefarmgeek/diplomat)
3
3
  ### A HTTP Ruby API for [Consul](http://www.consul.io/)
4
4
 
5
5
  ![Diplomacy Boad Game](http://i.imgur.com/Nkuy4b7.jpg)
@@ -310,10 +310,8 @@ Diplomat.configure do |config|
310
310
  config.url = "http://localhost:8888"
311
311
  # Set up a custom Faraday Middleware
312
312
  config.middleware = MyCustomMiddleware
313
- # Connect into consul with custom access token (ACL)
314
- config.acl_token = "xxxxxxxx-yyyy-zzzz-1111-222222222222"
315
- # Set extra Faraday configuration options
316
- config.options = {ssl: { version: :TLSv1_2 }}
313
+ # Set extra Faraday configuration options and custom access token (ACL)
314
+ config.options = {ssl: {version: :TLSv1_2}, headers: {"X-Consul-Token" => "xxxxxxxx-yyyy-zzzz-1111-222222222222"}}
317
315
  end
318
316
  ```
319
317
 
data/lib/diplomat.rb CHANGED
@@ -23,11 +23,11 @@ module Diplomat
23
23
 
24
24
  raise 'Diplomat only supports ruby >= 2.0.0' unless RUBY_VERSION.to_f >= 2.0
25
25
 
26
- self.root_path = File.expand_path '..', __FILE__
27
- self.lib_path = File.expand_path '../diplomat', __FILE__
26
+ self.root_path = File.expand_path __dir__
27
+ self.lib_path = File.expand_path 'diplomat', __dir__
28
28
 
29
- require_libs 'configuration', 'rest_client', 'api_options', 'kv', 'datacenter',
30
- 'service', 'members', 'node', 'nodes', 'check', 'health', 'session', 'lock',
29
+ require_libs 'configuration', 'rest_client', 'kv', 'datacenter', 'service',
30
+ 'members', 'node', 'nodes', 'check', 'health', 'session', 'lock',
31
31
  'error', 'event', 'acl', 'maintenance', 'query', 'agent', 'status'
32
32
  self.configuration ||= Diplomat::Configuration.new
33
33
 
data/lib/diplomat/acl.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Diplomat
2
2
  # Methods for interacting with the Consul ACL API endpoint
3
3
  class Acl < Diplomat::RestClient
4
- include ApiOptions
5
-
6
4
  @access_methods = %i[list info create destroy update]
7
5
  attr_reader :id, :type, :acl
8
6
 
@@ -1,7 +1,7 @@
1
1
  module Diplomat
2
2
  # Methods for configuring Diplomat
3
3
  class Configuration
4
- attr_accessor :middleware
4
+ attr_reader :middleware
5
5
  attr_accessor :url, :acl_token, :options
6
6
 
7
7
  # Override defaults for configuration
@@ -18,7 +18,10 @@ module Diplomat
18
18
  # Define a middleware for Faraday
19
19
  # @param middleware [Class] Faraday Middleware class
20
20
  def middleware=(middleware)
21
- return @middleware = middleware if middleware.is_a? Array
21
+ if middleware.is_a? Array
22
+ @middleware = middleware
23
+ return
24
+ end
22
25
  @middleware = [middleware]
23
26
  end
24
27
  end
@@ -1,8 +1,6 @@
1
1
  module Diplomat
2
2
  # Methods for interacting with the Consul event API endpoint
3
3
  class Event < Diplomat::RestClient
4
- include ApiOptions
5
-
6
4
  @access_methods = %i[fire get_all get]
7
5
 
8
6
  # Send an event
data/lib/diplomat/kv.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Diplomat
2
2
  # Methods for interacting with the Consul KV API endpoint
3
3
  class Kv < Diplomat::RestClient
4
- include ApiOptions
5
-
6
4
  @access_methods = %i[get put delete txn]
7
5
  attr_reader :key, :value, :raw
8
6
 
@@ -80,6 +78,7 @@ module Diplomat
80
78
  return @raw.first['Session'] if @options && @options[:session]
81
79
  return decode_values if @options && @options[:decode_values]
82
80
  return convert_to_hash(return_value(return_nil_values, transformation, true)) if @options && @options[:convert_to_hash]
81
+
83
82
  return return_value(return_nil_values, transformation)
84
83
  when :wait
85
84
  index = raw.headers['x-consul-index']
@@ -204,6 +203,7 @@ module Diplomat
204
203
 
205
204
  def transaction_consistency(options)
206
205
  return [] unless options
206
+
207
207
  if options[:consistency] && options[:consistency] == 'stale'
208
208
  ['stale']
209
209
  elsif options[:consistency] && options[:consistency] == 'consistent'
@@ -215,6 +215,7 @@ module Diplomat
215
215
 
216
216
  def transaction_verification(transaction)
217
217
  raise Diplomat::InvalidTransaction unless transaction.is_a?(Array)
218
+
218
219
  transaction.each do |req|
219
220
  raise Diplomat::InvalidTransaction unless transaction_type_verification(req)
220
221
  raise Diplomat::InvalidTransaction unless transaction_verb_verification(req['KV'])
@@ -230,6 +231,7 @@ module Diplomat
230
231
  def transaction_verb_verification(txn)
231
232
  transaction_verb = txn['Verb']
232
233
  raise Diplomat::InvalidTransaction unless valid_transaction_verbs.include? transaction_verb
234
+
233
235
  test_requirements = valid_transaction_verbs[transaction_verb] - txn.keys
234
236
  test_requirements.empty?
235
237
  end
@@ -237,6 +239,7 @@ module Diplomat
237
239
  def encode_transaction(transaction)
238
240
  transaction.each do |txn|
239
241
  next unless valid_value_transactions.include? txn['KV']['Verb']
242
+
240
243
  value = txn['KV']['Value']
241
244
  txn['KV']['Value'] = Base64.encode64(value).chomp
242
245
  end
@@ -248,14 +251,18 @@ module Diplomat
248
251
  OpenStruct.new decoded_return
249
252
  end
250
253
 
251
- def decode_transaction(transaction)
254
+ def decode_transaction(transaction) # rubocop:disable Metrics/MethodLength
252
255
  return transaction if transaction['Results'].nil? || transaction['Results'].empty?
253
256
 
254
257
  transaction.tap do |txn|
255
258
  txn['Results'].each do |resp|
256
259
  next unless resp['KV']['Value']
257
- value = resp['KV']['Value']
258
- resp['KV']['Value'] = Base64.decode64(value) rescue nil # rubocop:disable RescueModifier
260
+
261
+ begin
262
+ resp['KV']['Value'] = Base64.decode64(resp['KV']['Value'])
263
+ rescue StandardError
264
+ nil
265
+ end
259
266
  end
260
267
  end
261
268
  end
data/lib/diplomat/lock.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Diplomat
2
2
  # Methods for interacting with the Consul lock API endpoint
3
3
  class Lock < Diplomat::RestClient
4
- include ApiOptions
5
-
6
4
  @access_methods = %i[acquire wait_to_acquire release]
7
5
 
8
6
  # Acquire a lock
@@ -37,6 +37,7 @@ module Diplomat
37
37
 
38
38
  return_status = raw.status == 200
39
39
  raise Diplomat::UnknownStatus, "status #{raw.status}: #{raw.body}" unless return_status
40
+
40
41
  return_status
41
42
  end
42
43
  # rubocop:enable AbcSize
data/lib/diplomat/node.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Diplomat
2
2
  # Methods for interacting with the Consul node API endpoint
3
3
  class Node < Diplomat::RestClient
4
- include ApiOptions
5
-
6
4
  @access_methods = %i[get get_all register deregister]
7
5
 
8
6
  # Get a node by it's key
@@ -1,8 +1,6 @@
1
1
  module Diplomat
2
2
  # Methods for interacting with the Consul query API endpoint
3
3
  class Query < Diplomat::RestClient
4
- include ApiOptions
5
-
6
4
  @access_methods = %i[get get_all create delete update execute explain]
7
5
 
8
6
  # Get a prepared query by it's key
@@ -2,13 +2,22 @@ module Diplomat
2
2
  # Base class for interacting with the Consul RESTful API
3
3
  class RestClient
4
4
  @access_methods = []
5
+ @configuration = nil
5
6
 
6
7
  # Initialize the fadaray connection
7
8
  # @param api_connection [Faraday::Connection,nil] supply mock API Connection
8
- def initialize(api_connection = nil)
9
+ # @param configuration [Diplomat::Configuration] a dedicated config to use
10
+ def initialize(api_connection = nil, configuration: nil)
11
+ @configuration = configuration
9
12
  start_connection api_connection
10
13
  end
11
14
 
15
+ # Get client configuration or global one if not specified via initialize.
16
+ # @return [Diplomat::Configuration] used by this client
17
+ def configuration
18
+ @configuration || ::Diplomat.configuration
19
+ end
20
+
12
21
  # Format url parameters into strings correctly
13
22
  # @param name [String] the name of the parameter
14
23
  # @param value [String] the value of the parameter
@@ -80,8 +89,8 @@ module Diplomat
80
89
  end
81
90
 
82
91
  def build_connection(api_connection, raise_error = false)
83
- api_connection || Faraday.new(Diplomat.configuration.url, Diplomat.configuration.options) do |faraday|
84
- Diplomat.configuration.middleware.each do |middleware|
92
+ api_connection || Faraday.new(configuration.url, configuration.options) do |faraday|
93
+ configuration.middleware.each do |middleware|
85
94
  faraday.use middleware
86
95
  end
87
96
 
@@ -134,14 +143,20 @@ module Diplomat
134
143
  # Parse the body, apply it to the raw attribute
135
144
  def parse_body
136
145
  return JSON.parse(@raw.body) if @raw.status == 200
146
+
137
147
  raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
138
148
  end
139
149
 
140
150
  # Return @raw with Value fields decoded
141
151
  def decode_values
142
152
  return @raw if @raw.first.is_a? String
153
+
143
154
  @raw.each_with_object([]) do |acc, el|
144
- acc['Value'] = Base64.decode64(acc['Value']) rescue nil # rubocop:disable RescueModifier
155
+ begin
156
+ acc['Value'] = Base64.decode64(acc['Value'])
157
+ rescue StandardError
158
+ nil
159
+ end
145
160
  el << acc
146
161
  el
147
162
  end
@@ -152,6 +167,7 @@ module Diplomat
152
167
  def return_value(nil_values = false, transformation = nil, return_hash = false)
153
168
  @value = decode_values
154
169
  return @value if @value.first.is_a? String
170
+
155
171
  if @value.count == 1 && !return_hash
156
172
  @value = @value.first['Value']
157
173
  @value = transformation.call(@value) if transformation && !@value.nil?
@@ -172,5 +188,47 @@ module Diplomat
172
188
  payload: (Base64.decode64(e['Payload']) unless e['Payload'].nil?) }
173
189
  end
174
190
  end
191
+
192
+ def check_acl_token
193
+ use_named_parameter('token', configuration.acl_token)
194
+ end
195
+
196
+ def use_cas(options)
197
+ options ? use_named_parameter('cas', options[:cas]) : []
198
+ end
199
+
200
+ def use_consistency(options)
201
+ options && options[:consistency] ? [options[:consistency].to_s] : []
202
+ end
203
+
204
+ # Mapping for valid key/value store transaction verbs and required parameters
205
+ #
206
+ # @return [Hash] valid key/store transaction verbs and required parameters
207
+ # rubocop:disable MethodLength
208
+ def valid_transaction_verbs
209
+ {
210
+ 'set' => %w[Key Value],
211
+ 'cas' => %w[Key Value Index],
212
+ 'lock' => %w[Key Value Session],
213
+ 'unlock' => %w[Key Value Session],
214
+ 'get' => %w[Key],
215
+ 'get-tree' => %w[Key],
216
+ 'check-index' => %w[Key Index],
217
+ 'check-session' => %w[Key Session],
218
+ 'delete' => %w[Key],
219
+ 'delete-tree' => %w[Key],
220
+ 'delete-cas' => %w[Key Index]
221
+ }
222
+ end
223
+ # rubocop:enable MethodLength
224
+
225
+ # Key/value store transactions that require that a value be set
226
+ #
227
+ # @return [Array<String>] verbs that require a value be set
228
+ def valid_value_transactions
229
+ @valid_value_transactions ||= valid_transaction_verbs.select do |verb, requires|
230
+ verb if requires.include? 'Value'
231
+ end
232
+ end
175
233
  end
176
234
  end
@@ -1,8 +1,6 @@
1
1
  module Diplomat
2
2
  # Methods for interacting with the Consul serivce API endpoint.
3
3
  class Service < Diplomat::RestClient
4
- include ApiOptions
5
-
6
4
  @access_methods = %i[get get_all register deregister register_external deregister_external maintenance]
7
5
 
8
6
  # Get a service by it's key
@@ -66,8 +64,10 @@ module Diplomat
66
64
  # @param definition [Hash] Hash containing definition of service
67
65
  # @return [Boolean]
68
66
  def register(definition, path = '/v1/agent/service/register')
67
+ url = [path]
68
+ url += check_acl_token
69
69
  json_definition = JSON.dump(definition)
70
- register = @conn.put path, json_definition
70
+ register = @conn.put concat_url(url), json_definition
71
71
  register.status == 200
72
72
  end
73
73
 
@@ -75,7 +75,9 @@ module Diplomat
75
75
  # @param service_name [String] Service name to de-register
76
76
  # @return [Boolean]
77
77
  def deregister(service_name)
78
- deregister = @conn.get "/v1/agent/service/deregister/#{service_name}"
78
+ url = ["/v1/agent/service/deregister/#{service_name}"]
79
+ url += check_acl_token
80
+ deregister = @conn.put concat_url(url)
79
81
  deregister.status == 200
80
82
  end
81
83
 
@@ -113,6 +115,5 @@ module Diplomat
113
115
  end
114
116
  maintenance.status == 200
115
117
  end
116
- # rubocop:enable AbcSize
117
118
  end
118
119
  end
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = '2.0.2'.freeze
2
+ VERSION = '2.0.3'.freeze
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: 2.0.2
4
+ version: 2.0.3
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-23 00:00:00.000000000 Z
12
+ date: 2019-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -17,56 +17,48 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.3'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '1.3'
28
- - !ruby/object:Gem::Dependency
29
- name: rake
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
20
+ version: '2.0'
21
+ - - ">="
33
22
  - !ruby/object:Gem::Version
34
- version: '12.0'
23
+ version: 2.0.1
35
24
  type: :development
36
25
  prerelease: false
37
26
  version_requirements: !ruby/object:Gem::Requirement
38
27
  requirements:
39
28
  - - "~>"
40
29
  - !ruby/object:Gem::Version
41
- version: '12.0'
30
+ version: '2.0'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.1
42
34
  - !ruby/object:Gem::Dependency
43
- name: pry
35
+ name: codeclimate-test-reporter
44
36
  requirement: !ruby/object:Gem::Requirement
45
37
  requirements:
46
38
  - - "~>"
47
39
  - !ruby/object:Gem::Version
48
- version: '0.9'
40
+ version: 0.4.0
49
41
  type: :development
50
42
  prerelease: false
51
43
  version_requirements: !ruby/object:Gem::Requirement
52
44
  requirements:
53
45
  - - "~>"
54
46
  - !ruby/object:Gem::Version
55
- version: '0.9'
47
+ version: 0.4.0
56
48
  - !ruby/object:Gem::Dependency
57
- name: rspec
49
+ name: cucumber
58
50
  requirement: !ruby/object:Gem::Requirement
59
51
  requirements:
60
52
  - - "~>"
61
53
  - !ruby/object:Gem::Version
62
- version: '3.2'
54
+ version: '2.0'
63
55
  type: :development
64
56
  prerelease: false
65
57
  version_requirements: !ruby/object:Gem::Requirement
66
58
  requirements:
67
59
  - - "~>"
68
60
  - !ruby/object:Gem::Version
69
- version: '3.2'
61
+ version: '2.0'
70
62
  - !ruby/object:Gem::Dependency
71
63
  name: fakes-rspec
72
64
  requirement: !ruby/object:Gem::Requirement
@@ -82,95 +74,89 @@ dependencies:
82
74
  - !ruby/object:Gem::Version
83
75
  version: '2.1'
84
76
  - !ruby/object:Gem::Dependency
85
- name: codeclimate-test-reporter
77
+ name: fivemat
86
78
  requirement: !ruby/object:Gem::Requirement
87
79
  requirements:
88
80
  - - "~>"
89
81
  - !ruby/object:Gem::Version
90
- version: 0.4.0
82
+ version: '1.3'
91
83
  type: :development
92
84
  prerelease: false
93
85
  version_requirements: !ruby/object:Gem::Requirement
94
86
  requirements:
95
87
  - - "~>"
96
88
  - !ruby/object:Gem::Version
97
- version: 0.4.0
89
+ version: '1.3'
98
90
  - !ruby/object:Gem::Dependency
99
- name: fivemat
91
+ name: gem-release
100
92
  requirement: !ruby/object:Gem::Requirement
101
93
  requirements:
102
94
  - - "~>"
103
95
  - !ruby/object:Gem::Version
104
- version: '1.3'
96
+ version: '0.7'
105
97
  type: :development
106
98
  prerelease: false
107
99
  version_requirements: !ruby/object:Gem::Requirement
108
100
  requirements:
109
101
  - - "~>"
110
102
  - !ruby/object:Gem::Version
111
- version: '1.3'
103
+ version: '0.7'
112
104
  - !ruby/object:Gem::Dependency
113
- name: gem-release
105
+ name: pry
114
106
  requirement: !ruby/object:Gem::Requirement
115
107
  requirements:
116
108
  - - "~>"
117
109
  - !ruby/object:Gem::Version
118
- version: '0.7'
110
+ version: '0.9'
119
111
  type: :development
120
112
  prerelease: false
121
113
  version_requirements: !ruby/object:Gem::Requirement
122
114
  requirements:
123
115
  - - "~>"
124
116
  - !ruby/object:Gem::Version
125
- version: '0.7'
117
+ version: '0.9'
126
118
  - !ruby/object:Gem::Dependency
127
- name: cucumber
119
+ name: rake
128
120
  requirement: !ruby/object:Gem::Requirement
129
121
  requirements:
130
122
  - - "~>"
131
123
  - !ruby/object:Gem::Version
132
- version: '2.0'
124
+ version: '12.0'
133
125
  type: :development
134
126
  prerelease: false
135
127
  version_requirements: !ruby/object:Gem::Requirement
136
128
  requirements:
137
129
  - - "~>"
138
130
  - !ruby/object:Gem::Version
139
- version: '2.0'
131
+ version: '12.0'
140
132
  - !ruby/object:Gem::Dependency
141
- name: rubocop
133
+ name: rspec
142
134
  requirement: !ruby/object:Gem::Requirement
143
135
  requirements:
144
136
  - - "~>"
145
137
  - !ruby/object:Gem::Version
146
- version: '0.47'
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- version: 0.47.1
138
+ version: '3.2'
150
139
  type: :development
151
140
  prerelease: false
152
141
  version_requirements: !ruby/object:Gem::Requirement
153
142
  requirements:
154
143
  - - "~>"
155
144
  - !ruby/object:Gem::Version
156
- version: '0.47'
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: 0.47.1
145
+ version: '3.2'
160
146
  - !ruby/object:Gem::Dependency
161
- name: json
147
+ name: rubocop
162
148
  requirement: !ruby/object:Gem::Requirement
163
149
  requirements:
164
- - - ">="
150
+ - - "~>"
165
151
  - !ruby/object:Gem::Version
166
- version: '0'
167
- type: :runtime
152
+ version: '0.49'
153
+ type: :development
168
154
  prerelease: false
169
155
  version_requirements: !ruby/object:Gem::Requirement
170
156
  requirements:
171
- - - ">="
157
+ - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: '0'
159
+ version: '0.49'
174
160
  - !ruby/object:Gem::Dependency
175
161
  name: faraday
176
162
  requirement: !ruby/object:Gem::Requirement
@@ -201,7 +187,6 @@ files:
201
187
  - lib/diplomat.rb
202
188
  - lib/diplomat/acl.rb
203
189
  - lib/diplomat/agent.rb
204
- - lib/diplomat/api_options.rb
205
190
  - lib/diplomat/check.rb
206
191
  - lib/diplomat/configuration.rb
207
192
  - lib/diplomat/datacenter.rb
@@ -240,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
225
  version: '0'
241
226
  requirements: []
242
227
  rubyforge_project:
243
- rubygems_version: 2.6.11
228
+ rubygems_version: 2.7.7
244
229
  signing_key:
245
230
  specification_version: 4
246
231
  summary: Diplomat is a simple wrapper for Consul
@@ -1,46 +0,0 @@
1
- module Diplomat
2
- # Helper methods for interacting with the Consul RESTful API
3
- module ApiOptions
4
- def check_acl_token
5
- use_named_parameter('token', Diplomat.configuration.acl_token)
6
- end
7
-
8
- def use_cas(options)
9
- options ? use_named_parameter('cas', options[:cas]) : []
10
- end
11
-
12
- def use_consistency(options)
13
- options && options[:consistency] ? [options[:consistency].to_s] : []
14
- end
15
-
16
- # Mapping for valid key/value store transaction verbs and required parameters
17
- #
18
- # @return [Hash] valid key/store transaction verbs and required parameters
19
- # rubocop:disable MethodLength
20
- def valid_transaction_verbs
21
- {
22
- 'set' => %w[Key Value],
23
- 'cas' => %w[Key Value Index],
24
- 'lock' => %w[Key Value Session],
25
- 'unlock' => %w[Key Value Session],
26
- 'get' => %w[Key],
27
- 'get-tree' => %w[Key],
28
- 'check-index' => %w[Key Index],
29
- 'check-session' => %w[Key Session],
30
- 'delete' => %w[Key],
31
- 'delete-tree' => %w[Key],
32
- 'delete-cas' => %w[Key Index]
33
- }
34
- end
35
- # rubocop:enable MethodLength
36
-
37
- # Key/value store transactions that require that a value be set
38
- #
39
- # @return [Array<String>] verbs that require a value be set
40
- def valid_value_transactions
41
- @valid_value_transactions ||= valid_transaction_verbs.select do |verb, requires|
42
- verb if requires.include? 'Value'
43
- end
44
- end
45
- end
46
- end