diplomat 1.3.0 → 2.0.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
  SHA1:
3
- metadata.gz: 7e314345fea055152e86ff0e0a166185de4889f0
4
- data.tar.gz: 7630435e44ebfab12efe41d3949a880bb9538d7d
3
+ metadata.gz: 0aa77dadc7f5b36f11bdd50ee2e43b1bad16d351
4
+ data.tar.gz: e5c534280a221d8f17e2195a68fb9863cd58f31e
5
5
  SHA512:
6
- metadata.gz: 180b5d54fb5ee0ef5758ec5f22da3408b2cc2b9bfe135640a0755f84e5dc8d8176bf4215a0a24e44091f247a392e49cd3ec3996f0b812e657a6f0fa4346c4a4d
7
- data.tar.gz: 4045fb41d2ae39d4e6a2de5412782574e67834f7932042dcb4b52f1250add0666f7506290183d200d86ed6d8638810360be275a7f4c7a5bb3c1fbf20524f2661
6
+ metadata.gz: bf071f060eb8683f220baff80a21974d1b25e73e25caaa1e9a825949752476be8e76f85da1874ba003cbf6b1b8d580c85ffa733155299305e79edfb0bb50acad
7
+ data.tar.gz: d57740b2bb515c6e74db8540db26e1dc5ef63b0e1d3cb3d8cdef554e9d9d48731e98f20a78827e76201ed22c8d8c06d0ca28645ab92d68163f0c1717b16e1405
data/README.md CHANGED
@@ -338,4 +338,4 @@ This is traditionally kept inside the `config/initializers` directory if you're
338
338
 
339
339
  ## Enjoy!
340
340
 
341
- ![Photo Copyright "merlinmann". All rights reserved.](http://i.imgur.com/3mBwzR9.jpg Photo Copyright "merlinmann" https://www.flickr.com/photos/merlin/. All rights reserved.)
341
+ ![Photo Copyright "merlinmann" https://www.flickr.com/photos/merlin/. All rights reserved.](http://i.imgur.com/3mBwzR9.jpg)
@@ -77,7 +77,7 @@ module Diplomat
77
77
  @raw = parse_body
78
78
  return @raw.first['ModifyIndex'] if @options && @options[:modify_index]
79
79
  return decode_values if @options && @options[:decode_values]
80
- return convert_to_hash(return_value(return_nil_values, transformation)) if @options && @options[:convert_to_hash]
80
+ return convert_to_hash(return_value(return_nil_values, transformation, true)) if @options && @options[:convert_to_hash]
81
81
  return return_value(return_nil_values, transformation)
82
82
  when :wait
83
83
  index = raw.headers['x-consul-index']
@@ -81,13 +81,14 @@ module Diplomat
81
81
 
82
82
  def build_connection(api_connection, raise_error = false)
83
83
  api_connection || Faraday.new(Diplomat.configuration.url, Diplomat.configuration.options) do |faraday|
84
- faraday.adapter Faraday.default_adapter
85
- faraday.request :url_encoded
86
- faraday.response :raise_error unless raise_error
87
-
88
84
  Diplomat.configuration.middleware.each do |middleware|
89
85
  faraday.use middleware
90
86
  end
87
+
88
+ faraday.request :url_encoded
89
+ faraday.response :raise_error unless raise_error
90
+
91
+ faraday.adapter Faraday.default_adapter
91
92
  end
92
93
  end
93
94
 
@@ -148,10 +149,10 @@ module Diplomat
148
149
 
149
150
  # Get the key/value(s) from the raw output
150
151
  # rubocop:disable PerceivedComplexity, MethodLength, CyclomaticComplexity, AbcSize
151
- def return_value(nil_values = false, transformation = nil)
152
+ def return_value(nil_values = false, transformation = nil, return_hash = false)
152
153
  @value = decode_values
153
154
  return @value if @value.first.is_a? String
154
- if @value.count == 1
155
+ if @value.count == 1 && !return_hash
155
156
  @value = @value.first['Value']
156
157
  @value = transformation.call(@value) if transformation && !@value.nil?
157
158
  return @value
@@ -3,7 +3,7 @@ module Diplomat
3
3
  class Service < Diplomat::RestClient
4
4
  include ApiOptions
5
5
 
6
- @access_methods = %i[get get_all register deregister register_external deregister_external]
6
+ @access_methods = %i[get get_all register deregister register_external deregister_external maintenance]
7
7
 
8
8
  # Get a service by it's key
9
9
  # @param key [String] the key
@@ -94,5 +94,25 @@ module Diplomat
94
94
  deregister = @conn.put '/v1/catalog/deregister', json_definition
95
95
  deregister.status == 200
96
96
  end
97
+
98
+ # Enable or disable maintenance for a service
99
+ # @param [Hash] opts the options for enabling or disabling maintenance for a service
100
+ # @options opts [Boolean] :enable (true) whether to enable or disable maintenance
101
+ # @options opts [String] :reason reason for the service maintenance
102
+ # @raise [Diplomat::PathNotFound] if the request fails
103
+ # @return [Boolean] if the request was successful or not
104
+ def maintenance(service_id, options = { enable: true })
105
+ url = ["/v1/agent/service/maintenance/#{service_id}"]
106
+ url += check_acl_token
107
+ url << ["enable=#{options[:enable]}"]
108
+ url << ["reason=#{options[:reason].split(' ').join('+')}"] if options && options[:reason]
109
+ begin
110
+ maintenance = @conn.put concat_url(url)
111
+ rescue Faraday::ClientError
112
+ raise Diplomat::PathNotFound
113
+ end
114
+ maintenance.status == 200
115
+ end
116
+ # rubocop:enable AbcSize
97
117
  end
98
118
  end
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '2.0.0'.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: 1.3.0
4
+ version: 2.0.0
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-04-15 00:00:00.000000000 Z
12
+ date: 2017-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -240,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  version: '0'
241
241
  requirements: []
242
242
  rubyforge_project:
243
- rubygems_version: 2.6.8
243
+ rubygems_version: 2.6.11
244
244
  signing_key:
245
245
  specification_version: 4
246
246
  summary: Diplomat is a simple wrapper for Consul