diplomat 2.3.2 → 2.4.3
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/README.md +17 -1
- data/lib/diplomat.rb +1 -1
- data/lib/diplomat/acl.rb +1 -1
- data/lib/diplomat/autopilot.rb +30 -0
- data/lib/diplomat/configuration.rb +11 -1
- data/lib/diplomat/health.rb +3 -1
- data/lib/diplomat/rest_client.rb +16 -3
- data/lib/diplomat/service.rb +1 -15
- data/lib/diplomat/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b571a3aec13d14c2ab39cfd7ab851a3aad28aaa959d291ed03416efda30ded9b
|
4
|
+
data.tar.gz: f915b612a7a7f7caf110be521adb3eeca060319ab8291e5329c13b055e7e22f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6049a79b752f39d63da2bf5aa7fa10614b519f7e1cd6d055fe3479a32ecc8ae10e343c56a2b9bd5c51261d617444bd240aac9d644775cec3138bee483d8ccf62
|
7
|
+
data.tar.gz: 3bd373b3983469c65c120d2346cf9d74b2ab998e7748fc1e72343d079273d197d164741ae87686efb4f11412ad466a922f46973d16b7f3452f8a3b6460cd84ad
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Diplomat
|
2
|
-
[](https://rubygems.org/gems/diplomat) [](https://rubygems.org/gems/diplomat
|
2
|
+
[](https://rubygems.org/gems/diplomat) [](https://rubygems.org/gems/diplomat) [](https://travis-ci.org/WeAreFarmGeek/diplomat) [](https://codeclimate.com/github/WeAreFarmGeek/diplomat) [](http://inch-ci.org/github/wearefarmgeek/diplomat)
|
3
3
|
### A HTTP Ruby API for [Consul](http://www.consul.io/)
|
4
4
|
|
5
5
|

|
@@ -314,6 +314,22 @@ Get an array of Raft peers for the datacenter in which the agent is running
|
|
314
314
|
Diplomat::Status.peers()
|
315
315
|
```
|
316
316
|
|
317
|
+
### Autopilot
|
318
|
+
|
319
|
+
Returns information about the autopilot configuration of the Consul cluster
|
320
|
+
|
321
|
+
Get the current autopilot configuration
|
322
|
+
|
323
|
+
```ruby
|
324
|
+
Diplomat::Autopilot.get_configuration()
|
325
|
+
```
|
326
|
+
|
327
|
+
Get the health status from autopilot
|
328
|
+
|
329
|
+
```ruby
|
330
|
+
Diplomat::Autopilot.get_health()
|
331
|
+
```
|
332
|
+
|
317
333
|
### Maintenance mode
|
318
334
|
|
319
335
|
Enable maintenance mode on a host, with optional reason and DC (requires access to local agent)
|
data/lib/diplomat.rb
CHANGED
@@ -31,7 +31,7 @@ module Diplomat
|
|
31
31
|
require_libs 'configuration', 'rest_client', 'kv', 'datacenter', 'service',
|
32
32
|
'members', 'node', 'nodes', 'check', 'health', 'session', 'lock',
|
33
33
|
'error', 'event', 'acl', 'maintenance', 'query', 'agent', 'status',
|
34
|
-
'policy', 'token', 'role'
|
34
|
+
'policy', 'token', 'role', 'autopilot'
|
35
35
|
self.configuration ||= Diplomat::Configuration.new
|
36
36
|
|
37
37
|
class << self
|
data/lib/diplomat/acl.rb
CHANGED
@@ -73,7 +73,7 @@ module Diplomat
|
|
73
73
|
# Destroy an ACl token by its id
|
74
74
|
# @param ID [String] the Acl ID
|
75
75
|
# @param options [Hash] options parameter hash
|
76
|
-
# @return [Bool]
|
76
|
+
# @return [Bool] true if operation succeeded
|
77
77
|
def destroy(id, options = {})
|
78
78
|
@id = id
|
79
79
|
@raw = send_put_request(@conn, ["/v1/acl/destroy/#{@id}"], options, nil)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Diplomat
|
4
|
+
# Methods for interacting with the Consul operator autopilot API endpoint
|
5
|
+
class Autopilot < Diplomat::RestClient
|
6
|
+
@access_methods = %i[get_configuration get_health update]
|
7
|
+
|
8
|
+
# Get autopilot configuration
|
9
|
+
# @param options [Hash] options parameter hash
|
10
|
+
# @return [OpenStruct] all data associated with the autopilot configuration
|
11
|
+
def get_configuration(options = {})
|
12
|
+
custom_params = []
|
13
|
+
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
14
|
+
|
15
|
+
ret = send_get_request(@conn, ['/v1/operator/autopilot/configuration'], options, custom_params)
|
16
|
+
JSON.parse(ret.body)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get health status from the autopilot
|
20
|
+
# @param options [Hash] options parameter hash
|
21
|
+
# @return [OpenStruct] all data associated with the health of the autopilot
|
22
|
+
def get_health(options = {})
|
23
|
+
custom_params = []
|
24
|
+
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
25
|
+
|
26
|
+
ret = send_get_request(@conn, ['/v1/operator/autopilot/health'], options, custom_params)
|
27
|
+
JSON.parse(ret.body)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -6,11 +6,20 @@ module Diplomat
|
|
6
6
|
attr_reader :middleware
|
7
7
|
attr_accessor :url, :acl_token, :options
|
8
8
|
|
9
|
+
# Get the most appropriate consul agent value from env
|
10
|
+
# Parse the environment variable `CONSUL_HTTP_ADDR` and prefixes it with http:// if needed
|
11
|
+
# Return default http://localhost:8500 if not found
|
12
|
+
def self.parse_consul_addr
|
13
|
+
ret = ENV['CONSUL_HTTP_ADDR'] || 'http://localhost:8500'
|
14
|
+
ret = "http://#{ret}" unless ret.start_with?('http://', 'https://')
|
15
|
+
ret
|
16
|
+
end
|
17
|
+
|
9
18
|
# Override defaults for configuration
|
10
19
|
# @param url [String] consul's connection URL
|
11
20
|
# @param acl_token [String] a connection token used when making requests to consul
|
12
21
|
# @param options [Hash] extra options to configure Faraday::Connection
|
13
|
-
def initialize(url =
|
22
|
+
def initialize(url = Configuration.parse_consul_addr, acl_token = ENV['CONSUL_HTTP_TOKEN'], options = {})
|
14
23
|
@middleware = []
|
15
24
|
@url = url
|
16
25
|
@acl_token = acl_token
|
@@ -19,6 +28,7 @@ module Diplomat
|
|
19
28
|
|
20
29
|
# Define a middleware for Faraday
|
21
30
|
# @param middleware [Class] Faraday Middleware class
|
31
|
+
# @return [Array] Array of Faraday Middlewares
|
22
32
|
def middleware=(middleware)
|
23
33
|
if middleware.is_a? Array
|
24
34
|
@middleware = middleware
|
data/lib/diplomat/health.rb
CHANGED
@@ -39,12 +39,14 @@ module Diplomat
|
|
39
39
|
custom_params = []
|
40
40
|
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
41
41
|
custom_params << ['passing'] if options[:passing]
|
42
|
-
custom_params
|
42
|
+
custom_params += [*options[:tag]].map { |value| use_named_parameter('tag', value) } if options[:tag]
|
43
43
|
custom_params << use_named_parameter('near', options[:near]) if options[:near]
|
44
|
+
custom_params << use_named_parameter('node-meta', options[:node_meta]) if options[:node_meta]
|
44
45
|
|
45
46
|
ret = send_get_request(@conn, ["/v1/health/service/#{s}"], options, custom_params)
|
46
47
|
JSON.parse(ret.body).map { |service| OpenStruct.new service }
|
47
48
|
end
|
49
|
+
|
48
50
|
# rubocop:enable Metrics/PerceivedComplexity
|
49
51
|
|
50
52
|
# Get service health
|
data/lib/diplomat/rest_client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'deep_merge'
|
3
|
+
require 'deep_merge/core'
|
4
4
|
|
5
5
|
module Diplomat
|
6
6
|
# Base class for interacting with the Consul RESTful API
|
@@ -140,15 +140,26 @@ module Diplomat
|
|
140
140
|
faraday.request :url_encoded
|
141
141
|
faraday.response :raise_error unless raise_error
|
142
142
|
|
143
|
+
# We have to provide a custom params encoder here because Faraday - by default - assumes that
|
144
|
+
# list keys have [] as part of their name. This is however does not match the expectation of
|
145
|
+
# the Consul API, which assumes the same query param to simply be repeated
|
146
|
+
#
|
147
|
+
# So faraday reduces this: http://localhost:8500?a=1&a=2 to http://localhost:8500?a=2 unless you
|
148
|
+
# explicitly tell it not to.
|
149
|
+
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
150
|
+
|
143
151
|
faraday.adapter Faraday.default_adapter
|
144
152
|
end
|
145
153
|
end
|
146
154
|
|
147
155
|
# Converts k/v data into ruby hash
|
148
156
|
def convert_to_hash(data)
|
149
|
-
data.map do |item|
|
157
|
+
data_h = data.map do |item|
|
150
158
|
item[:key].split('/').reverse.reduce(item[:value]) { |h, v| { v => h } }
|
151
|
-
end
|
159
|
+
end
|
160
|
+
data_h.reduce({}) do |dest, source|
|
161
|
+
DeepMerge.deep_merge!(source, dest, { preserve_unmergeables: true })
|
162
|
+
end
|
152
163
|
end
|
153
164
|
|
154
165
|
# Parse the body, apply it to the raw attribute
|
@@ -226,6 +237,8 @@ module Diplomat
|
|
226
237
|
consistency = 'consistent' if options[:consistent]
|
227
238
|
query_params << consistency
|
228
239
|
|
240
|
+
query_params << 'cached' if options[:cached]
|
241
|
+
|
229
242
|
# Parse url host
|
230
243
|
url_prefix = options[:http_addr] if options[:http_addr]
|
231
244
|
{ query_params: query_params, headers: headers, url_prefix: url_prefix }
|
data/lib/diplomat/service.rb
CHANGED
@@ -17,21 +17,7 @@ module Diplomat
|
|
17
17
|
custom_params << use_named_parameter('wait', options[:wait]) if options[:wait]
|
18
18
|
custom_params << use_named_parameter('index', options[:index]) if options[:index]
|
19
19
|
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
20
|
-
if options[:tag]
|
21
|
-
# tag can be either a String, or an array of strings
|
22
|
-
# by splatting it is guaranteed to be an array of strings
|
23
|
-
[*options[:tag]].each do |value|
|
24
|
-
custom_params << use_named_parameter('tag', value)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# We have to provide a custom params encoder here because Faraday - by default - assumes that
|
29
|
-
# list keys have [] as part of their name. This is however not the case for consul tags, which
|
30
|
-
# just use repeated occurences of the same key.
|
31
|
-
#
|
32
|
-
# So faraday reduces this: http://localhost:8500?a=1&a=2 to http://localhost:8500?a=2 unless you
|
33
|
-
# explicitly tell it not to.
|
34
|
-
options[:params_encoder] = Faraday::FlatParamsEncoder
|
20
|
+
custom_params += [*options[:tag]].map { |value| use_named_parameter('tag', value) } if options[:tag]
|
35
21
|
|
36
22
|
ret = send_get_request(@conn, ["/v1/catalog/service/#{key}"], options, custom_params)
|
37
23
|
if meta && ret.headers
|
data/lib/diplomat/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diplomat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3
|
4
|
+
version: 2.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hamelink
|
8
8
|
- Trevor Wood
|
9
9
|
- Pierre Souchay
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-01-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -122,14 +122,14 @@ dependencies:
|
|
122
122
|
requirements:
|
123
123
|
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 12.3.3
|
126
126
|
type: :development
|
127
127
|
prerelease: false
|
128
128
|
version_requirements: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version:
|
132
|
+
version: 12.3.3
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
134
|
name: rspec
|
135
135
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,7 +201,7 @@ dependencies:
|
|
201
201
|
version: '0.9'
|
202
202
|
- - "<"
|
203
203
|
- !ruby/object:Gem::Version
|
204
|
-
version:
|
204
|
+
version: 1.1.0
|
205
205
|
type: :runtime
|
206
206
|
prerelease: false
|
207
207
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -211,7 +211,7 @@ dependencies:
|
|
211
211
|
version: '0.9'
|
212
212
|
- - "<"
|
213
213
|
- !ruby/object:Gem::Version
|
214
|
-
version:
|
214
|
+
version: 1.1.0
|
215
215
|
description: Diplomat is a simple wrapper for Consul
|
216
216
|
email:
|
217
217
|
- john@johnhamelink.com
|
@@ -229,6 +229,7 @@ files:
|
|
229
229
|
- lib/diplomat.rb
|
230
230
|
- lib/diplomat/acl.rb
|
231
231
|
- lib/diplomat/agent.rb
|
232
|
+
- lib/diplomat/autopilot.rb
|
232
233
|
- lib/diplomat/check.rb
|
233
234
|
- lib/diplomat/configuration.rb
|
234
235
|
- lib/diplomat/datacenter.rb
|
@@ -254,7 +255,7 @@ homepage: https://github.com/WeAreFarmGeek/diplomat
|
|
254
255
|
licenses:
|
255
256
|
- BSD-3-Clause
|
256
257
|
metadata: {}
|
257
|
-
post_install_message:
|
258
|
+
post_install_message:
|
258
259
|
rdoc_options: []
|
259
260
|
require_paths:
|
260
261
|
- lib
|
@@ -269,9 +270,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
270
|
- !ruby/object:Gem::Version
|
270
271
|
version: '0'
|
271
272
|
requirements: []
|
272
|
-
|
273
|
-
|
274
|
-
signing_key:
|
273
|
+
rubygems_version: 3.1.2
|
274
|
+
signing_key:
|
275
275
|
specification_version: 4
|
276
276
|
summary: Diplomat is a simple wrapper for Consul
|
277
277
|
test_files: []
|