rabbit_manager 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rabbit_manager.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'rest-client'
@@ -0,0 +1 @@
1
+ Some basic (incomplete) bindings. Mainly for my personal use, but maybe someone will find it useful. Pull requests welcome.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,103 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+ class RabbitManager
4
+
5
+ def initialize(uri)
6
+ @uri = uri
7
+ end
8
+
9
+ def add_vhost(vh)
10
+ RestClient.put "#{@uri}/api/vhosts/#{CGI.escape(vh)}", nil, :content_type => :json, :accept => :json
11
+ end
12
+
13
+ def delete_vhost(vh)
14
+ RestClient.delete "#{@uri}/api/vhosts/#{CGI.escape(vh)}"
15
+ end
16
+
17
+ def add_queue(queue_name, options = {})
18
+ options = default_options.merge(options)
19
+ RestClient.put "#{@uri}/api/queues/#{CGI.escape(options[:vhost])}/#{queue_name}", {"type"=> options[:type],"auto_delete" => options[:auto_delete], "durable" =>options[:durable], "arguments" => options[:arguments]}.to_json, :content_type => :json, :accept => :json
20
+ end
21
+
22
+ def get_queue(queue_name, options = {})
23
+ options[:vhost] ||= '/'
24
+ begin
25
+ JSON.parse(RestClient.get "#{@uri}/api/queues/#{CGI.escape(options[:vhost])}/#{queue_name}")
26
+ rescue
27
+ nil
28
+ end
29
+ end
30
+
31
+ def delete_queue(queue_name, options = {})
32
+ options[:vhost] ||= '/'
33
+ begin
34
+ RestClient.delete "#{@uri}/api/queues/#{CGI.escape(options[:vhost])}/#{queue_name}"
35
+ rescue
36
+ nil
37
+ end
38
+ end
39
+
40
+ def add_exchange(name, options = {})
41
+ options = default_options.merge(options)
42
+ RestClient.put "#{@uri}/api/exchanges/#{CGI.escape(options[:vhost])}/#{name}", {"type" => options[:type], "auto_delete" => options[:auto_delete], "durable" => options[:durable], "internal" => options[:internal], "arguments" => options[:arguments]}.to_json, :content_type => :json, :accept => :json
43
+ end
44
+
45
+ def delete_exchange(name, options = {})
46
+ options[:vhost] ||= '/'
47
+ RestClient.delete "#{@uri}/api/exchanges/#{CGI.escape(options[:vhost])}/#{name}"
48
+ end
49
+
50
+ def add_binding(exchange, queue, options = {})
51
+ options = default_options.merge(options)
52
+ url = "#{@uri}/api/bindings/#{CGI.escape(options[:vhost])}/e/#{exchange}/q/#{queue}"
53
+ RestClient.post url, {'routing_key' => options[:key], "arguments" => options[:arguments] }.to_json, :content_type => :json
54
+ end
55
+
56
+
57
+ def add_user(username, password, options = {})
58
+ options[:administrator] ||= false
59
+ RestClient.put "#{@uri}/api/users/#{username}", {"password" => password, "administrator" =>options[:administrator]}.to_json, :content_type => :json, :accept => :json
60
+ end
61
+
62
+
63
+ def get_user(username)
64
+ begin
65
+ JSON.parse(RestClient.get "#{@uri}/api/users/#{username}")
66
+ rescue
67
+ nil
68
+ end
69
+ end
70
+
71
+ def delete_user(username)
72
+ begin
73
+ RestClient.delete "#{@uri}/api/users/#{username}"
74
+ rescue
75
+ nil
76
+ end
77
+ end
78
+
79
+ def add_permission(username, permissions, options = {})
80
+ options[:vhost] ||= '/'
81
+ RestClient.put "#{@uri}/api/permissions/#{CGI.escape(options[:vhost])}/#{username}", permissions.to_json, :content_type => :json, :accept => :json
82
+ end
83
+
84
+ def get_permissions(username, options = {})
85
+ options[:vhost] ||= '/'
86
+ begin
87
+ JSON.parse(RestClient.get "#{@uri}/api/permissions/#{CGI.escape(options[:vhost])}/#{username}")
88
+ rescue
89
+ nil
90
+ end
91
+ end
92
+
93
+ def default_options
94
+ options = {}
95
+ options[:vhost] = '/'
96
+ options[:auto_delete] = false
97
+ options[:durable] = true
98
+ options[:arguments] = []
99
+ options[:internal] = false
100
+ options
101
+ end
102
+
103
+ end
@@ -0,0 +1,3 @@
1
+ class RabbitManager
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rabbit_manager/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rabbit_manager"
7
+ s.version = RabbitManager::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["mixtli"]
10
+ s.email = ["mixtli@github.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Client for RabbitMQ management plugin}
13
+ s.description = %q{Wrapper around management plugin REST api}
14
+
15
+ s.rubyforge_project = "rabbit_manager"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe RabbitManager do
4
+
5
+ before do
6
+ @rabbit = RabbitManager.new("http://guest:guest@localhost:55672")
7
+ @vhost = '/'
8
+ @rabbit.add_vhost(@vhost)
9
+ @rabbit.delete_queue("test_queue", :vhost => @vhost)
10
+ @rabbit.delete_user("testuser")
11
+ end
12
+
13
+ after do
14
+ @rabbit.delete_queue("test_queue", :vhost => @vhost)
15
+ end
16
+
17
+ it "should create a queue" do
18
+ queue = @rabbit.get_queue("test_queue", :vhost => @vhost)
19
+ queue.should be_nil
20
+ @rabbit.add_queue("test_queue", :vhost => @vhost)
21
+ queue = @rabbit.get_queue("test_queue", :vhost => @vhost)
22
+ queue['name'].should eql("test_queue")
23
+ @rabbit.delete_queue('test_queue', :vhost => @vhost)
24
+ end
25
+
26
+ it "should create a user" do
27
+ user = @rabbit.get_user("testuser")
28
+ user.should be_nil
29
+ @rabbit.add_user("testuser", "testpass")
30
+ user = @rabbit.get_user("testuser")
31
+ user.should_not be_nil
32
+ end
33
+
34
+
35
+ it "should create a permission" do
36
+ permissions = {
37
+ 'scope' => 'client',
38
+ 'configure' => '.*',
39
+ 'write' => '.*',
40
+ 'read' =>'.*'
41
+ }
42
+ @rabbit.add_user("testuser", "testpass")
43
+ @rabbit.add_queue("test_queue", :vhost => @vhost)
44
+ @rabbit.add_permission("testuser", permissions, :vhost => @vhost)
45
+
46
+ perms = @rabbit.get_permissions("testuser", :vhost => @vhost)
47
+ perms['user'].should == "testuser"
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rabbit_manager'
4
+ require 'rspec'
5
+ require 'rspec/autorun'
6
+
7
+ #Spec::Runner.configure do |config|
8
+
9
+ #end
10
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbit_manager
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - mixtli
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-01 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Wrapper around management plugin REST api
22
+ email:
23
+ - mixtli@github.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.rdoc
34
+ - Rakefile
35
+ - lib/rabbit_manager.rb
36
+ - lib/rabbit_manager/version.rb
37
+ - rabbit_manager.gemspec
38
+ - spec/rabbit_spec.rb
39
+ - spec/spec_helper.rb
40
+ has_rdoc: true
41
+ homepage: ""
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: rabbit_manager
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Client for RabbitMQ management plugin
72
+ test_files:
73
+ - spec/rabbit_spec.rb
74
+ - spec/spec_helper.rb