rabbitmq_manager 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ff53ef51f95271af116e41fb5130d7f4843d825
4
+ data.tar.gz: d78078c29a5162f3a8b3a5786364b7950924509c
5
+ SHA512:
6
+ metadata.gz: 98aced92ae24e542932c21bcb419a6d467467af63615d3c9bff6b5d8e4de9d5a3f8b1e2b067d32a96664177239edef15c0638c42a517ead3ca7191789d3b7d0c
7
+ data.tar.gz: a88cb6aae684c57bbbcc5ce789a911629152cfc49f2cf12774299d36f2171a181f30d155f3871673cfa2b66d48b4775fd8c476c28f369e5a1a82810293bbffe9
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # RabbitMQ Manager
2
2
 
3
- A wrapper for RabbitMQs management HTTP API.
3
+ A wrapper for RabbitMQs management HTTP API.
4
4
 
5
- [More information on the API](http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v2_7_1/priv/www/api/index.html)
5
+ [More information on the API](http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_2_4/priv/www/api/index.html)
6
6
 
7
7
  ## Installation
8
8
 
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- rmq = RabbitMQManager.new 'http://guest:guest@localhost:55672'
23
+ rmq = RabbitMQManager.new 'http://guest:guest@localhost:15672'
24
24
  rmq.overview #=> cluster overview
25
25
 
26
26
  rmq.nodes #=> array of nodes
@@ -6,7 +6,7 @@ require 'uri'
6
6
  class RabbitMQManager
7
7
  def initialize(url, ssl_options = nil)
8
8
  opts = {
9
- :headers => {
9
+ :headers => {
10
10
  'accept' => 'application/json',
11
11
  'Content-Type' => 'application/json'
12
12
  },
@@ -25,6 +25,41 @@ class RabbitMQManager
25
25
  @conn.get(url :overview).body
26
26
  end
27
27
 
28
+ def connections
29
+ @conn.get(url :connections).body
30
+ end
31
+
32
+ def channels
33
+ @conn.get(url :channels).body
34
+ end
35
+
36
+ def policies(vhost = '')
37
+ @conn.get(url :policies, vhost).body
38
+ end
39
+
40
+ def policy_get(vhost, name)
41
+ @conn.get(url :policies, vhost, name).body
42
+ end
43
+
44
+ def policy_create(vhost, name, pattern, definition, opts = nil)
45
+ valid = ["ha-mode", "ha-params", "ha-sync-mode", "alternate-exchange", "dead-letter-exchange","dead-letter-routing-key", "message-ttl", "expires", "max-length", "federation-upstream-set"]
46
+ definition.keys.each { | key |
47
+ if !valid.include?(key)
48
+ raise "The definition key '#{key}' is not valid, try these #{valid}"
49
+ end
50
+ }
51
+ policy = {
52
+ pattern: pattern,
53
+ definition: definition
54
+ }.merge(opts || {})
55
+
56
+ @conn.put(url(:policies, vhost, name), policy).body
57
+ end
58
+
59
+ def policy_delete(vhost, name)
60
+ @conn.delete(url :policies, vhost, name).body
61
+ end
62
+
28
63
  def queues(vhost = '')
29
64
  @conn.get(url :queues, vhost).body
30
65
  end
@@ -76,8 +111,8 @@ class RabbitMQManager
76
111
 
77
112
  def user_create(name, password, tags = '')
78
113
  @conn.put(url(:users, name), {
79
- :password => password,
80
- :tags => tags
114
+ :password => password,
115
+ :tags => tags
81
116
  }).body
82
117
  end
83
118
 
@@ -88,7 +123,7 @@ class RabbitMQManager
88
123
  def user_set_permissions(name, vhost, configure, write, read)
89
124
  @conn.put(url(:permissions, vhost, name), {
90
125
  :configure => configure,
91
- :write => write,
126
+ :write => write,
92
127
  :read => read
93
128
  }).body
94
129
  end
@@ -1,3 +1,3 @@
1
1
  class RabbitMQManager
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.add_runtime_dependency 'faraday'
19
19
  gem.add_runtime_dependency 'faraday_middleware'
20
20
  gem.add_development_dependency 'rspec'
21
- gem.add_development_dependency 'simple_cov'
21
+ gem.add_development_dependency 'simplecov'
22
22
  end
@@ -1,93 +1,184 @@
1
1
  require './spec/spec_helper'
2
2
  require './lib/rabbitmq_manager'
3
3
 
4
- describe RabbitMQManager do
5
- let(:manager) {
6
- RabbitMQManager.new 'http://guest:guest@localhost:55672'
7
- }
8
-
9
- context '#overview' do
10
- subject { manager.overview }
11
- it { should be_instance_of Hash }
4
+ def make_name(name_prefix)
5
+ name_prefix + '-' + rand(1000).to_s
6
+ end
7
+
8
+ RSpec.describe RabbitMQManager do
9
+ before(:all) do
10
+ @rspec_user = 'guest'
11
+ rspec_password = 'guest'
12
+ @manager = RabbitMQManager.new "http://#{@rspec_user}:#{rspec_password}@localhost:15672"
13
+ end
14
+
15
+ it 'the overview method provides a Hash' do
16
+ expect(@manager.overview()).to be_a Hash
12
17
  end
13
18
 
14
- context '#nodes' do
15
- subject { manager.nodes }
16
- it { should have(1).things }
19
+ it 'there will be at least one connection' do
20
+ items = @manager.connections()
21
+ expect(items.length).to be >= 1
17
22
  end
18
23
 
19
- context '#queues' do
20
- subject { manager.queues }
21
- it { should be_instance_of Array }
24
+ it 'there will be at least one channel' do
25
+ items = @manager.channels()
26
+ expect(items.length).to be >= 1
22
27
  end
23
28
 
24
- context '#queues(vhost)' do
25
- subject { manager.queues('/') }
26
- it { should be_instance_of Array }
29
+ describe 'node discovery' do
30
+ it 'there will be at least one node' do
31
+ items = @manager.nodes()
32
+ expect(items.length).to be >= 1
33
+ end
34
+ it 'the list of nodes is a Hash' do
35
+ hostname = `hostname`.chop
36
+ item = @manager.node("rabbit@#{hostname}")
37
+ expect(item).to be_a Hash
38
+ end
27
39
  end
28
40
 
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) }
41
+ it 'all queues can be listed as an Array' do
42
+ items = @manager.queues()
43
+ expect(items).to be_an Array
36
44
  end
37
45
 
38
- context '#node' do
39
- let(:hostname) { `hostname -s`.chop }
40
- subject { manager.node("rabbit@#{hostname}") }
41
- it { should be_instance_of Hash }
46
+ it 'queues can be listed per vhost as an Array' do
47
+ items = @manager.queues('/')
48
+ expect(items).to be_an Array
42
49
  end
43
50
 
44
- context 'when administering users and vhosts' do
45
- let(:user) { 'user1' }
46
- let(:passwd) { 'rand123' }
47
- let(:vhost) { 'vh1' }
51
+ describe 'queue manipulation' do
52
+ queue = make_name 'rspec-q1'
53
+ vhost = '/'
48
54
 
49
- before do
50
- manager.user_create user, passwd
51
- manager.vhost_create vhost
55
+ after(:all) do
56
+ @manager.queue_delete(vhost, queue)
52
57
  end
53
58
 
54
- after do
55
- manager.user_delete user
56
- manager.vhost_delete vhost
59
+ it 'queues can be created and removed' do
60
+ @manager.queue_create(vhost, queue)
61
+ items = @manager.queue(vhost, queue)
62
+ expect(items).to be_a Hash
63
+ expect(items['name']).to eq(queue)
57
64
  end
58
-
59
- it 'can list vhosts' do
60
- manager.vhosts.should have_at_least(2).things
65
+ end
66
+
67
+ describe 'when administering users and vhosts' do
68
+ user = make_name 'rspec-user'
69
+ passwd = make_name ''
70
+ vhost = 'rspec-vh'
71
+
72
+ before(:all) do
73
+ @manager.user_create user, passwd
74
+ @manager.vhost_create vhost
75
+ end
76
+
77
+ after(:all) do
78
+ @manager.user_delete user
79
+ @manager.vhost_delete vhost
80
+ end
81
+
82
+ it 'list vhosts' do
83
+ expect(@manager.vhosts.length).to be >= 2
61
84
  end
62
85
 
63
86
  it 'can view one vhost' do
64
- manager.vhost(vhost)['name'].should == vhost
87
+ expect(@manager.vhost(vhost)['name']).to eq(vhost)
65
88
  end
66
89
 
67
90
  it 'can list users' do
68
- manager.users.should have_at_least(2).things
91
+ expect(@manager.users.length).to be >= 2
69
92
  end
70
93
 
71
94
  it 'can view one user' do
72
- manager.user(user)['name'].should == user
95
+ expect(@manager.user(user)['name']).to eq(user)
73
96
  end
74
97
 
75
98
  it 'cannot view an non existing user' do
76
- lambda {
77
- manager.user('foo')
78
- }.should raise_error Faraday::Error::ResourceNotFound
79
- end
80
-
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'] == '.*' }
99
+ expect {
100
+ @manager.user('foo')
101
+ }.to raise_error Faraday::Error::ResourceNotFound
102
+ end
103
+
104
+ describe 'when administering users and vhosts' do
105
+ users = []
106
+ first = nil
107
+
108
+ before(:all) do
109
+ @manager.user_set_permissions(user, vhost, '.*', '.*', '.*')
110
+ users = @manager.user_permissions(user)
111
+ first = users.first
112
+ end
113
+
114
+ it 'user permissions is an Array' do
115
+ expect(users).to be_an Array
116
+ end
117
+
118
+ it 'can read first users name' do
119
+ expect(first['user']).to eq(user)
120
+ end
121
+
122
+ it 'first users has read permissions' do
123
+ expect(first['read']).to eq('.*')
124
+ end
125
+
126
+ it 'first users has write permissions' do
127
+ expect(first['write']).to eq('.*')
90
128
  end
129
+
91
130
  end
131
+
92
132
  end
93
- end
133
+
134
+ describe 'high availability policies can be administered' do
135
+ vhost = make_name 'rspec-vh'
136
+
137
+ before(:each) do
138
+ @manager.vhost_create(vhost)
139
+ @manager.user_set_permissions(@rspec_user, vhost, '.*', '.*', '.*')
140
+ end
141
+
142
+ after(:each) do
143
+ @manager.vhost_delete(vhost)
144
+ end
145
+
146
+ it 'initially a specific vhost has no policies, the Array is empty' do
147
+ policies = @manager.policies(vhost)
148
+ expect(policies).to be_an Array
149
+ expect(policies.length).to eq(0)
150
+ end
151
+
152
+ it 'Creating a basic policy requires a name, pattern and a definition' do
153
+ name = make_name 'rspec-policy'
154
+ @manager.policy_create(vhost, name, '^None', {'ha-mode'=>'all'})
155
+ policies = @manager.policies(vhost)
156
+ expect(policies.length).to eq(1)
157
+ end
158
+
159
+ it 'individual policies can be queried' do
160
+ name = make_name 'rspec-policy'
161
+ @manager.policy_create(vhost, name, '^None', {'ha-mode'=>'all'})
162
+ policy = @manager.policy_get(vhost, name)
163
+
164
+ expect(policy['name']).to eq(name)
165
+ end
166
+
167
+ it 'individual policies can be deleted' do
168
+ name = make_name 'rspec-policy'
169
+
170
+ @manager.policy_create(vhost, name, '^None', {'ha-mode'=>'all'})
171
+ @manager.policy_delete(vhost, name)
172
+
173
+ expect(@manager.policies(vhost).length).to eq(0)
174
+ end
175
+
176
+ it 'queries on a non-existent policy throws and error' do
177
+ name = make_name 'rspec-policy'
178
+ expect {
179
+ @manager.policy_get(vhost, name)
180
+ }.to raise_error Faraday::Error::ResourceNotFound
181
+ end
182
+
183
+ end
184
+ end
metadata CHANGED
@@ -1,60 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbitmq_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Carl Hörberg
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-03-13 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: faraday
16
- requirement: &70099315206060 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70099315206060
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: faraday_middleware
27
- requirement: &70099315205400 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70099315205400
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: rspec
38
- requirement: &70099315204860 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - ">="
42
46
  - !ruby/object:Gem::Version
43
47
  version: '0'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70099315204860
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  - !ruby/object:Gem::Dependency
48
- name: simple_cov
49
- requirement: &70099315204260 !ruby/object:Gem::Requirement
50
- none: false
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - ">="
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *70099315204260
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  description: Ruby wrapper for RabbitMQ management HTTP API
59
70
  email:
60
71
  - carl.hoerberg@gmail.com
@@ -62,7 +73,7 @@ executables: []
62
73
  extensions: []
63
74
  extra_rdoc_files: []
64
75
  files:
65
- - .gitignore
76
+ - ".gitignore"
66
77
  - Gemfile
67
78
  - LICENSE
68
79
  - README.md
@@ -74,27 +85,26 @@ files:
74
85
  - spec/spec_helper.rb
75
86
  homepage: https://github.com/carlhoerberg/rabbitmq_manager
76
87
  licenses: []
88
+ metadata: {}
77
89
  post_install_message:
78
90
  rdoc_options: []
79
91
  require_paths:
80
92
  - lib
81
93
  required_ruby_version: !ruby/object:Gem::Requirement
82
- none: false
83
94
  requirements:
84
- - - ! '>='
95
+ - - ">="
85
96
  - !ruby/object:Gem::Version
86
97
  version: '0'
87
98
  required_rubygems_version: !ruby/object:Gem::Requirement
88
- none: false
89
99
  requirements:
90
- - - ! '>='
100
+ - - ">="
91
101
  - !ruby/object:Gem::Version
92
102
  version: '0'
93
103
  requirements: []
94
104
  rubyforge_project:
95
- rubygems_version: 1.8.17
105
+ rubygems_version: 2.2.2
96
106
  signing_key:
97
- specification_version: 3
107
+ specification_version: 4
98
108
  summary: Ruby wrapper for RabbitMQ management HTTP API
99
109
  test_files:
100
110
  - spec/rabbitmq_manager_spec.rb