dmexe_rabbitmq_http_api_client 0.3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/ChangeLog.md +19 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +328 -0
- data/Rakefile +1 -0
- data/lib/rabbitmq/http/client.rb +343 -0
- data/lib/rabbitmq/http/client/version.rb +7 -0
- data/rabbitmq_http_client.gemspec +26 -0
- data/spec/integration/client_spec.rb +681 -0
- data/spec/spec_helper.rb +12 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YWMyNWYyYTBiMTI2OTFiYjMzODY1ZmE2Njc5OTBlYTdlM2NmNjMxMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzliMTVmMjViOTU4OGY5Y2IwZmQyYTE3Y2UxYjhlYjk2MmY2ZGEwMw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
N2Y0MTYzZjRhMTg3NGJiNDM2Y2Y3NDNjY2IwNWViOWVhMTZlYzkzNjk1ZTM0
|
10
|
+
ZDJmZmZmMmNiNzc3ZDNjNWY1YzQ1YTFhNThmOGIzMjcyNDU3YTNjMzFiNDIy
|
11
|
+
OGMwYTI4MTlkMmE2NDA1NjAyNzgwYTFjMjNjZDMyNmIwYzM2ZDE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWM1MjM5ZDdiYTQ5MWMzM2FhNTA4Yjc4Y2MyZjEyN2M3ZTMzOThkOTI0ZTY5
|
14
|
+
MDI1ZWY1YjIwODNkMzRlMDNhM2YyZjc4MzJjMWE1NTkyMTcwNmUxODA2M2E3
|
15
|
+
YTQ4MmI3MjA2ZjZkYmRjYTQxY2U1MTM3ZTYxNGQ2NDlkZTkzZGM=
|
data/.gitignore
ADDED
data/ChangeLog.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## Changes Between 0.1.0 and 0.2.0
|
2
|
+
|
3
|
+
### Support for more HTTP API operations
|
4
|
+
|
5
|
+
* Operations on queues
|
6
|
+
* Operations on users
|
7
|
+
* Operations on permissions
|
8
|
+
* Operations on parameters
|
9
|
+
* Operations on policies
|
10
|
+
|
11
|
+
|
12
|
+
## Original Release: 0.1.0
|
13
|
+
|
14
|
+
### Support for many HTTP API operations
|
15
|
+
|
16
|
+
* Status overview
|
17
|
+
* Cluster nodes information
|
18
|
+
* Operations on exchanges, queues, bindings
|
19
|
+
* Operations on connections
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Michael Klishin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,328 @@
|
|
1
|
+
# RabbitMQ HTTP API Client for Ruby
|
2
|
+
|
3
|
+
This gem is a RabbitMQ HTTP API Client for Ruby. It supports
|
4
|
+
|
5
|
+
* Getting cluster overview information
|
6
|
+
* Getting cluster nodes status (# file descriptors used, RAM consumption and so on)
|
7
|
+
* Getting information about exchanges, queues, bindings
|
8
|
+
* Closing client connections
|
9
|
+
* Getting information about vhosts, users, permissions
|
10
|
+
|
11
|
+
and will support more HTTP API features in the future
|
12
|
+
|
13
|
+
* Publishing messages via HTTP
|
14
|
+
* Operations on components/extensions
|
15
|
+
* Operations on federation policies
|
16
|
+
|
17
|
+
## Supported Ruby Versions
|
18
|
+
|
19
|
+
* MRI 1.9.3
|
20
|
+
* JRuby 1.7+
|
21
|
+
* Rubinius 2.0+
|
22
|
+
* MRI 1.9.2
|
23
|
+
* MRI 1.8.7
|
24
|
+
|
25
|
+
## Supported RabbitMQ Versions
|
26
|
+
|
27
|
+
* RabbitMQ 3.x
|
28
|
+
* RabbitMQ 2.x
|
29
|
+
|
30
|
+
All versions require [RabbitMQ Management UI plugin](http://www.rabbitmq.com/management.html) to be installed and enabled.
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
gem 'rabbitmq_http_api_client'
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle
|
41
|
+
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install rabbitmq_http_api_client
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
To require the client:
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
require "rabbitmq/http/client"
|
52
|
+
```
|
53
|
+
|
54
|
+
### Specifying Endpoint and Credentials
|
55
|
+
|
56
|
+
Use `RabbitMQ::HTTP::Client#connect` to specify RabbitMQ HTTP API endpoint (e.g. `http://127.0.0.1:15672`) and credentials:
|
57
|
+
|
58
|
+
``` ruby
|
59
|
+
require "rabbitmq/http/client"
|
60
|
+
|
61
|
+
endpoint = "http://127.0.0.1:55672"
|
62
|
+
client = RabbitMQ::HTTP::Client.new(endpoint, :username => "guest", :password => "guest")
|
63
|
+
```
|
64
|
+
|
65
|
+
### Client API Design Overview
|
66
|
+
|
67
|
+
All client methods return arrays or hash-like structures that can be used
|
68
|
+
like JSON, via `Hash#[]` or regular method access:
|
69
|
+
|
70
|
+
``` ruby
|
71
|
+
r = client.overview
|
72
|
+
|
73
|
+
puts r[:rabbitmq_version]
|
74
|
+
puts r.erlang_version
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
### Node and Cluster Status
|
80
|
+
|
81
|
+
``` ruby
|
82
|
+
# Get cluster information overview
|
83
|
+
h = client.overview
|
84
|
+
|
85
|
+
# List cluster nodes with detailed status info for each one of them
|
86
|
+
nodes = client.list_nodes
|
87
|
+
n = nodes.first
|
88
|
+
puts n.sockets_used
|
89
|
+
puts n.mem_used
|
90
|
+
puts n.run_queue
|
91
|
+
|
92
|
+
# Get detailed status of a node
|
93
|
+
n = client.node_info("rabbit@localhost")
|
94
|
+
puts n.disk_free
|
95
|
+
puts n.proc_used
|
96
|
+
puts n.fd_total
|
97
|
+
|
98
|
+
# Get Management Plugin extension list
|
99
|
+
xs = client.list_extensions
|
100
|
+
|
101
|
+
# List all the entities (vhosts, queues, exchanges, bindings, users, etc)
|
102
|
+
defs = client.list_definitions
|
103
|
+
```
|
104
|
+
|
105
|
+
### Operations on Connections
|
106
|
+
|
107
|
+
``` ruby
|
108
|
+
# List all connections to a node
|
109
|
+
conns = client.list_connections
|
110
|
+
conn = conns.first
|
111
|
+
puts conn.name
|
112
|
+
puts conn.client_properties.product
|
113
|
+
|
114
|
+
# Get a connection information by name
|
115
|
+
conns = client.list_connections
|
116
|
+
conn = client.connection_info(conns.first.name)
|
117
|
+
puts conn.name
|
118
|
+
puts conn.client_properties.product
|
119
|
+
|
120
|
+
# Forcefully close a connection
|
121
|
+
conns = client.list_connections
|
122
|
+
client.close_connection(conns.first.name)
|
123
|
+
```
|
124
|
+
|
125
|
+
### Operations on Channels
|
126
|
+
|
127
|
+
``` ruby
|
128
|
+
# List all channels
|
129
|
+
channs = client.list_channels
|
130
|
+
ch = channs.first
|
131
|
+
puts ch.number
|
132
|
+
puts ch.prefetch_count
|
133
|
+
puts ch.name
|
134
|
+
|
135
|
+
|
136
|
+
# Get a channel information by name
|
137
|
+
conns = client.list_channels
|
138
|
+
conn = client.channel_info(conns.first.name)
|
139
|
+
puts conn.name
|
140
|
+
```
|
141
|
+
|
142
|
+
### Operations on Exchanges
|
143
|
+
|
144
|
+
``` ruby
|
145
|
+
# List all exchanges in the cluster
|
146
|
+
xs = client.list_exchanges
|
147
|
+
x = xs.first
|
148
|
+
|
149
|
+
puts x.type
|
150
|
+
puts x.name
|
151
|
+
puts x.vhost
|
152
|
+
puts x.durable
|
153
|
+
puts x.auto_delete
|
154
|
+
|
155
|
+
# List all exchanges in a vhost
|
156
|
+
xs = client.list_exchanges("myapp.production")
|
157
|
+
x = xs.first
|
158
|
+
|
159
|
+
puts x.type
|
160
|
+
puts x.name
|
161
|
+
puts x.vhost
|
162
|
+
|
163
|
+
# Get information about an exchange in a vhost
|
164
|
+
x = client.exchange_info("/", "log.events")
|
165
|
+
|
166
|
+
puts x.type
|
167
|
+
puts x.name
|
168
|
+
puts x.vhost
|
169
|
+
|
170
|
+
# List all exchanges in a vhost for which an exchange is the source
|
171
|
+
client.list_bindings_by_source("/", "log.events")
|
172
|
+
|
173
|
+
# List all exchanges in a vhost for which an exchange is the destination
|
174
|
+
client.list_bindings_by_destination("/", "command.handlers.email")
|
175
|
+
```
|
176
|
+
|
177
|
+
### Operations on Queues
|
178
|
+
|
179
|
+
``` ruby
|
180
|
+
# List all queues in a node
|
181
|
+
qs = client.list_queues
|
182
|
+
q = qs.first
|
183
|
+
|
184
|
+
puts q.name
|
185
|
+
puts q.auto_delete
|
186
|
+
puts q.durable
|
187
|
+
puts q.backing_queue_status
|
188
|
+
puts q.active_consumers
|
189
|
+
|
190
|
+
|
191
|
+
# Declare a queue
|
192
|
+
client.declare_queue("/", "collector1.megacorp.local", :durable => false, :auto_delete => true)
|
193
|
+
|
194
|
+
# Delete a queue
|
195
|
+
client.delete_queue("/", "collector1.megacorp.local")
|
196
|
+
|
197
|
+
# List bindings for a queue
|
198
|
+
bs = client.list_queue_bindings("/", "collector1.megacorp.local")
|
199
|
+
|
200
|
+
# Purge a queue
|
201
|
+
client.purge_queue("/", "collector1.megacorp.local")
|
202
|
+
|
203
|
+
# Fetch messages from a queue
|
204
|
+
ms = client.get_messages("/", "collector1.megacorp.local", :count => 10, :requeue => false, :encoding => "auto")
|
205
|
+
m = ms.first
|
206
|
+
|
207
|
+
puts m.properties.content_type
|
208
|
+
puts m.payload
|
209
|
+
puts m.payload_encoding
|
210
|
+
```
|
211
|
+
|
212
|
+
### Operations on Bindings
|
213
|
+
|
214
|
+
``` ruby
|
215
|
+
# List all bindings
|
216
|
+
bs = client.list_bindings
|
217
|
+
b = bs.first
|
218
|
+
|
219
|
+
puts b.destination
|
220
|
+
puts b.destination_type
|
221
|
+
puts b.source
|
222
|
+
puts b.routing_key
|
223
|
+
puts b.vhost
|
224
|
+
|
225
|
+
# List all bindings in a vhost
|
226
|
+
bs = client.list_bindings("/")
|
227
|
+
|
228
|
+
# List all binsings between an exchange and a queue
|
229
|
+
bs = client.list_bindings_between_queue_and_exchange("/", "collector1.megacorp.local", "log.events")
|
230
|
+
```
|
231
|
+
|
232
|
+
### Operations on Vhosts
|
233
|
+
|
234
|
+
``` ruby
|
235
|
+
# List all vhosts
|
236
|
+
vs = client.list_vhosts
|
237
|
+
v = vs.first
|
238
|
+
|
239
|
+
puts v.name
|
240
|
+
puts v.tracing
|
241
|
+
|
242
|
+
# Get information about a vhost
|
243
|
+
v = client.vhost_info("/")
|
244
|
+
|
245
|
+
puts v.name
|
246
|
+
puts v.tracing
|
247
|
+
|
248
|
+
# Create a vhost
|
249
|
+
client.create_vhost("myapp.staging")
|
250
|
+
|
251
|
+
# Delete a vhost
|
252
|
+
client.delete_vhost("myapp.staging")
|
253
|
+
```
|
254
|
+
|
255
|
+
### Operations on Users
|
256
|
+
|
257
|
+
``` ruby
|
258
|
+
# List all users
|
259
|
+
us = client.list_users
|
260
|
+
u = us.first
|
261
|
+
|
262
|
+
puts u.name
|
263
|
+
puts u.password_hash
|
264
|
+
puts u.tags
|
265
|
+
|
266
|
+
# Get information about a user
|
267
|
+
u = client.user_info("guest")
|
268
|
+
|
269
|
+
puts u.name
|
270
|
+
puts u.password_hash
|
271
|
+
puts u.tags
|
272
|
+
|
273
|
+
# Update information about a user
|
274
|
+
client.update_user("myapp", :tags => "services", :password => "t0ps3krEt")
|
275
|
+
|
276
|
+
# Delete a user
|
277
|
+
client.delete_user("myapp")
|
278
|
+
```
|
279
|
+
|
280
|
+
### Operations on Permissions
|
281
|
+
|
282
|
+
``` ruby
|
283
|
+
# List all permissions
|
284
|
+
ps = client.list_permissions
|
285
|
+
|
286
|
+
puts p.user
|
287
|
+
puts p.read
|
288
|
+
puts p.write
|
289
|
+
puts p.configure
|
290
|
+
puts p.vhost
|
291
|
+
|
292
|
+
# List all permissions in a vhost
|
293
|
+
ps = client.list_permissions("/")
|
294
|
+
|
295
|
+
puts p.user
|
296
|
+
puts p.read
|
297
|
+
puts p.write
|
298
|
+
puts p.configure
|
299
|
+
puts p.vhost
|
300
|
+
|
301
|
+
# List permissions of a user
|
302
|
+
ps = client.user_permissions("guest")
|
303
|
+
|
304
|
+
# List permissions of a user in a vhost
|
305
|
+
ps = client.list_permissions_of("/", "guest")
|
306
|
+
|
307
|
+
# Update permissions of a user in a vhost
|
308
|
+
ps = client.update_permissions_of("/", "guest", :write => ".*", :read => ".*", :configure => ".*")
|
309
|
+
|
310
|
+
# Clear permissions of a user in a vhost
|
311
|
+
ps = client.clear_permissions_of("/", "guest")
|
312
|
+
```
|
313
|
+
|
314
|
+
|
315
|
+
## Contributing
|
316
|
+
|
317
|
+
1. Fork it
|
318
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
319
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
320
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
321
|
+
5. Create new Pull Request
|
322
|
+
|
323
|
+
|
324
|
+
## License & Copyright
|
325
|
+
|
326
|
+
Double-licensed under the MIT and Mozilla Public License (same as RabbitMQ).
|
327
|
+
|
328
|
+
(c) Michael S. Klishin, 2012-2013.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,343 @@
|
|
1
|
+
require "hashie"
|
2
|
+
require "faraday"
|
3
|
+
require "faraday_middleware"
|
4
|
+
require "multi_json"
|
5
|
+
|
6
|
+
# for URI encoding
|
7
|
+
require "cgi"
|
8
|
+
|
9
|
+
module RabbitMQ
|
10
|
+
module HTTP
|
11
|
+
class Client
|
12
|
+
|
13
|
+
#
|
14
|
+
# API
|
15
|
+
#
|
16
|
+
|
17
|
+
def self.connect(endpoint, options = {})
|
18
|
+
new(endpoint, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(endpoint, options = {})
|
22
|
+
@endpoint = endpoint
|
23
|
+
@options = options
|
24
|
+
|
25
|
+
initialize_connection(endpoint, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def overview
|
29
|
+
decode_resource(@connection.get("/api/overview"))
|
30
|
+
end
|
31
|
+
|
32
|
+
def list_nodes
|
33
|
+
decode_resource_collection(@connection.get("/api/nodes"))
|
34
|
+
end
|
35
|
+
|
36
|
+
def node_info(name)
|
37
|
+
decode_resource(@connection.get("/api/nodes/#{uri_encode(name)}"))
|
38
|
+
end
|
39
|
+
|
40
|
+
def list_extensions
|
41
|
+
decode_resource_collection(@connection.get("/api/extensions"))
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_definitions
|
45
|
+
decode_resource(@connection.get("/api/definitions"))
|
46
|
+
end
|
47
|
+
|
48
|
+
def upload_definitions(defs)
|
49
|
+
raise NotImplementedError.new
|
50
|
+
end
|
51
|
+
|
52
|
+
def list_connections
|
53
|
+
decode_resource_collection(@connection.get("/api/connections"))
|
54
|
+
end
|
55
|
+
|
56
|
+
def connection_info(name)
|
57
|
+
decode_resource(@connection.get("/api/connections/#{uri_encode(name)}"))
|
58
|
+
end
|
59
|
+
|
60
|
+
def close_connection(name)
|
61
|
+
decode_resource(@connection.delete("/api/connections/#{uri_encode(name)}"))
|
62
|
+
end
|
63
|
+
|
64
|
+
def list_channels
|
65
|
+
decode_resource_collection(@connection.get("/api/channels"))
|
66
|
+
end
|
67
|
+
|
68
|
+
def channel_info(name)
|
69
|
+
decode_resource(@connection.get("/api/channels/#{uri_encode(name)}"))
|
70
|
+
end
|
71
|
+
|
72
|
+
def list_exchanges(vhost = nil)
|
73
|
+
path = if vhost.nil?
|
74
|
+
"/api/exchanges"
|
75
|
+
else
|
76
|
+
"/api/exchanges/#{uri_encode(vhost)}"
|
77
|
+
end
|
78
|
+
|
79
|
+
decode_resource_collection(@connection.get(path))
|
80
|
+
end
|
81
|
+
|
82
|
+
def exchange_info(vhost, name)
|
83
|
+
decode_resource(@connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}"))
|
84
|
+
end
|
85
|
+
|
86
|
+
def update_exchange(vhost, name, attributes)
|
87
|
+
response = @connection.put("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
|
88
|
+
req.headers['Content-Type'] = "application/json"
|
89
|
+
req.body = MultiJson.dump(attributes)
|
90
|
+
end
|
91
|
+
decode_resource(response)
|
92
|
+
end
|
93
|
+
|
94
|
+
def delete_exchange(vhost, name)
|
95
|
+
decode_resource(@connection.delete("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}"))
|
96
|
+
end
|
97
|
+
|
98
|
+
def list_bindings_by_source(vhost, exchange)
|
99
|
+
decode_resource_collection(@connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/source"))
|
100
|
+
end
|
101
|
+
|
102
|
+
def list_bindings_by_destination(vhost, exchange)
|
103
|
+
decode_resource_collection(@connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/destination"))
|
104
|
+
end
|
105
|
+
|
106
|
+
def list_queues(vhost = nil)
|
107
|
+
path = if vhost.nil?
|
108
|
+
"/api/queues"
|
109
|
+
else
|
110
|
+
"/api/queues/#{uri_encode(vhost)}"
|
111
|
+
end
|
112
|
+
|
113
|
+
decode_resource_collection(@connection.get(path))
|
114
|
+
end
|
115
|
+
|
116
|
+
def queue_info(vhost, name)
|
117
|
+
decode_resource(@connection.get("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}"))
|
118
|
+
end
|
119
|
+
|
120
|
+
def declare_queue(vhost, name, attributes)
|
121
|
+
response = @connection.put("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
|
122
|
+
req.headers['Content-Type'] = "application/json"
|
123
|
+
req.body = MultiJson.dump(attributes)
|
124
|
+
end
|
125
|
+
decode_resource(response)
|
126
|
+
end
|
127
|
+
|
128
|
+
def delete_queue(vhost, name)
|
129
|
+
decode_resource(@connection.delete("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}"))
|
130
|
+
end
|
131
|
+
|
132
|
+
def list_queue_bindings(vhost, queue)
|
133
|
+
decode_resource_collection(@connection.get("/api/queues/#{uri_encode(vhost)}/#{uri_encode(queue)}/bindings"))
|
134
|
+
end
|
135
|
+
|
136
|
+
def purge_queue(vhost, name)
|
137
|
+
decode_resource(@connection.delete("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}/contents"))
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_messages(vhost, name, options)
|
141
|
+
response = @connection.post("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}/get") do |req|
|
142
|
+
req.headers['Content-Type'] = "application/json"
|
143
|
+
req.body = MultiJson.dump(options)
|
144
|
+
end
|
145
|
+
decode_resource_collection(response)
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
def list_bindings(vhost = nil)
|
150
|
+
path = if vhost.nil?
|
151
|
+
"/api/bindings"
|
152
|
+
else
|
153
|
+
"/api/bindings/#{uri_encode(vhost)}"
|
154
|
+
end
|
155
|
+
|
156
|
+
decode_resource_collection(@connection.get(path))
|
157
|
+
end
|
158
|
+
|
159
|
+
def list_bindings_between_queue_and_exchange(vhost, queue, exchange)
|
160
|
+
decode_resource_collection(@connection.get("/api/bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}"))
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
def list_vhosts
|
167
|
+
decode_resource_collection(@connection.get("/api/vhosts"))
|
168
|
+
end
|
169
|
+
|
170
|
+
def vhost_info(name)
|
171
|
+
decode_resource(@connection.get("/api/vhosts/#{uri_encode(name)}"))
|
172
|
+
end
|
173
|
+
|
174
|
+
def create_vhost(name)
|
175
|
+
response = @connection.put("/api/vhosts/#{uri_encode(name)}") do |req|
|
176
|
+
req.headers['Content-Type'] = "application/json"
|
177
|
+
end
|
178
|
+
decode_resource(response)
|
179
|
+
end
|
180
|
+
|
181
|
+
def delete_vhost(name)
|
182
|
+
decode_resource(@connection.delete("/api/vhosts/#{uri_encode(name)}"))
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
def list_permissions(vhost = nil)
|
188
|
+
path = if vhost
|
189
|
+
"/api/vhosts/#{uri_encode(vhost)}/permissions"
|
190
|
+
else
|
191
|
+
"/api/permissions"
|
192
|
+
end
|
193
|
+
|
194
|
+
decode_resource_collection(@connection.get(path))
|
195
|
+
end
|
196
|
+
|
197
|
+
def list_permissions_of(vhost, user)
|
198
|
+
decode_resource(@connection.get("/api/permissions/#{uri_encode(vhost)}/#{uri_encode(user)}"))
|
199
|
+
end
|
200
|
+
|
201
|
+
def update_permissions_of(vhost, user, attributes)
|
202
|
+
response = @connection.put("/api/permissions/#{uri_encode(vhost)}/#{uri_encode(user)}") do |req|
|
203
|
+
req.headers['Content-Type'] = "application/json"
|
204
|
+
req.body = MultiJson.dump(attributes)
|
205
|
+
end
|
206
|
+
decode_resource(response)
|
207
|
+
end
|
208
|
+
|
209
|
+
def clear_permissions_of(vhost, user)
|
210
|
+
decode_resource(@connection.delete("/api/permissions/#{uri_encode(vhost)}/#{uri_encode(user)}"))
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
def list_users
|
216
|
+
decode_resource_collection(@connection.get("/api/users"))
|
217
|
+
end
|
218
|
+
|
219
|
+
def user_info(name)
|
220
|
+
decode_resource(@connection.get("/api/users/#{uri_encode(name)}"))
|
221
|
+
end
|
222
|
+
|
223
|
+
def update_user(name, attributes)
|
224
|
+
response = @connection.put("/api/users/#{uri_encode(name)}") do |req|
|
225
|
+
req.headers['Content-Type'] = "application/json"
|
226
|
+
req.body = MultiJson.dump(attributes)
|
227
|
+
end
|
228
|
+
decode_resource(response)
|
229
|
+
end
|
230
|
+
alias create_user update_user
|
231
|
+
|
232
|
+
def delete_user(name)
|
233
|
+
decode_resource(@connection.delete("/api/users/#{uri_encode(name)}"))
|
234
|
+
end
|
235
|
+
|
236
|
+
def user_permissions(name)
|
237
|
+
decode_resource_collection(@connection.get("/api/users/#{uri_encode(name)}/permissions"))
|
238
|
+
end
|
239
|
+
|
240
|
+
def whoami
|
241
|
+
decode_resource(@connection.get("/api/whoami"))
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
def list_policies(vhost = nil)
|
247
|
+
path = if vhost
|
248
|
+
"/api/policies/#{uri_encode(vhost)}"
|
249
|
+
else
|
250
|
+
"/api/policies"
|
251
|
+
end
|
252
|
+
|
253
|
+
decode_resource_collection(@connection.get(path))
|
254
|
+
end
|
255
|
+
|
256
|
+
def list_policies_of(vhost, name = nil)
|
257
|
+
path = if name
|
258
|
+
"/api/policies/#{uri_encode(vhost)}/#{uri_encode(name)}"
|
259
|
+
else
|
260
|
+
"/api/policies/#{uri_encode(vhost)}"
|
261
|
+
end
|
262
|
+
decode_resource_collection(@connection.get(path))
|
263
|
+
end
|
264
|
+
|
265
|
+
def update_policies_of(vhost, name, attributes)
|
266
|
+
response = @connection.put("/api/policies/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
|
267
|
+
req.headers['Content-Type'] = "application/json"
|
268
|
+
req.body = MultiJson.dump(attributes)
|
269
|
+
end
|
270
|
+
decode_resource(response)
|
271
|
+
end
|
272
|
+
|
273
|
+
def clear_policies_of(vhost, name)
|
274
|
+
decode_resource(@connection.delete("/api/policies/#{uri_encode(vhost)}/#{uri_encode(name)}"))
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
def list_parameters(component = nil)
|
281
|
+
path = if component
|
282
|
+
"/api/parameters/#{uri_encode(component)}"
|
283
|
+
else
|
284
|
+
"/api/parameters"
|
285
|
+
end
|
286
|
+
decode_resource_collection(@connection.get(path))
|
287
|
+
end
|
288
|
+
|
289
|
+
def list_parameters_of(component, vhost, name = nil)
|
290
|
+
path = if name
|
291
|
+
"/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}"
|
292
|
+
else
|
293
|
+
"/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}"
|
294
|
+
end
|
295
|
+
decode_resource_collection(@connection.get(path))
|
296
|
+
end
|
297
|
+
|
298
|
+
def update_parameters_of(component, vhost, name, attributes)
|
299
|
+
response = @connection.put("/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
|
300
|
+
req.headers['Content-Type'] = "application/json"
|
301
|
+
req.body = MultiJson.dump(attributes)
|
302
|
+
end
|
303
|
+
decode_resource(response)
|
304
|
+
end
|
305
|
+
|
306
|
+
def clear_parameters_of(component, vhost, name)
|
307
|
+
decode_resource(@connection.delete("/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}"))
|
308
|
+
end
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
def aliveness_test(vhost)
|
313
|
+
r = @connection.get("/api/aliveness-test/#{uri_encode(vhost)}")
|
314
|
+
r.body["status"] == "ok"
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
protected
|
319
|
+
|
320
|
+
def initialize_connection(endpoint, options = {})
|
321
|
+
@connection = Faraday.new(:url => endpoint) do |conn|
|
322
|
+
conn.basic_auth options.fetch(:username, "guest"), options.fetch(:password, "guest")
|
323
|
+
conn.use FaradayMiddleware::FollowRedirects, :limit => 3
|
324
|
+
conn.response :json, :content_type => /\bjson$/
|
325
|
+
|
326
|
+
conn.adapter options.fetch(:adapter, Faraday.default_adapter)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
def uri_encode(s)
|
331
|
+
CGI.escape(s)
|
332
|
+
end
|
333
|
+
|
334
|
+
def decode_resource(response)
|
335
|
+
Hashie::Mash.new(response.body)
|
336
|
+
end
|
337
|
+
|
338
|
+
def decode_resource_collection(response)
|
339
|
+
response.body.map { |i| Hashie::Mash.new(i) }
|
340
|
+
end
|
341
|
+
end # Client
|
342
|
+
end # HTTP
|
343
|
+
end # RabbitMQ
|