rabbitmqadmin-cli 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,154 @@
1
+ require 'date'
2
+
3
+ #############################################################################
4
+ #
5
+ # Helper functions
6
+ #
7
+ #############################################################################
8
+
9
+ def name
10
+ @name ||= Dir['*.gemspec'].first.split('.').first
11
+ end
12
+
13
+ def version
14
+ line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
15
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
16
+ end
17
+
18
+ def date
19
+ Date.today.to_s
20
+ end
21
+
22
+ def rubyforge_project
23
+ name
24
+ end
25
+
26
+ def gemspec_file
27
+ "#{name}.gemspec"
28
+ end
29
+
30
+ def gem_file
31
+ "#{name}-#{version}.gem"
32
+ end
33
+
34
+ def replace_header(head, header_name, provider = nil)
35
+ if provider
36
+ value = send(provider)
37
+ else
38
+ value = "'#{send(header_name)}'"
39
+ end
40
+
41
+ provider ||= header_name
42
+ head.sub!(/(\.#{header_name}\s*= ).*/) { "#{$1}#{value}"}
43
+ end
44
+
45
+ def platform
46
+ jruby? ? '-java' : ''
47
+ end
48
+
49
+ def platform_dependant_gem_file
50
+ "#{name}-#{version}#{platform}.gem"
51
+ end
52
+
53
+ def platform_dependent_version
54
+ "'#{version}#{platform}'"
55
+ end
56
+
57
+ def jruby?
58
+ RUBY_PLATFORM.to_s == 'java'
59
+ end
60
+
61
+ def trim_array_ends array
62
+ array.shift
63
+ array.pop
64
+ array
65
+ end
66
+
67
+ #############################################################################
68
+ #
69
+ # Custom tasks
70
+ #
71
+ #############################################################################
72
+
73
+
74
+ #############################################################################
75
+ #
76
+ # Packaging tasks
77
+ #
78
+ #############################################################################
79
+
80
+ def built_gem
81
+ @built_gem ||= Dir["#{name}*.gem"].first
82
+ end
83
+
84
+ desc "Create tag v#{platform_dependent_version} and build and push #{platform_dependant_gem_file} to Rubygems"
85
+ task :release => :build do
86
+ unless `git branch` =~ /^\* master$/
87
+ puts "You must be on the master branch to release!"
88
+ exit!
89
+ end
90
+
91
+ sh "git commit --allow-empty -a -m 'Release #{platform_dependent_version}'"
92
+ sh "git tag v#{platform_dependent_version}"
93
+ sh "git push origin master"
94
+ sh "git push origin v#{platform_dependent_version}"
95
+
96
+ command = "gem push pkg/#{platform_dependant_gem_file}"
97
+
98
+ if jruby?
99
+ puts "--------------------------------------------------------------------------------------"
100
+ puts "can't push to rubygems using jruby at the moment, so switch to mri and run: #{command}"
101
+ puts "--------------------------------------------------------------------------------------"
102
+ else
103
+ sh command
104
+ end
105
+ end
106
+
107
+ desc "Build #{platform_dependant_gem_file} into the pkg directory"
108
+ task :build => :gemspec do
109
+ sh "mkdir -p pkg"
110
+ sh "gem build #{gemspec_file}"
111
+ sh "mv #{built_gem} pkg"
112
+ end
113
+
114
+ desc "Generate #{gemspec_file}"
115
+ task :gemspec => :validate do
116
+ # read spec file and split out manifest section
117
+ spec = File.read(gemspec_file)
118
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
119
+
120
+ # replace name version and date
121
+ replace_header(head, :name)
122
+ replace_header(head, :version)
123
+ replace_header(head, :date)
124
+ #comment this out if your rubyforge_project has a different name
125
+ #replace_header(head, :rubyforge_project)
126
+
127
+ # determine file list from git ls-files
128
+ files = `git ls-files`.
129
+ split("\n").
130
+ sort.
131
+ reject { |file| file =~ /^\./ }.
132
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
133
+ map { |file| " #{file}" }.
134
+ join("\n")
135
+
136
+ # piece file back together and write
137
+ manifest = " s.files = %w[\n#{files}\n ]\n"
138
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
139
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
140
+ puts "Updated #{gemspec_file}"
141
+ end
142
+
143
+ desc "Validate #{gemspec_file}"
144
+ task :validate do
145
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
146
+ unless libfiles.empty?
147
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
148
+ exit!
149
+ end
150
+ unless Dir['VERSION*'].empty?
151
+ puts "A `VERSION` file at root level violates Gem best practices."
152
+ exit!
153
+ end
154
+ end
@@ -0,0 +1,74 @@
1
+ class RabbitMqAdminCli
2
+ def initialize admin_user = 'guest', admin_password = 'guest'
3
+ @admin_user = admin_user
4
+ @admin_password = admin_password
5
+ end
6
+
7
+ def delete_exchanges
8
+ list_exchanges.each { |exchange| `#{run vhost} delete exchange name=#{exchange[:name]}` }
9
+ end
10
+
11
+ def delete_queues
12
+ list_queues.each { |queue| `#{run vhost} delete queue name=#{queue[:name]}` }
13
+ end
14
+
15
+ def initialize_user vhost, user, password, tags = ''
16
+ `#{run} delete user name=#{user}` if user_exists? user
17
+ `#{run} declare user name=#{user} password=#{password} tags=#{tags}`
18
+ add_user_to_vhost vhost, user
19
+ end
20
+
21
+ def initialize_vhost vhost
22
+ `#{run} delete vhost name=#{vhost}` if vhost_exists? vhost
23
+ `#{run} declare vhost name=#{vhost}`
24
+ add_user_to_vhost vhost, @admin_user
25
+ end
26
+
27
+ def run vhost = nil
28
+ vhost_arg = vhost.nil? ? '' : "-V #{vhost}"
29
+
30
+ "rabbitmqadmin -u #{@admin_user} -p #{@admin_password} -f raw_json #{vhost_arg}"
31
+ end
32
+
33
+ def list_bindings vhost
34
+ parse `#{run vhost} list bindings`
35
+ end
36
+
37
+ def list_exchanges vhost
38
+ parse `#{run vhost} list exchanges`
39
+ end
40
+
41
+ def list_queues vhost
42
+ parse `#{run vhost} list queues`
43
+ end
44
+
45
+ def list_users
46
+ parse `#{run} list users`
47
+ end
48
+
49
+ def list_vhosts
50
+ parse `#{run} list vhosts`
51
+ end
52
+
53
+ def purge_queues
54
+ list_queues.each { |queue| `#{run vhost} purge queue name=#{queue[:name]}` }
55
+ end
56
+
57
+ def user_exists? user
58
+ list_users.any? { |u| u[:name] == user }
59
+ end
60
+
61
+ def vhost_exists? vhost
62
+ list_vhosts.any? { |h| h[:name] == vhost }
63
+ end
64
+
65
+ private
66
+
67
+ def parse json
68
+ JSON.parse json, :symbolize_names => true
69
+ end
70
+
71
+ def add_user_to_vhost vhost, user
72
+ `#{run} -V #{vhost} declare permission vhost=#{vhost} user=#{user} configure=\"\.\*\" write=\"\.\*\" read=\"\.\*\"`
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module RabbitMqAdminCli
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'rabbitmqadmin-cli'
3
+ s.version = '1.0.0'
4
+ s.platform = Gem::Platform::RUBY
5
+ s.authors = ['Lee Henson', 'Guy Boertje']
6
+ s.email = ['lee.m.henson@gmail.com', 'guyboertje@gmail.com']
7
+ s.summary = %q{Ruby wrapper for calling out the rabbitmqadmin cli script}
8
+ s.description = "Requires rabbitmqadmin to be in your path"
9
+ s.homepage = 'http://github.com/leemhenson/rabbitmqadmin-cli'
10
+
11
+ # = MANIFEST =
12
+ s.files = %w[
13
+ Gemfile
14
+ Rakefile
15
+ lib/rabbitmqadmin-cli.rb
16
+ lib/rabbitmqadmin-cli/version.rb
17
+ rabbitmqadmin-cli.gemspec
18
+ ]
19
+ # = MANIFEST =
20
+
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+
24
+ s.add_dependency 'json'
25
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbitmqadmin-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lee Henson
9
+ - Guy Boertje
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-09-27 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ requirement: &70181339511660 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70181339511660
26
+ description: Requires rabbitmqadmin to be in your path
27
+ email:
28
+ - lee.m.henson@gmail.com
29
+ - guyboertje@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - Rakefile
36
+ - lib/rabbitmqadmin-cli.rb
37
+ - lib/rabbitmqadmin-cli/version.rb
38
+ - rabbitmqadmin-cli.gemspec
39
+ homepage: http://github.com/leemhenson/rabbitmqadmin-cli
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.10
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Ruby wrapper for calling out the rabbitmqadmin cli script
63
+ test_files: []