rabbitmq_manager 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rabbitmq_manager.rb +44 -18
- data/lib/rabbitmq_manager/version.rb +1 -1
- data/rabbitmq_manager.gemspec +1 -0
- data/spec/rabbitmq_manager_spec.rb +30 -9
- data/spec/spec_helper.rb +3 -0
- metadata +21 -8
data/lib/rabbitmq_manager.rb
CHANGED
@@ -4,12 +4,16 @@ require 'faraday_middleware'
|
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
class RabbitMQManager
|
7
|
-
def initialize(url)
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def initialize(url, ssl_options = nil)
|
8
|
+
opts = {
|
9
|
+
:headers => {
|
10
|
+
'accept' => 'application/json',
|
11
|
+
'Content-Type' => 'application/json'
|
12
|
+
},
|
13
|
+
:ssl => ssl_options
|
11
14
|
}
|
12
|
-
|
15
|
+
|
16
|
+
@conn = Faraday::Connection.new(url, opts) do |builder|
|
13
17
|
builder.use Faraday::Response::RaiseError
|
14
18
|
builder.use FaradayMiddleware::EncodeJson
|
15
19
|
builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
|
@@ -18,54 +22,71 @@ class RabbitMQManager
|
|
18
22
|
end
|
19
23
|
|
20
24
|
def overview
|
21
|
-
@conn.get(
|
25
|
+
@conn.get(url :overview).body
|
26
|
+
end
|
27
|
+
|
28
|
+
def queues(vhost = '')
|
29
|
+
@conn.get(url :queues, vhost).body
|
30
|
+
end
|
31
|
+
|
32
|
+
def queue(vhost, name)
|
33
|
+
@conn.get(url :queues, vhost, name).body
|
34
|
+
end
|
35
|
+
|
36
|
+
def queue_create(vhost, name, durable = false, auto_delete = false, args = {})
|
37
|
+
opts = { durable: durable, auto_delete: auto_delete, arguments: args }
|
38
|
+
@conn.put(url(:queues, vhost, name), opts).body
|
39
|
+
end
|
40
|
+
|
41
|
+
def queue_delete(vhost, name)
|
42
|
+
@conn.delete(url :queues, vhost, name).body
|
22
43
|
end
|
23
44
|
|
24
45
|
def nodes
|
25
|
-
@conn.get(
|
46
|
+
@conn.get(url :nodes).body
|
26
47
|
end
|
27
48
|
|
28
49
|
def node(name)
|
29
|
-
@conn.get(
|
50
|
+
@conn.get(url :nodes, name).body
|
30
51
|
end
|
31
52
|
|
32
53
|
def vhosts
|
33
|
-
@conn.get(
|
54
|
+
@conn.get(url :vhosts).body
|
34
55
|
end
|
35
56
|
|
36
57
|
def vhost(name)
|
37
|
-
@conn.get(
|
58
|
+
@conn.get(url :vhosts, name).body
|
38
59
|
end
|
39
60
|
|
40
61
|
def vhost_create(name)
|
41
|
-
@conn.put(
|
62
|
+
@conn.put(url :vhosts, name).body
|
42
63
|
end
|
43
64
|
|
44
65
|
def vhost_delete(name)
|
45
|
-
@conn.delete(
|
66
|
+
@conn.delete(url :vhosts, name).body
|
46
67
|
end
|
47
68
|
|
48
69
|
def users
|
49
|
-
@conn.get(
|
70
|
+
@conn.get(url :users).body
|
50
71
|
end
|
51
72
|
|
52
73
|
def user(name)
|
53
|
-
@conn.get(
|
74
|
+
@conn.get(url :users, name).body
|
54
75
|
end
|
55
76
|
|
56
77
|
def user_create(name, password, tags = '')
|
57
|
-
@conn.put(
|
78
|
+
@conn.put(url(:users, name), {
|
58
79
|
:password => password,
|
59
80
|
:tags => tags
|
60
81
|
}).body
|
61
82
|
end
|
62
83
|
|
63
84
|
def user_delete(name)
|
64
|
-
@conn.delete(
|
85
|
+
@conn.delete(url :users, name).body
|
65
86
|
end
|
66
87
|
|
67
88
|
def user_set_permissions(name, vhost, configure, write, read)
|
68
|
-
@conn.put(
|
89
|
+
@conn.put(url(:permissions, vhost, name), {
|
69
90
|
:configure => configure,
|
70
91
|
:write => write,
|
71
92
|
:read => read
|
@@ -73,6 +94,11 @@ class RabbitMQManager
|
|
73
94
|
end
|
74
95
|
|
75
96
|
def user_permissions(name)
|
76
|
-
@conn.get(
|
97
|
+
@conn.get(url :users, name, :permissions).body
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def url(*args)
|
102
|
+
'/api/' + args.map{ |a| URI.encode_www_form_component a.to_s }.join('/')
|
77
103
|
end
|
78
104
|
end
|
data/rabbitmq_manager.gemspec
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require './spec/spec_helper'
|
1
2
|
require './lib/rabbitmq_manager'
|
2
3
|
|
3
4
|
describe RabbitMQManager do
|
@@ -15,6 +16,25 @@ describe RabbitMQManager do
|
|
15
16
|
it { should have(1).things }
|
16
17
|
end
|
17
18
|
|
19
|
+
context '#queues' do
|
20
|
+
subject { manager.queues }
|
21
|
+
it { should be_instance_of Array }
|
22
|
+
end
|
23
|
+
|
24
|
+
context '#queues(vhost)' do
|
25
|
+
subject { manager.queues('/') }
|
26
|
+
it { should be_instance_of Array }
|
27
|
+
end
|
28
|
+
|
29
|
+
context '#queue' do
|
30
|
+
let(:queue) { 'q1' }
|
31
|
+
before { manager.queue_create('/', queue) }
|
32
|
+
subject { manager.queue('/', queue) }
|
33
|
+
it { should be_instance_of Hash }
|
34
|
+
it { subject['name'].should == queue }
|
35
|
+
after { manager.queue_delete('/', queue) }
|
36
|
+
end
|
37
|
+
|
18
38
|
context '#node' do
|
19
39
|
let(:hostname) { `hostname -s`.chop }
|
20
40
|
subject { manager.node("rabbit@#{hostname}") }
|
@@ -58,15 +78,16 @@ describe RabbitMQManager do
|
|
58
78
|
}.should raise_error Faraday::Error::ResourceNotFound
|
59
79
|
end
|
60
80
|
|
61
|
-
|
62
|
-
manager.user_set_permissions(user, vhost, '.*', '.*', '.*')
|
63
|
-
manager.user_permissions(user)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
81
|
+
context 'permissions' do
|
82
|
+
before { manager.user_set_permissions(user, vhost, '.*', '.*', '.*') }
|
83
|
+
subject { manager.user_permissions(user) }
|
84
|
+
it { subject.should be_instance_of Array }
|
85
|
+
context 'for first element' do
|
86
|
+
subject { manager.user_permissions(user).first }
|
87
|
+
it('has name') { subject['user'] == user }
|
88
|
+
it('has read permissions') { subject['read'] == '.*' }
|
89
|
+
it('has write permissions') { subject['write'] == '.*' }
|
90
|
+
end
|
70
91
|
end
|
71
92
|
end
|
72
93
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbitmq_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
|
-
requirement: &
|
16
|
+
requirement: &70099315206060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70099315206060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: faraday_middleware
|
27
|
-
requirement: &
|
27
|
+
requirement: &70099315205400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70099315205400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70099315204860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,18 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70099315204860
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: simple_cov
|
49
|
+
requirement: &70099315204260 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70099315204260
|
47
58
|
description: Ruby wrapper for RabbitMQ management HTTP API
|
48
59
|
email:
|
49
60
|
- carl.hoerberg@gmail.com
|
@@ -60,6 +71,7 @@ files:
|
|
60
71
|
- lib/rabbitmq_manager/version.rb
|
61
72
|
- rabbitmq_manager.gemspec
|
62
73
|
- spec/rabbitmq_manager_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
63
75
|
homepage: https://github.com/carlhoerberg/rabbitmq_manager
|
64
76
|
licenses: []
|
65
77
|
post_install_message:
|
@@ -86,3 +98,4 @@ specification_version: 3
|
|
86
98
|
summary: Ruby wrapper for RabbitMQ management HTTP API
|
87
99
|
test_files:
|
88
100
|
- spec/rabbitmq_manager_spec.rb
|
101
|
+
- spec/spec_helper.rb
|