rabbitmqadmin-cli 1.0.1-java
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.
- data/Gemfile +2 -0
- data/Rakefile +154 -0
- data/lib/rabbitmqadmin-cli/version.rb +3 -0
- data/lib/rabbitmqadmin-cli.rb +78 -0
- data/rabbitmqadmin-cli.gemspec +29 -0
- metadata +66 -0
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -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,78 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class RabbitMqAdminCli
|
4
|
+
def initialize admin_user = 'guest', admin_password = 'guest'
|
5
|
+
@admin_user = admin_user
|
6
|
+
@admin_password = admin_password
|
7
|
+
end
|
8
|
+
|
9
|
+
def delete_exchanges
|
10
|
+
list_exchanges.each { |exchange| `#{run vhost} delete exchange name=#{exchange[:name]}` }
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_queues
|
14
|
+
list_queues.each { |queue| `#{run vhost} delete queue name=#{queue[:name]}` }
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize_user vhost, user, password, tags = ''
|
18
|
+
raise "Can't initialize the admin user '#{user}' without crippling your access" if user == @admin_user
|
19
|
+
|
20
|
+
`#{run} delete user name=#{user}` if user_exists? user
|
21
|
+
`#{run} declare user name=#{user} password=#{password} tags=#{tags}`
|
22
|
+
add_user_to_vhost vhost, user
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize_vhost vhost
|
26
|
+
`#{run} delete vhost name=#{vhost}` if vhost_exists? vhost
|
27
|
+
`#{run} declare vhost name=#{vhost}`
|
28
|
+
add_user_to_vhost vhost, @admin_user
|
29
|
+
end
|
30
|
+
|
31
|
+
def run vhost = nil
|
32
|
+
vhost_arg = vhost.nil? ? '' : "-V #{vhost}"
|
33
|
+
|
34
|
+
"rabbitmqadmin -u #{@admin_user} -p #{@admin_password} -f raw_json #{vhost_arg}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def list_bindings vhost
|
38
|
+
parse `#{run vhost} list bindings`
|
39
|
+
end
|
40
|
+
|
41
|
+
def list_exchanges vhost
|
42
|
+
parse `#{run vhost} list exchanges`
|
43
|
+
end
|
44
|
+
|
45
|
+
def list_queues vhost
|
46
|
+
parse `#{run vhost} list queues`
|
47
|
+
end
|
48
|
+
|
49
|
+
def list_users
|
50
|
+
parse `#{run} list users`
|
51
|
+
end
|
52
|
+
|
53
|
+
def list_vhosts
|
54
|
+
parse `#{run} list vhosts`
|
55
|
+
end
|
56
|
+
|
57
|
+
def purge_queues
|
58
|
+
list_queues.each { |queue| `#{run vhost} purge queue name=#{queue[:name]}` }
|
59
|
+
end
|
60
|
+
|
61
|
+
def user_exists? user
|
62
|
+
list_users.any? { |u| u[:name] == user }
|
63
|
+
end
|
64
|
+
|
65
|
+
def vhost_exists? vhost
|
66
|
+
list_vhosts.any? { |h| h[:name] == vhost }
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def parse json
|
72
|
+
JSON.parse json, :symbolize_names => true
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_user_to_vhost vhost, user
|
76
|
+
`#{run} -V #{vhost} declare permission vhost=#{vhost} user=#{user} configure=\"\.\*\" write=\"\.\*\" read=\"\.\*\"`
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'rabbitmqadmin-cli'
|
3
|
+
s.version = '1.0.1'
|
4
|
+
s.platform = RUBY_PLATFORM.to_s == 'java' ? 'java' : 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
|
+
if RUBY_PLATFORM.to_s == 'java'
|
25
|
+
s.add_dependency 'json-jruby'
|
26
|
+
else
|
27
|
+
s.add_dependency 'json'
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rabbitmqadmin-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.1
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- Lee Henson
|
9
|
+
- Guy Boertje
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-09-28 00:00:00.000000000 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: json-jruby
|
18
|
+
version_requirements: &2172 !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
none: false
|
24
|
+
requirement: *2172
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
description: Requires rabbitmqadmin to be in your path
|
28
|
+
email:
|
29
|
+
- lee.m.henson@gmail.com
|
30
|
+
- guyboertje@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- Gemfile
|
36
|
+
- Rakefile
|
37
|
+
- lib/rabbitmqadmin-cli.rb
|
38
|
+
- lib/rabbitmqadmin-cli/version.rb
|
39
|
+
- rabbitmqadmin-cli.gemspec
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/leemhenson/rabbitmqadmin-cli
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
none: false
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
none: false
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.5.1
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Ruby wrapper for calling out the rabbitmqadmin cli script
|
65
|
+
test_files: []
|
66
|
+
...
|