rabbitmq_http_api_client 1.15.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
  SHA256:
3
- metadata.gz: 8f9e2a79489994cac18b3d82cbae44444ad8c9f8336918beac33b2027f9a252e
4
- data.tar.gz: 6ecb5b243fa30f127992fdc1dda6c5b60e69612c2b2bfc0138f3dfb38856e05d
3
+ metadata.gz: d150e442727e74f41f77d8683053124770d6f5aff55962d6a7a50ae27cfae5ab
4
+ data.tar.gz: 79b440a0f074cb4a30802a4f7b92473b49aa90bc94a1abe530b04395f86fdd0a
5
5
  SHA512:
6
- metadata.gz: 6f92d37c3b8aed5323318cb4a1977d23783576e9e0c2a4add3a3dbf56c47f26777b261a8f9b2a8c260c7a5ece1b2ed4a80d99f7eb03d3d2c6d1a423096b6480b
7
- data.tar.gz: 2bf80f3b75c092791b1673823d877b1ce8bb49e118550a7da9931a2dea1b8419c4912b122516c0b95292065566bc3c5fd035702e0ca4a864faa6ab93e59f6365
6
+ metadata.gz: b992aa3b4b3a6d24f6008d165235358cdc2141e9f1fd710d8d76a03064ec553c948d38d7cfa76d22b31ffd740a4696cd85fd411514123fa4157fbf7f1d4c41cf
7
+ data.tar.gz: ac715cfaac81c870b7898e5025253773bb7e8e51ceab96b35d50d2d3e43d0c2155297809907c18e0939a39aa9cd6c928b7901665b57b165002dc1f3bc375783f
data/ChangeLog.md CHANGED
@@ -1,6 +1,42 @@
1
- ## Changes Between 1.15.0 and 1.16.0 (unreleased)
1
+ ## Changes Between 1.15.0 and 2.0.0 (May 21, 2021)
2
2
 
3
- No changes yet.
3
+ ### Health Check Endpoint Changes
4
+
5
+ `RabbitMQ::HTTP::Client#aliveness_test` has been removed. The endpoint has been deprecated
6
+ in favor of [more focussed health check endpoints](https://www.rabbitmq.com/monitoring.html#health-checks):
7
+
8
+ ``` ruby
9
+ c = RabbitMQ::HTTP::Client.new("http://username:s3kRe7@localhost:15672")
10
+
11
+ # Returns a pair of [success, details]. Details will be nil
12
+ # if the check succeeds.
13
+ #
14
+ # Checks for any alarms across the cluster
15
+ passed, details = c.health.check_alarms
16
+
17
+ # alarms on the given node
18
+ passed, details = c.health.check_local_alarms
19
+
20
+ # is this node essential for an online quorum of any quorum queues?
21
+ passed, details = c.health.check_if_node_is_quorum_critical
22
+
23
+ # do any certificates used by this node's TLS listeners expire within
24
+ # three months?
25
+ passed, details = c.health.check_certificate_expiration(3, "months")
26
+ ```
27
+
28
+ See the list of methods in `RabbitMQ::HTTP::HealthChecks` to find out what other
29
+ health checks are available.
30
+
31
+ ### User Tags Type Change
32
+
33
+ User tags returned by the `RabbitMQ::HTTP::Client#list_users` and `RabbitMQ::HTTP::Client#user_info`
34
+ methods are now arrays of strings instead of comma-separated strings.
35
+
36
+ Internally the method encodes both command-separated strings and JSON arrays in API responses
37
+ to support response types from RabbitMQ 3.9 and earlier versions.
38
+
39
+ See https://github.com/rabbitmq/rabbitmq-server/pull/2676 for details.
4
40
 
5
41
  ## Changes Between 1.14.0 and 1.15.0 (February 16th, 2021)
6
42
  ### Content Length Detection Changes
data/README.md CHANGED
@@ -32,7 +32,7 @@ All versions require [RabbitMQ Management UI plugin](http://www.rabbitmq.com/man
32
32
  Add this line to your application's Gemfile:
33
33
 
34
34
  ``` ruby
35
- gem 'rabbitmq_http_api_client', '>= 1.13.0'
35
+ gem 'rabbitmq_http_api_client', '>= 1.15.0'
36
36
  ```
37
37
 
38
38
  And then execute:
@@ -5,6 +5,10 @@ require "faraday_middleware"
5
5
  require "multi_json"
6
6
  require "uri"
7
7
 
8
+ require_relative "client/request_helper"
9
+ require_relative "client/response_helper"
10
+ require_relative "client/health_checks"
11
+
8
12
  module RabbitMQ
9
13
  module HTTP
10
14
  class Client
@@ -13,7 +17,8 @@ module RabbitMQ
13
17
  # API
14
18
  #
15
19
 
16
- attr_reader :endpoint
20
+ attr_reader :endpoint, :health
21
+ attr_reader :connection, :request_helper, :response_helper
17
22
 
18
23
  def self.connect(endpoint, options = {})
19
24
  new(endpoint, options)
@@ -23,6 +28,10 @@ module RabbitMQ
23
28
  @endpoint = endpoint
24
29
  @options = options
25
30
 
31
+ @request_helper = RequestHelper.new()
32
+ @response_helper = ResponseHelper.new(self)
33
+ @health = HealthChecks.new(self)
34
+
26
35
  initialize_connection(endpoint, options)
27
36
  end
28
37
 
@@ -114,10 +123,10 @@ module RabbitMQ
114
123
 
115
124
  def declare_exchange(vhost, name, attributes = {})
116
125
  opts = {
117
- :type => "direct",
118
- :auto_delete => false,
119
- :durable => true,
120
- :arguments => {}
126
+ type: "direct",
127
+ auto_delete: false,
128
+ durable: true,
129
+ arguments: {}
121
130
  }.merge(attributes)
122
131
 
123
132
  response = @connection.put("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
@@ -293,11 +302,22 @@ module RabbitMQ
293
302
 
294
303
 
295
304
  def list_users(query = {})
296
- decode_resource_collection(@connection.get("users", query))
305
+ results = decode_resource_collection(@connection.get("users", query))
306
+
307
+ # HTTP API will return tags as an array starting with RabbitMQ 3.9
308
+ results.map do |u|
309
+ u.tags = u.tags.split(",") if u.tags.is_a?(String)
310
+ u
311
+ end
297
312
  end
298
313
 
299
314
  def user_info(name)
300
- decode_resource(@connection.get("users/#{encode_uri_path_segment(name)}"))
315
+ result = decode_resource(@connection.get("users/#{encode_uri_path_segment(name)}"))
316
+
317
+ # HTTP API will return tags as an array starting with RabbitMQ 3.9
318
+ result.tags = result.tags.split(",") if result.tags.is_a?(String)
319
+
320
+ result
301
321
  end
302
322
 
303
323
  def update_user(name, attributes)
@@ -389,14 +409,6 @@ module RabbitMQ
389
409
  decode_resource(@connection.delete("parameters/#{encode_uri_path_segment(component)}/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
390
410
  end
391
411
 
392
-
393
-
394
- def aliveness_test(vhost)
395
- r = @connection.get("aliveness-test/#{encode_uri_path_segment(vhost)}")
396
- r.body["status"] == "ok"
397
- end
398
-
399
-
400
412
  protected
401
413
 
402
414
  def initialize_connection(endpoint, options = {})
@@ -418,25 +430,19 @@ module RabbitMQ
418
430
  end
419
431
 
420
432
  def encode_uri_path_segment(segment)
421
- # Correctly escapes spaces, see ruby-amqp/rabbitmq_http_api_client#28.
422
- #
423
- # Note that slashes also must be escaped since this is a single URI path segment,
424
- # not an entire path.
425
- Addressable::URI.encode_component(segment, Addressable::URI::CharacterClasses::UNRESERVED)
433
+ @request_helper.encode_uri_path_segment(segment)
426
434
  end
427
435
 
428
436
  def decode_resource(response)
429
- if response.body.empty?
430
- Hashie::Mash.new
431
- else
432
- Hashie::Mash.new(response.body)
433
- end
437
+ @response_helper.decode_resource(response)
434
438
  end
435
439
 
436
- def decode_resource_collection(response)
437
- collection = response.body.is_a?(Array) ? response.body : response.body.fetch('items')
440
+ def decode_response_body(body)
441
+ @response_helper.decode_response_body(body)
442
+ end
438
443
 
439
- collection.map { |i| Hashie::Mash.new(i) }
444
+ def decode_resource_collection(response)
445
+ @response_helper.decode_resource_collection(response)
440
446
  end
441
447
  end # Client
442
448
  end # HTTP
@@ -0,0 +1,70 @@
1
+ require "hashie"
2
+ require "faraday"
3
+ require "faraday_middleware"
4
+ require "multi_json"
5
+ require "uri"
6
+
7
+ module RabbitMQ
8
+ module HTTP
9
+ class HealthChecks
10
+
11
+ def initialize(client)
12
+ @client = client
13
+ @request_helper = @client.request_helper
14
+ @response_helper = @client.response_helper
15
+ end
16
+
17
+ def check_alarms
18
+ health_check_for("health/checks/alarms")
19
+ end
20
+
21
+ def check_local_alarms
22
+ health_check_for("health/checks/local-alarms")
23
+ end
24
+
25
+ def check_virtual_hosts
26
+ health_check_for("health/checks/virtual-hosts")
27
+ end
28
+
29
+ def check_if_node_is_quorum_critical
30
+ health_check_for("health/checks/node-is-quorum-critical")
31
+ end
32
+
33
+ def check_if_node_is_mirror_sync_critical
34
+ health_check_for("health/checks/node-is-mirror-sync-critical")
35
+ end
36
+
37
+ def check_port_listener(port)
38
+ health_check_for("health/checks/port-listener/#{encode_uri_path_segment(port)}")
39
+ end
40
+
41
+ def check_protocol_listener(proto)
42
+ health_check_for("health/checks/protocol-listener/#{encode_uri_path_segment(proto)}")
43
+ end
44
+
45
+ TIME_UNITS = %w(days weeks months years)
46
+
47
+ def check_certificate_expiration(within, unit)
48
+ raise ArgumentError.new("supported time units are #{TIME_UNITS.join(', ')}, given: #{unit}") if !TIME_UNITS.include?(unit)
49
+ raise ArgumentError.new("the number of time units must be a positive integer") if within <= 0
50
+
51
+ health_check_for("health/checks/certificate-expiration/#{@request_helper.encode_uri_path_segment(within)}/#{@request_helper.encode_uri_path_segment(unit)}")
52
+ end
53
+
54
+
55
+ def health_check_for(path)
56
+ begin
57
+ _ = @response_helper.decode_resource(@client.connection.get(path))
58
+ [true, nil]
59
+ rescue Faraday::ServerError => se
60
+ # health check endpoints respond with a 503 if the server fails
61
+ if se.response_status == 503
62
+ [false, @response_helper.decode_response_body(se.response[:body])]
63
+ else
64
+ raise se
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,19 @@
1
+ require "hashie"
2
+ require "faraday"
3
+ require "faraday_middleware"
4
+ require "multi_json"
5
+ require "uri"
6
+
7
+ module RabbitMQ
8
+ module HTTP
9
+ class RequestHelper
10
+ def encode_uri_path_segment(segment)
11
+ # Correctly escapes spaces, see ruby-amqp/rabbitmq_http_api_client#28.
12
+ #
13
+ # Note that slashes also must be escaped since this is a single URI path segment,
14
+ # not an entire path.
15
+ Addressable::URI.encode_component(segment, Addressable::URI::CharacterClasses::UNRESERVED)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ require "hashie"
2
+ require "faraday"
3
+ require "faraday_middleware"
4
+ require "multi_json"
5
+ require "uri"
6
+
7
+ module RabbitMQ
8
+ module HTTP
9
+ class ResponseHelper
10
+
11
+ def initialize(client)
12
+ @client = client
13
+ end
14
+
15
+ def decode_resource(response)
16
+ if response.body.empty?
17
+ Hashie::Mash.new
18
+ else
19
+ decode_response_body(response.body)
20
+ end
21
+ end
22
+
23
+ def decode_response_body(body)
24
+ if body.empty?
25
+ Hashie::Mash.new
26
+ else
27
+ Hashie::Mash.new(body)
28
+ end
29
+ end
30
+
31
+ def decode_resource_collection(response)
32
+ collection = response.body.is_a?(Array) ? response.body : response.body.fetch('items')
33
+
34
+ collection.map { |i| Hashie::Mash.new(i) }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,7 +1,7 @@
1
1
  module RabbitMQ
2
2
  module HTTP
3
3
  class Client
4
- VERSION = "1.15.0"
4
+ VERSION = "2.0.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbitmq_http_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klishin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-16 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -91,6 +91,9 @@ files:
91
91
  - LICENSE.txt
92
92
  - README.md
93
93
  - lib/rabbitmq/http/client.rb
94
+ - lib/rabbitmq/http/client/health_checks.rb
95
+ - lib/rabbitmq/http/client/request_helper.rb
96
+ - lib/rabbitmq/http/client/response_helper.rb
94
97
  - lib/rabbitmq/http/client/version.rb
95
98
  homepage: http://github.com/ruby-amqp/rabbitmq_http_api_client
96
99
  licenses:
@@ -112,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  - !ruby/object:Gem::Version
113
116
  version: '0'
114
117
  requirements: []
115
- rubygems_version: 3.1.2
118
+ rubygems_version: 3.1.4
116
119
  signing_key:
117
120
  specification_version: 4
118
121
  summary: RabbitMQ HTTP API client for Ruby