diplomat 2.3.3 → 2.4.0

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
2
  SHA256:
3
- metadata.gz: 1ace94d171ba67ae1b4b8ddbb3a5ff959564925e9fc35f9449de864445f61318
4
- data.tar.gz: fc1e85c7e9b2e327fa765d4a14d6df65407dd8851bfaee43769c44acadefe179
3
+ metadata.gz: dc7fe7869eadb5b93aa45340e84587d631975b4a90507a05168bea3018670054
4
+ data.tar.gz: 6e5516f00e6d51bc36cb7ee8abf39d8a4f2c8c4b689ff15b39bbf7586cdb8613
5
5
  SHA512:
6
- metadata.gz: df7576f01b09a1475b3149c16a85b7142aa0367b2934f8fd1689309f2ce55b0424437f102f2face472f447929a6e029be08ddfa272d56b4590c3b681b05dec19
7
- data.tar.gz: da846235b84bb59ff064d1530eaeb9f62c25308ba71bd4e6b3c3056a1420ab6dd5115f350b348c6c55ee201810659ce62d0d3f3568a1d46b4f82f3c60646ac71
6
+ metadata.gz: 41dc809f1752060d51e33edb6a4989a451ec7690ebb80516906b914ce8fa1b9a2ddee570ee98216ec19ad6921f162e0c8ee732d674f46c7e9bc2f63bbe1077fa
7
+ data.tar.gz: 1cb32fb53c7e619de9170733918e0e359092ba453c6574277df69ebb63b50bb2027fa0467183cfb1f52046cb974c5e1741a76322539be14ccf02eacfc1da25bd
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Diplomat
2
- [![Gem Version](https://badge.fury.io/rb/diplomat.svg)](https://rubygems.org/gems/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)
2
+ [![Gem Version](https://badge.fury.io/rb/diplomat.svg)](https://rubygems.org/gems/diplomat) [![Gem](https://img.shields.io/gem/dt/diplomat.svg)](https://rubygems.org/gems/diplomat) [![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 Board Game](http://i.imgur.com/Nkuy4b7.jpg)
@@ -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)
@@ -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
@@ -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 = 'http://localhost:8500', acl_token = nil, options = {})
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diplomat
4
- VERSION = '2.3.3'
4
+ VERSION = '2.4.0'
5
5
  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.3.3
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-02-29 00:00:00.000000000 Z
13
+ date: 2020-05-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -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