rabbitmq_manager 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rabbitmq_manager.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Carl Hörberg
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,44 @@
1
+ # RabbitMQ Manager
2
+
3
+ A wrapper for RabbitMQs management HTTP API.
4
+
5
+ [More information on the API](http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v2_7_1/priv/www/api/index.html)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rabbitmq_manager'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rabbitmq_manager
20
+
21
+ ## Usage
22
+
23
+ rmq = RabbitMQManager.new 'http://guest:guest@localhost:55672'
24
+ rmq.overview #=> cluster overview
25
+
26
+ rmq.nodes #=> array of nodes
27
+ rmq.node('node_name')
28
+
29
+ rmq.vhosts #=> array of vhosts
30
+ rmq.vhost_create 'vhost_name'
31
+ rmq.vhost_delete 'vhost_name'
32
+
33
+ rmq.users #=> array of users
34
+ rmq.user_create 'username', 'password'
35
+ rmq.user_delete 'username'
36
+ rmq.user_set_permissions 'username', 'vhost', '.*', '.*', '.*'
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ class RabbitMQManager
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,78 @@
1
+ require "rabbitmq_manager/version"
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+ require 'uri'
5
+
6
+ class RabbitMQManager
7
+ def initialize(url)
8
+ headers = {
9
+ 'accept' => 'application/json',
10
+ 'Content-Type' => 'application/json'
11
+ }
12
+ @conn = Faraday.new(:url => url, :headers => headers) do |builder|
13
+ builder.use Faraday::Response::RaiseError
14
+ builder.use FaradayMiddleware::EncodeJson
15
+ builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
16
+ builder.adapter Faraday.default_adapter
17
+ end
18
+ end
19
+
20
+ def overview
21
+ @conn.get('/api/overview').body
22
+ end
23
+
24
+ def nodes
25
+ @conn.get('/api/nodes').body
26
+ end
27
+
28
+ def node(name)
29
+ @conn.get("/api/nodes/#{URI.escape name}").body
30
+ end
31
+
32
+ def vhosts
33
+ @conn.get('/api/vhosts').body
34
+ end
35
+
36
+ def vhost(name)
37
+ @conn.get("/api/vhosts/#{URI.escape name}").body
38
+ end
39
+
40
+ def vhost_create(name)
41
+ @conn.put("/api/vhosts/#{URI.escape name}").body
42
+ end
43
+
44
+ def vhost_delete(name)
45
+ @conn.delete("/api/vhosts/#{URI.escape name}").body
46
+ end
47
+
48
+ def users
49
+ @conn.get('/api/users').body
50
+ end
51
+
52
+ def user(name)
53
+ @conn.get("/api/users/#{URI.escape name}").body
54
+ end
55
+
56
+ def user_create(name, password, tags = '')
57
+ @conn.put("/api/users/#{URI.escape name}", {
58
+ :password => password,
59
+ :tags => tags
60
+ }).body
61
+ end
62
+
63
+ def user_delete(name)
64
+ @conn.delete("/api/users/#{URI.escape name}").body
65
+ end
66
+
67
+ def user_set_permissions(name, vhost, configure, write, read)
68
+ @conn.put("/api/permissions/#{URI.escape vhost}/#{URI.escape name}", {
69
+ :configure => configure,
70
+ :write => write,
71
+ :read => read
72
+ }).body
73
+ end
74
+
75
+ def user_permissions(name)
76
+ @conn.get("/api/users/#{URI.escape name}/permissions").body
77
+ end
78
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rabbitmq_manager/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Carl Hörberg"]
6
+ gem.email = ["carl.hoerberg@gmail.com"]
7
+ gem.description = %q{Ruby wrapper for RabbitMQ management HTTP API}
8
+ gem.summary = %q{Ruby wrapper for RabbitMQ management HTTP API}
9
+ gem.homepage = "https://github.com/carlhoerberg/rabbitmq_manager"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "rabbitmq_manager"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = RabbitMQManager::VERSION
17
+
18
+ gem.add_runtime_dependency 'faraday'
19
+ gem.add_runtime_dependency 'faraday_middleware'
20
+ gem.add_development_dependency 'rspec'
21
+ end
@@ -0,0 +1,72 @@
1
+ require './lib/rabbitmq_manager'
2
+
3
+ describe RabbitMQManager do
4
+ let(:manager) {
5
+ RabbitMQManager.new 'http://guest:guest@localhost:55672'
6
+ }
7
+
8
+ context '#overview' do
9
+ subject { manager.overview }
10
+ it { should be_instance_of Hash }
11
+ end
12
+
13
+ context '#nodes' do
14
+ subject { manager.nodes }
15
+ it { should have(1).things }
16
+ end
17
+
18
+ context '#node' do
19
+ let(:hostname) { `hostname -s`.chop }
20
+ subject { manager.node("rabbit@#{hostname}") }
21
+ it { should be_instance_of Hash }
22
+ end
23
+
24
+ context 'when administering users and vhosts' do
25
+ let(:user) { 'user1' }
26
+ let(:passwd) { 'rand123' }
27
+ let(:vhost) { 'vh1' }
28
+
29
+ before do
30
+ manager.user_create user, passwd
31
+ manager.vhost_create vhost
32
+ end
33
+
34
+ after do
35
+ manager.user_delete user
36
+ manager.vhost_delete vhost
37
+ end
38
+
39
+ it 'can list vhosts' do
40
+ manager.vhosts.should have_at_least(2).things
41
+ end
42
+
43
+ it 'can view one vhost' do
44
+ manager.vhost(vhost)['name'].should == vhost
45
+ end
46
+
47
+ it 'can list users' do
48
+ manager.users.should have_at_least(2).things
49
+ end
50
+
51
+ it 'can view one user' do
52
+ manager.user(user)['name'].should == user
53
+ end
54
+
55
+ it 'cannot view an non existing user' do
56
+ lambda {
57
+ manager.user('foo')
58
+ }.should raise_error Faraday::Error::ResourceNotFound
59
+ end
60
+
61
+ it 'can set permissions' do
62
+ manager.user_set_permissions(user, vhost, '.*', '.*', '.*')
63
+ manager.user_permissions(user).should == [{
64
+ "user"=>"user1",
65
+ "vhost"=>"vh1",
66
+ "configure"=>".*",
67
+ "write"=>".*",
68
+ "read"=>".*"
69
+ }]
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbitmq_manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Carl Hörberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &70360235104620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70360235104620
25
+ - !ruby/object:Gem::Dependency
26
+ name: faraday_middleware
27
+ requirement: &70360235104200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70360235104200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70360235103780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70360235103780
47
+ description: Ruby wrapper for RabbitMQ management HTTP API
48
+ email:
49
+ - carl.hoerberg@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/rabbitmq_manager.rb
60
+ - lib/rabbitmq_manager/version.rb
61
+ - rabbitmq_manager.gemspec
62
+ - spec/rabbitmq_manager_spec.rb
63
+ homepage: https://github.com/carlhoerberg/rabbitmq_manager
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.17
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Ruby wrapper for RabbitMQ management HTTP API
87
+ test_files:
88
+ - spec/rabbitmq_manager_spec.rb