diplomat 2.3.1 → 2.4.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/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 +2 -0
- data/lib/diplomat/rest_client.rb +8 -3
- data/lib/diplomat/version.rb +1 -1
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c7e8a3d9eafc0f8f531682772b965cae7d19fce0e7cfb875b8c28c0cceda992
|
4
|
+
data.tar.gz: dba720fa8b559c3a7ff1f9456ccf4f97fad2376144fbf4712676a09c6edc4798
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75aed31505c916be58fb45ee7c8c761279d7eb8b24a35819bfdb0a18e5807603d1fecca5dc0dcfadd9bf7d81259164143be09b455774cde3096b42cec2190184
|
7
|
+
data.tar.gz: 1034365593d00617b244e20cdcc1e7c0718ac488f9ba8b6ec615a0069fa491f1f6e8fb41380fa3f5a38a8d5808408b2cc34f72d2315dfd850315219b34e16567
|
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
@@ -41,10 +41,12 @@ module Diplomat
|
|
41
41
|
custom_params << ['passing'] if options[:passing]
|
42
42
|
custom_params << use_named_parameter('tag', options[:tag]) 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
|
@@ -146,9 +146,12 @@ module Diplomat
|
|
146
146
|
|
147
147
|
# Converts k/v data into ruby hash
|
148
148
|
def convert_to_hash(data)
|
149
|
-
data.map do |item|
|
149
|
+
data_h = data.map do |item|
|
150
150
|
item[:key].split('/').reverse.reduce(item[:value]) { |h, v| { v => h } }
|
151
|
-
end
|
151
|
+
end
|
152
|
+
data_h.reduce({}) do |dest, source|
|
153
|
+
DeepMerge.deep_merge!(source, dest, { preserve_unmergeables: true })
|
154
|
+
end
|
152
155
|
end
|
153
156
|
|
154
157
|
# Parse the body, apply it to the raw attribute
|
@@ -226,6 +229,8 @@ module Diplomat
|
|
226
229
|
consistency = 'consistent' if options[:consistent]
|
227
230
|
query_params << consistency
|
228
231
|
|
232
|
+
query_params << 'cached' if options[:cached]
|
233
|
+
|
229
234
|
# Parse url host
|
230
235
|
url_prefix = options[:http_addr] if options[:http_addr]
|
231
236
|
{ query_params: query_params, headers: headers, url_prefix: url_prefix }
|
data/lib/diplomat/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diplomat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hamelink
|
8
8
|
- Trevor Wood
|
9
|
+
- Pierre Souchay
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2020-
|
13
|
+
date: 2020-10-19 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: bundler
|
@@ -121,14 +122,14 @@ dependencies:
|
|
121
122
|
requirements:
|
122
123
|
- - "~>"
|
123
124
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
125
|
+
version: 12.3.3
|
125
126
|
type: :development
|
126
127
|
prerelease: false
|
127
128
|
version_requirements: !ruby/object:Gem::Requirement
|
128
129
|
requirements:
|
129
130
|
- - "~>"
|
130
131
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
132
|
+
version: 12.3.3
|
132
133
|
- !ruby/object:Gem::Dependency
|
133
134
|
name: rspec
|
134
135
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,7 +201,7 @@ dependencies:
|
|
200
201
|
version: '0.9'
|
201
202
|
- - "<"
|
202
203
|
- !ruby/object:Gem::Version
|
203
|
-
version:
|
204
|
+
version: 1.1.0
|
204
205
|
type: :runtime
|
205
206
|
prerelease: false
|
206
207
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -210,11 +211,12 @@ dependencies:
|
|
210
211
|
version: '0.9'
|
211
212
|
- - "<"
|
212
213
|
- !ruby/object:Gem::Version
|
213
|
-
version:
|
214
|
+
version: 1.1.0
|
214
215
|
description: Diplomat is a simple wrapper for Consul
|
215
216
|
email:
|
216
217
|
- john@johnhamelink.com
|
217
218
|
- trevor.g.wood@gmail.com
|
219
|
+
- p.souchay@criteo.com
|
218
220
|
executables: []
|
219
221
|
extensions: []
|
220
222
|
extra_rdoc_files: []
|
@@ -227,6 +229,7 @@ files:
|
|
227
229
|
- lib/diplomat.rb
|
228
230
|
- lib/diplomat/acl.rb
|
229
231
|
- lib/diplomat/agent.rb
|
232
|
+
- lib/diplomat/autopilot.rb
|
230
233
|
- lib/diplomat/check.rb
|
231
234
|
- lib/diplomat/configuration.rb
|
232
235
|
- lib/diplomat/datacenter.rb
|
@@ -260,15 +263,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
260
263
|
requirements:
|
261
264
|
- - ">="
|
262
265
|
- !ruby/object:Gem::Version
|
263
|
-
version: '0'
|
266
|
+
version: '2.0'
|
264
267
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
265
268
|
requirements:
|
266
269
|
- - ">="
|
267
270
|
- !ruby/object:Gem::Version
|
268
271
|
version: '0'
|
269
272
|
requirements: []
|
270
|
-
|
271
|
-
rubygems_version: 2.7.7
|
273
|
+
rubygems_version: 3.0.8
|
272
274
|
signing_key:
|
273
275
|
specification_version: 4
|
274
276
|
summary: Diplomat is a simple wrapper for Consul
|