rabbitmq_http_api_client 1.11.0 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c83f7c4baf8046804a62452446fff5289d5cdae70746871cf50171deb29957a1
4
- data.tar.gz: 82ac2db12a2616e67236d3eca0b20049c2d63d91cd23334ff38fcb2f747d8c49
3
+ metadata.gz: d150e442727e74f41f77d8683053124770d6f5aff55962d6a7a50ae27cfae5ab
4
+ data.tar.gz: 79b440a0f074cb4a30802a4f7b92473b49aa90bc94a1abe530b04395f86fdd0a
5
5
  SHA512:
6
- metadata.gz: 2f0a7c2bcb0d5c2bab65b689e7e92cbecb7e1778bae5e180203bfc1ba52fae84b40735a4f6484cc21755afd7a7f4ce900578191ee8d63cc170408a33f9b72077
7
- data.tar.gz: f4e0bd98a8ab387352f0d691274d77f2e9c225c4b9276503a8fe736cda62cf15d860a5422258d8ca101ab82361881e0bdf3e99918a99560450e52261022efed7
6
+ metadata.gz: b992aa3b4b3a6d24f6008d165235358cdc2141e9f1fd710d8d76a03064ec553c948d38d7cfa76d22b31ffd740a4696cd85fd411514123fa4157fbf7f1d4c41cf
7
+ data.tar.gz: ac715cfaac81c870b7898e5025253773bb7e8e51ceab96b35d50d2d3e43d0c2155297809907c18e0939a39aa9cd6c928b7901665b57b165002dc1f3bc375783f
data/ChangeLog.md CHANGED
@@ -1,6 +1,90 @@
1
- ## Changes Between 1.11.0 and 1.12.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.
40
+
41
+ ## Changes Between 1.14.0 and 1.15.0 (February 16th, 2021)
42
+ ### Content Length Detection Changes
43
+
44
+ When deserialising response bodies, the client now uses actual body length instead of
45
+ the value of the `content-length` header.
46
+
47
+ Contributed by Ryan @rquant Quant.
48
+
49
+ GitHub issue: [#49](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/49)
50
+
51
+ ## Changes Between 1.13.0 and 1.14.0 (July 8th, 2020)
52
+
53
+ ### URI.escape is No Longer Used
54
+
55
+ Deprecated `URI.escape` has been replaced with `Addressable::URI.escape_component`.
56
+ This introduces `addressable` as a new dependency.
57
+
58
+ ### Dependency Bump
59
+
60
+ Note: Faraday will now raise a `Faraday::ResourceNotFound` instead of `Faraday::Error::ResourceNotFound`.
61
+
62
+ GitHub issue: [#45](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/45)
63
+
64
+ Contributed by Niels Jansen.
65
+
66
+ ## Changes Between 1.12.0 and 1.13.0 (March 5th, 2020)
67
+
68
+ ### Pagination Support
69
+
70
+ GitHub issue: [#43](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/43)
71
+
72
+ Contributed by Rustam Sharshenov.
73
+
74
+ ### Dependency Updates
75
+
76
+ GitHub issue: [#42](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/42)
77
+
78
+ Contributed by @hatch-carl.
79
+
80
+
81
+ ## Changes Between 1.11.0 and 1.12.0 (March 12th, 2019)
82
+
83
+ ### Dependency Updates
84
+
85
+ GitHub issue: [#38](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/38)
86
+
87
+ Contributed by Jon Homan.
4
88
 
5
89
 
6
90
  ## Changes Between 1.10.0 and 1.11.0 (Dec 25th, 2018)
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2017 Michael Klishin
1
+ Copyright (c) 2012-2020 Michael Klishin
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -18,9 +18,9 @@ and will support more HTTP API features in the future
18
18
 
19
19
  ## Supported Ruby Versions
20
20
 
21
- * CRuby 2.0 through 2.4.x
21
+ * CRuby 2.2 through 2.7.x
22
22
  * JRuby 9K
23
-
23
+
24
24
  ## Supported RabbitMQ Versions
25
25
 
26
26
  * RabbitMQ 3.x
@@ -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.9.1'
35
+ gem 'rabbitmq_http_api_client', '>= 1.15.0'
36
36
  ```
37
37
 
38
38
  And then execute:
@@ -59,7 +59,7 @@ Use `RabbitMQ::HTTP::Client#connect` to specify RabbitMQ HTTP API endpoint (e.g.
59
59
  require "rabbitmq/http/client"
60
60
 
61
61
  endpoint = "http://127.0.0.1:15672"
62
- client = RabbitMQ::HTTP::Client.new(endpoint, :username => "guest", :password => "guest")
62
+ client = RabbitMQ::HTTP::Client.new(endpoint, username: "guest", password: "guest")
63
63
  ```
64
64
 
65
65
  Alternatively, credentials can be specified in the endpoint URI:
@@ -127,7 +127,7 @@ puts n.proc_used
127
127
  puts n.fd_total
128
128
 
129
129
  # Get Management Plugin extension list
130
- xs = client.list_extensions
130
+ xs = client.list_extensions
131
131
 
132
132
  # List all the entities (vhosts, queues, exchanges, bindings, users, etc)
133
133
  defs = client.list_definitions
@@ -259,7 +259,7 @@ puts b.vhost
259
259
  # List all bindings in a vhost
260
260
  bs = client.list_bindings("/")
261
261
 
262
- # List all binsings between an exchange and a queue
262
+ # List all bindings between an exchange and a queue
263
263
  bs = client.list_bindings_between_queue_and_exchange("/", "collector1.megacorp.local", "log.events")
264
264
  ```
265
265
 
@@ -371,5 +371,4 @@ and rabbitmq-management plugin enabled.
371
371
 
372
372
  Double-licensed under the MIT and Mozilla Public License (same as RabbitMQ).
373
373
 
374
- (c) Michael S. Klishin, 2012-2017.
375
-
374
+ (c) Michael S. Klishin, 2012-2020.
@@ -1,9 +1,14 @@
1
+ require "addressable/uri"
1
2
  require "hashie"
2
3
  require "faraday"
3
4
  require "faraday_middleware"
4
5
  require "multi_json"
5
6
  require "uri"
6
7
 
8
+ require_relative "client/request_helper"
9
+ require_relative "client/response_helper"
10
+ require_relative "client/health_checks"
11
+
7
12
  module RabbitMQ
8
13
  module HTTP
9
14
  class Client
@@ -12,7 +17,8 @@ module RabbitMQ
12
17
  # API
13
18
  #
14
19
 
15
- attr_reader :endpoint
20
+ attr_reader :endpoint, :health
21
+ attr_reader :connection, :request_helper, :response_helper
16
22
 
17
23
  def self.connect(endpoint, options = {})
18
24
  new(endpoint, options)
@@ -22,6 +28,10 @@ module RabbitMQ
22
28
  @endpoint = endpoint
23
29
  @options = options
24
30
 
31
+ @request_helper = RequestHelper.new()
32
+ @response_helper = ResponseHelper.new(self)
33
+ @health = HealthChecks.new(self)
34
+
25
35
  initialize_connection(endpoint, options)
26
36
  end
27
37
 
@@ -57,16 +67,16 @@ module RabbitMQ
57
67
  reduce(Hash.new) { |acc, lnr| acc[lnr.protocol] = lnr.port; acc }
58
68
  end
59
69
 
60
- def list_nodes
61
- decode_resource_collection(@connection.get("nodes"))
70
+ def list_nodes(query = {})
71
+ decode_resource_collection(@connection.get("nodes", query))
62
72
  end
63
73
 
64
74
  def node_info(name)
65
- decode_resource(@connection.get("nodes/#{uri_encode(name)}"))
75
+ decode_resource(@connection.get("nodes/#{encode_uri_path_segment(name)}"))
66
76
  end
67
77
 
68
- def list_extensions
69
- decode_resource_collection(@connection.get("extensions"))
78
+ def list_extensions(query = {})
79
+ decode_resource_collection(@connection.get("extensions", query))
70
80
  end
71
81
 
72
82
  def list_definitions
@@ -81,45 +91,45 @@ module RabbitMQ
81
91
  response.success?
82
92
  end
83
93
 
84
- def list_connections
85
- decode_resource_collection(@connection.get("connections"))
94
+ def list_connections(query = {})
95
+ decode_resource_collection(@connection.get("connections", query))
86
96
  end
87
97
 
88
98
  def connection_info(name)
89
- decode_resource(@connection.get("connections/#{uri_encode(name)}"))
99
+ decode_resource(@connection.get("connections/#{encode_uri_path_segment(name)}"))
90
100
  end
91
101
 
92
102
  def close_connection(name)
93
- decode_resource(@connection.delete("connections/#{uri_encode(name)}"))
103
+ decode_resource(@connection.delete("connections/#{encode_uri_path_segment(name)}"))
94
104
  end
95
105
 
96
- def list_channels
97
- decode_resource_collection(@connection.get("channels"))
106
+ def list_channels(query = {})
107
+ decode_resource_collection(@connection.get("channels", query))
98
108
  end
99
109
 
100
110
  def channel_info(name)
101
- decode_resource(@connection.get("channels/#{uri_encode(name)}"))
111
+ decode_resource(@connection.get("channels/#{encode_uri_path_segment(name)}"))
102
112
  end
103
113
 
104
- def list_exchanges(vhost = nil)
114
+ def list_exchanges(vhost = nil, query = {})
105
115
  path = if vhost.nil?
106
116
  "exchanges"
107
117
  else
108
- "exchanges/#{uri_encode(vhost)}"
118
+ "exchanges/#{encode_uri_path_segment(vhost)}"
109
119
  end
110
120
 
111
- decode_resource_collection(@connection.get(path))
121
+ decode_resource_collection(@connection.get(path, query))
112
122
  end
113
123
 
114
124
  def declare_exchange(vhost, name, attributes = {})
115
125
  opts = {
116
- :type => "direct",
117
- :auto_delete => false,
118
- :durable => true,
119
- :arguments => {}
126
+ type: "direct",
127
+ auto_delete: false,
128
+ durable: true,
129
+ arguments: {}
120
130
  }.merge(attributes)
121
131
 
122
- response = @connection.put("exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
132
+ response = @connection.put("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
123
133
  req.headers['Content-Type'] = 'application/json'
124
134
  req.body = MultiJson.dump(opts)
125
135
  end
@@ -127,40 +137,40 @@ module RabbitMQ
127
137
  end
128
138
 
129
139
  def delete_exchange(vhost, name, if_unused = false)
130
- response = @connection.delete("exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
140
+ response = @connection.delete("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
131
141
  req.params["if-unused"] = true if if_unused
132
142
  end
133
143
  decode_resource(response)
134
144
  end
135
145
 
136
146
  def exchange_info(vhost, name)
137
- decode_resource(@connection.get("exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}"))
147
+ decode_resource(@connection.get("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
138
148
  end
139
149
 
140
- def list_bindings_by_source(vhost, exchange)
141
- decode_resource_collection(@connection.get("exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/source"))
150
+ def list_bindings_by_source(vhost, exchange, query = {})
151
+ decode_resource_collection(@connection.get("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(exchange)}/bindings/source", query))
142
152
  end
143
153
 
144
- def list_bindings_by_destination(vhost, exchange)
145
- decode_resource_collection(@connection.get("exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/destination"))
154
+ def list_bindings_by_destination(vhost, exchange, query = {})
155
+ decode_resource_collection(@connection.get("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(exchange)}/bindings/destination", query))
146
156
  end
147
157
 
148
- def list_queues(vhost = nil)
158
+ def list_queues(vhost = nil, query = {})
149
159
  path = if vhost.nil?
150
160
  "queues"
151
161
  else
152
- "queues/#{uri_encode(vhost)}"
162
+ "queues/#{encode_uri_path_segment(vhost)}"
153
163
  end
154
164
 
155
- decode_resource_collection(@connection.get(path))
165
+ decode_resource_collection(@connection.get(path, query))
156
166
  end
157
167
 
158
168
  def queue_info(vhost, name)
159
- decode_resource(@connection.get("queues/#{uri_encode(vhost)}/#{uri_encode(name)}"))
169
+ decode_resource(@connection.get("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
160
170
  end
161
171
 
162
172
  def declare_queue(vhost, name, attributes)
163
- response = @connection.put("queues/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
173
+ response = @connection.put("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
164
174
  req.headers['Content-Type'] = "application/json"
165
175
  req.body = MultiJson.dump(attributes)
166
176
  end
@@ -168,46 +178,46 @@ module RabbitMQ
168
178
  end
169
179
 
170
180
  def delete_queue(vhost, name)
171
- decode_resource(@connection.delete("queues/#{uri_encode(vhost)}/#{uri_encode(name)}"))
181
+ decode_resource(@connection.delete("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
172
182
  end
173
183
 
174
- def list_queue_bindings(vhost, queue)
175
- decode_resource_collection(@connection.get("queues/#{uri_encode(vhost)}/#{uri_encode(queue)}/bindings"))
184
+ def list_queue_bindings(vhost, queue, query = {})
185
+ decode_resource_collection(@connection.get("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(queue)}/bindings", query))
176
186
  end
177
187
 
178
188
  def purge_queue(vhost, name)
179
- @connection.delete("queues/#{uri_encode(vhost)}/#{uri_encode(name)}/contents")
189
+ @connection.delete("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}/contents")
180
190
  Hashie::Mash.new
181
191
  end
182
192
 
183
193
  def get_messages(vhost, name, options)
184
- response = @connection.post("queues/#{uri_encode(vhost)}/#{uri_encode(name)}/get") do |req|
194
+ response = @connection.post("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}/get") do |req|
185
195
  req.headers['Content-Type'] = "application/json"
186
196
  req.body = MultiJson.dump(options)
187
197
  end
188
198
  decode_resource_collection(response)
189
199
  end
190
200
 
191
- def list_bindings(vhost = nil)
201
+ def list_bindings(vhost = nil, query = {})
192
202
  path = if vhost.nil?
193
203
  "bindings"
194
204
  else
195
- "bindings/#{uri_encode(vhost)}"
205
+ "bindings/#{encode_uri_path_segment(vhost)}"
196
206
  end
197
207
 
198
- decode_resource_collection(@connection.get(path))
208
+ decode_resource_collection(@connection.get(path, query))
199
209
  end
200
210
 
201
- def list_bindings_between_queue_and_exchange(vhost, queue, exchange)
202
- decode_resource_collection(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}"))
211
+ def list_bindings_between_queue_and_exchange(vhost, queue, exchange, query = {})
212
+ decode_resource_collection(@connection.get("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(exchange)}/q/#{encode_uri_path_segment(queue)}", query))
203
213
  end
204
214
 
205
215
  def queue_binding_info(vhost, queue, exchange, properties_key)
206
- decode_resource(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}/#{uri_encode(properties_key)}"))
216
+ decode_resource(@connection.get("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(exchange)}/q/#{encode_uri_path_segment(queue)}/#{encode_uri_path_segment(properties_key)}"))
207
217
  end
208
218
 
209
219
  def bind_queue(vhost, queue, exchange, routing_key, arguments = [])
210
- resp = @connection.post("bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}") do |req|
220
+ resp = @connection.post("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(exchange)}/q/#{encode_uri_path_segment(queue)}") do |req|
211
221
  req.headers['Content-Type'] = 'application/json'
212
222
  req.body = MultiJson.dump({:routing_key => routing_key, :arguments => arguments})
213
223
  end
@@ -215,21 +225,21 @@ module RabbitMQ
215
225
  end
216
226
 
217
227
  def delete_queue_binding(vhost, queue, exchange, properties_key)
218
- resp = @connection.delete("bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}/#{uri_encode(properties_key)}")
228
+ resp = @connection.delete("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(exchange)}/q/#{encode_uri_path_segment(queue)}/#{encode_uri_path_segment(properties_key)}")
219
229
  resp.success?
220
230
  end
221
231
 
222
- def list_bindings_between_exchanges(vhost, destination_exchange, source_exchange)
223
- decode_resource_collection(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}"))
232
+ def list_bindings_between_exchanges(vhost, destination_exchange, source_exchange, query = {})
233
+ decode_resource_collection(@connection.get("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(source_exchange)}/e/#{encode_uri_path_segment(destination_exchange)}", query))
224
234
  end
225
235
 
226
236
  def exchange_binding_info(vhost, destination_exchange, source_exchange, properties_key)
227
- decode_resource(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}/#{uri_encode(properties_key)}"))
237
+ decode_resource(@connection.get("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(source_exchange)}/e/#{encode_uri_path_segment(destination_exchange)}/#{encode_uri_path_segment(properties_key)}"))
228
238
  end
229
239
 
230
240
 
231
241
  def bind_exchange(vhost, destination_exchange, source_exchange, routing_key, arguments = [])
232
- resp = @connection.post("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}") do |req|
242
+ resp = @connection.post("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(source_exchange)}/e/#{encode_uri_path_segment(destination_exchange)}") do |req|
233
243
  req.headers['Content-Type'] = 'application/json'
234
244
  req.body = MultiJson.dump({:routing_key => routing_key, :arguments => arguments})
235
245
  end
@@ -237,48 +247,48 @@ module RabbitMQ
237
247
  end
238
248
 
239
249
  def delete_exchange_binding(vhost, destination_exchange, source_exchange, properties_key)
240
- resp = @connection.delete("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}/#{uri_encode(properties_key)}")
250
+ resp = @connection.delete("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(source_exchange)}/e/#{encode_uri_path_segment(destination_exchange)}/#{encode_uri_path_segment(properties_key)}")
241
251
  resp.success?
242
252
  end
243
253
 
244
254
 
245
- def list_vhosts
246
- decode_resource_collection(@connection.get("vhosts"))
255
+ def list_vhosts(query = {})
256
+ decode_resource_collection(@connection.get("vhosts", query))
247
257
  end
248
258
 
249
259
  def vhost_info(name)
250
- decode_resource(@connection.get("vhosts/#{uri_encode(name)}"))
260
+ decode_resource(@connection.get("vhosts/#{encode_uri_path_segment(name)}"))
251
261
  end
252
262
 
253
263
  def create_vhost(name)
254
- response = @connection.put("vhosts/#{uri_encode(name)}") do |req|
264
+ response = @connection.put("vhosts/#{encode_uri_path_segment(name)}") do |req|
255
265
  req.headers['Content-Type'] = "application/json"
256
266
  end
257
267
  decode_resource(response)
258
268
  end
259
269
 
260
270
  def delete_vhost(name)
261
- decode_resource(@connection.delete("vhosts/#{uri_encode(name)}"))
271
+ decode_resource(@connection.delete("vhosts/#{encode_uri_path_segment(name)}"))
262
272
  end
263
273
 
264
274
 
265
275
 
266
- def list_permissions(vhost = nil)
276
+ def list_permissions(vhost = nil, query = {})
267
277
  path = if vhost
268
- "vhosts/#{uri_encode(vhost)}/permissions"
278
+ "vhosts/#{encode_uri_path_segment(vhost)}/permissions"
269
279
  else
270
280
  "permissions"
271
281
  end
272
282
 
273
- decode_resource_collection(@connection.get(path))
283
+ decode_resource_collection(@connection.get(path, query))
274
284
  end
275
285
 
276
286
  def list_permissions_of(vhost, user)
277
- decode_resource(@connection.get("permissions/#{uri_encode(vhost)}/#{uri_encode(user)}"))
287
+ decode_resource(@connection.get("permissions/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(user)}"))
278
288
  end
279
289
 
280
290
  def update_permissions_of(vhost, user, attributes)
281
- response = @connection.put("permissions/#{uri_encode(vhost)}/#{uri_encode(user)}") do |req|
291
+ response = @connection.put("permissions/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(user)}") do |req|
282
292
  req.headers['Content-Type'] = "application/json"
283
293
  req.body = MultiJson.dump(attributes)
284
294
  end
@@ -286,23 +296,34 @@ module RabbitMQ
286
296
  end
287
297
 
288
298
  def clear_permissions_of(vhost, user)
289
- decode_resource(@connection.delete("permissions/#{uri_encode(vhost)}/#{uri_encode(user)}"))
299
+ decode_resource(@connection.delete("permissions/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(user)}"))
290
300
  end
291
301
 
292
302
 
293
303
 
294
- def list_users
295
- decode_resource_collection(@connection.get("users"))
304
+ def list_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
296
312
  end
297
313
 
298
314
  def user_info(name)
299
- decode_resource(@connection.get("users/#{uri_encode(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
300
321
  end
301
322
 
302
323
  def update_user(name, attributes)
303
324
  attributes[:tags] ||= ""
304
325
 
305
- response = @connection.put("users/#{uri_encode(name)}") do |req|
326
+ response = @connection.put("users/#{encode_uri_path_segment(name)}") do |req|
306
327
  req.headers['Content-Type'] = "application/json"
307
328
  req.body = MultiJson.dump(attributes)
308
329
  end
@@ -311,11 +332,11 @@ module RabbitMQ
311
332
  alias create_user update_user
312
333
 
313
334
  def delete_user(name)
314
- decode_resource(@connection.delete("users/#{uri_encode(name)}"))
335
+ decode_resource(@connection.delete("users/#{encode_uri_path_segment(name)}"))
315
336
  end
316
337
 
317
- def user_permissions(name)
318
- decode_resource_collection(@connection.get("users/#{uri_encode(name)}/permissions"))
338
+ def user_permissions(name, query = {})
339
+ decode_resource_collection(@connection.get("users/#{encode_uri_path_segment(name)}/permissions", query))
319
340
  end
320
341
 
321
342
  def whoami
@@ -324,27 +345,27 @@ module RabbitMQ
324
345
 
325
346
 
326
347
 
327
- def list_policies(vhost = nil)
348
+ def list_policies(vhost = nil, query = {})
328
349
  path = if vhost
329
- "policies/#{uri_encode(vhost)}"
350
+ "policies/#{encode_uri_path_segment(vhost)}"
330
351
  else
331
352
  "policies"
332
353
  end
333
354
 
334
- decode_resource_collection(@connection.get(path))
355
+ decode_resource_collection(@connection.get(path, query))
335
356
  end
336
357
 
337
- def list_policies_of(vhost, name = nil)
358
+ def list_policies_of(vhost, name = nil, query = {})
338
359
  path = if name
339
- "policies/#{uri_encode(vhost)}/#{uri_encode(name)}"
360
+ "policies/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"
340
361
  else
341
- "policies/#{uri_encode(vhost)}"
362
+ "policies/#{encode_uri_path_segment(vhost)}"
342
363
  end
343
- decode_resource_collection(@connection.get(path))
364
+ decode_resource_collection(@connection.get(path, query))
344
365
  end
345
366
 
346
367
  def update_policies_of(vhost, name, attributes)
347
- response = @connection.put("policies/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
368
+ response = @connection.put("policies/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
348
369
  req.headers['Content-Type'] = "application/json"
349
370
  req.body = MultiJson.dump(attributes)
350
371
  end
@@ -352,32 +373,32 @@ module RabbitMQ
352
373
  end
353
374
 
354
375
  def clear_policies_of(vhost, name)
355
- decode_resource(@connection.delete("policies/#{uri_encode(vhost)}/#{uri_encode(name)}"))
376
+ decode_resource(@connection.delete("policies/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
356
377
  end
357
378
 
358
379
 
359
380
 
360
381
 
361
- def list_parameters(component = nil)
382
+ def list_parameters(component = nil, query = {})
362
383
  path = if component
363
- "parameters/#{uri_encode(component)}"
384
+ "parameters/#{encode_uri_path_segment(component)}"
364
385
  else
365
386
  "parameters"
366
387
  end
367
- decode_resource_collection(@connection.get(path))
388
+ decode_resource_collection(@connection.get(path, query))
368
389
  end
369
390
 
370
- def list_parameters_of(component, vhost, name = nil)
391
+ def list_parameters_of(component, vhost, name = nil, query = {})
371
392
  path = if name
372
- "parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}"
393
+ "parameters/#{encode_uri_path_segment(component)}/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"
373
394
  else
374
- "parameters/#{uri_encode(component)}/#{uri_encode(vhost)}"
395
+ "parameters/#{encode_uri_path_segment(component)}/#{encode_uri_path_segment(vhost)}"
375
396
  end
376
- decode_resource_collection(@connection.get(path))
397
+ decode_resource_collection(@connection.get(path, query))
377
398
  end
378
399
 
379
400
  def update_parameters_of(component, vhost, name, attributes)
380
- response = @connection.put("parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
401
+ response = @connection.put("parameters/#{encode_uri_path_segment(component)}/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
381
402
  req.headers['Content-Type'] = "application/json"
382
403
  req.body = MultiJson.dump(attributes)
383
404
  end
@@ -385,17 +406,9 @@ module RabbitMQ
385
406
  end
386
407
 
387
408
  def clear_parameters_of(component, vhost, name)
388
- decode_resource(@connection.delete("parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}"))
389
- end
390
-
391
-
392
-
393
- def aliveness_test(vhost)
394
- r = @connection.get("aliveness-test/#{uri_encode(vhost)}")
395
- r.body["status"] == "ok"
409
+ decode_resource(@connection.delete("parameters/#{encode_uri_path_segment(component)}/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
396
410
  end
397
411
 
398
-
399
412
  protected
400
413
 
401
414
  def initialize_connection(endpoint, options = {})
@@ -416,27 +429,20 @@ module RabbitMQ
416
429
  end
417
430
  end
418
431
 
419
- def uri_encode(s)
420
- # correctly escapes spaces, unlike CGI.escape, see ruby-amqp/rabbitmq_http_api_client#28
421
- URI.escape(s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
432
+ def encode_uri_path_segment(segment)
433
+ @request_helper.encode_uri_path_segment(segment)
422
434
  end
423
435
 
424
436
  def decode_resource(response)
425
- case response.headers["content-length"]
426
- when nil then Hashie::Mash.new
427
- when 0 then Hashie::Mash.new
428
- when "0" then Hashie::Mash.new
429
- else
430
- if response.body.empty?
431
- Hashie::Mash.new
432
- else
433
- Hashie::Mash.new(response.body)
434
- end
435
- end
437
+ @response_helper.decode_resource(response)
438
+ end
439
+
440
+ def decode_response_body(body)
441
+ @response_helper.decode_response_body(body)
436
442
  end
437
443
 
438
444
  def decode_resource_collection(response)
439
- response.body.map { |i| Hashie::Mash.new(i) }
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.11.0"
4
+ VERSION = "2.0.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbitmq_http_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klishin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-25 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: hashie
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '3.5'
33
+ version: '4.1'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '3.5'
40
+ version: '4.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: multi_json
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '1.12'
47
+ version: '1.15'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '1.12'
54
+ version: '1.15'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: faraday
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 0.13.0
61
+ version: '1.3'
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 0.13.0
68
+ version: '1.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: faraday_middleware
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 0.12.0
75
+ version: '1.0'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 0.12.0
82
+ version: '1.0'
69
83
  description: RabbitMQ HTTP API client for Ruby
70
84
  email:
71
85
  - michael@clojurewerkz.org
@@ -77,13 +91,16 @@ files:
77
91
  - LICENSE.txt
78
92
  - README.md
79
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
80
97
  - lib/rabbitmq/http/client/version.rb
81
98
  homepage: http://github.com/ruby-amqp/rabbitmq_http_api_client
82
99
  licenses:
83
100
  - MIT
84
- - Mozilla Public License
101
+ - MPL-2.0
85
102
  metadata: {}
86
- post_install_message:
103
+ post_install_message:
87
104
  rdoc_options: []
88
105
  require_paths:
89
106
  - lib
@@ -98,9 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
115
  - !ruby/object:Gem::Version
99
116
  version: '0'
100
117
  requirements: []
101
- rubyforge_project:
102
- rubygems_version: 2.7.8
103
- signing_key:
118
+ rubygems_version: 3.1.4
119
+ signing_key:
104
120
  specification_version: 4
105
121
  summary: RabbitMQ HTTP API client for Ruby
106
122
  test_files: []