stormmq-client 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010, Tony Byrne & StormMQ Ltd.
2
+ All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1 @@
1
+ === Client for StormMQ's Cloud Messaging Service.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ #--
2
+ # Copyright (c) 2010, Tony Byrne & StormMQ Ltd.
3
+ # All rights reserved.
4
+ #
5
+ # Please refer to the LICENSE file that accompanies this source
6
+ # for terms of use and redistribution.
7
+ #++
8
+
9
+ require 'rake'
10
+ require 'spec/rake/spectask'
11
+
12
+ Spec::Rake::SpecTask.new(:spec) do |t|
13
+ t.spec_files = FileList['spec/**/*_spec.rb']
14
+ t.spec_opts = ['--colour','--format progress']
15
+ t.rcov = true
16
+ t.rcov_opts = ['--exclude "spec/*,gems/*"']
17
+ end
18
+
19
+ task :default => :spec
data/TODO ADDED
@@ -0,0 +1,11 @@
1
+ * Implement Windows support / Windows GEM.
2
+
3
+ * stormmq-create-system: implement template reading from file
4
+
5
+ * Test proxy support
6
+
7
+ * SSL certificate support
8
+
9
+ * Refactor REST methods
10
+
11
+ * Tests and coverage.
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #--
4
+ # Copyright (c) 2010, Tony Byrne & StormMQ Ltd.
5
+ # All rights reserved.
6
+ #
7
+ # Please refer to the LICENSE file that accompanies this source
8
+ # for terms of use and redistribution.
9
+ #++
10
+
11
+ $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
12
+
13
+ require 'stormmq/amqp'
14
+ require 'stormmq/application'
15
+
16
+ class StormMQ::Application::AMQPEchoTest < StormMQ::Application
17
+
18
+ def initialize
19
+ synopsis "--help | --company <companyName> --system <systemName> --environment <environmentName> --amqpUser <amqpUserName> --amqpPassword <amqpUserPassword> [--host <host>] [--port <port>] [--debug]"
20
+ options :help, :debug
21
+
22
+ option :names => %w(--host),
23
+ :opt_description => "server to connect to - defaults to 'amqp.stormmq.com'",
24
+ :arity => [1,1],
25
+ :opt_found => get_args,
26
+ :opt_not_found => 'amqp.stormmq.com'
27
+
28
+ option :names => %w(--port),
29
+ :opt_description => "SSL port on server to connect to - defaults to '443'",
30
+ :arity => [1,1],
31
+ :opt_found => get_args,
32
+ :opt_not_found => '443'
33
+
34
+ option :names => %w(--amqpUser -u),
35
+ :opt_description => "a valid user name, i.e. the login you use at http://stormmq.com/",
36
+ :arity => [1,1],
37
+ :opt_found => get_args,
38
+ :opt_not_found => CommandLine::OptionParser::OPT_NOT_FOUND_BUT_REQUIRED
39
+
40
+ option :names => %w(--amqpPassword -p),
41
+ :opt_description => "Base64 encoded password, e.g. 'BNuWk1agaAUPTZ15sx44kHvNkTnJXsevqTjIo1M1iwFOeNaUqr3qPn75Dnk=='",
42
+ :arity => [1,1],
43
+ :opt_found => get_args,
44
+ :opt_not_found => CommandLine::OptionParser::OPT_NOT_FOUND_BUT_REQUIRED
45
+
46
+ option :names => %w(--company -c),
47
+ :opt_description => "your company identifier, usually the same as --amqpUser",
48
+ :arity => [1,1],
49
+ :opt_found => get_args,
50
+ :opt_not_found => CommandLine::OptionParser::OPT_NOT_FOUND_BUT_REQUIRED
51
+
52
+ option :names => %w(--system -s),
53
+ :opt_description => "your system, usually the same as --amqpUser",
54
+ :arity => [1,1],
55
+ :opt_found => get_args,
56
+ :opt_not_found => CommandLine::OptionParser::OPT_NOT_FOUND_BUT_REQUIRED
57
+
58
+ option :names => %w(--environment -e),
59
+ :opt_description => "the environment to use, e.g 'production', 'development', or 'testing'",
60
+ :arity => [1,1],
61
+ :opt_found => get_args,
62
+ :opt_not_found => CommandLine::OptionParser::OPT_NOT_FOUND_BUT_REQUIRED
63
+
64
+ end
65
+
66
+ def main
67
+
68
+ EM.run do
69
+
70
+ puts "creating connection"
71
+ connection = StormMQ::AMQPClient.connect(
72
+ :user => opt.amqpUser,
73
+ :password => opt.amqpPassword,
74
+ :company => opt.company,
75
+ :system => opt.system,
76
+ :environment => opt.environment,
77
+ :host => opt.host,
78
+ :port => opt.port,
79
+ :logging => opt['--debug']
80
+ )
81
+
82
+ puts "opening a channel on the A MQP connection"
83
+ channel = MQ.new(connection)
84
+
85
+ puts "declaring a queue on the channel"
86
+ queue = MQ::Queue.new(channel, 'test queue')
87
+
88
+ puts "creating a test exchange"
89
+ exchange = MQ::Exchange.new(channel, :direct, 'test exchange')
90
+
91
+ puts "binding the queue the the exchange"
92
+ queue.bind(exchange)
93
+
94
+ puts "publishing test message to the exchange"
95
+ exchange.publish('hello world')
96
+
97
+ puts "subsribing to the queue"
98
+ queue.subscribe do |headers, msg|
99
+ puts "recevied message from the queue:"
100
+ pp headers
101
+ puts msg
102
+ puts msg == 'hello world' ? 'Succeeded' : 'Failed'
103
+ connection.close{ EM.stop_event_loop }
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+
110
+ def man
111
+ <<-EOM
112
+ NAME
113
+
114
+ #{File.basename(__FILE__)}
115
+
116
+ PURPOSE
117
+
118
+ Tests connections to our AMQP servers (default: amqp.stormmq.com)
119
+ to try to troubleshoot problems with users, passwords and SSL.
120
+
121
+ USAGE
122
+
123
+ #{File.basename(__FILE__)} --help
124
+ #{File.basename(__FILE__)} --company <companyName> --system <systemName> --environment <environmentName> --amqpUser <amqpUserName> --amqpPassword <amqpUserPassword>
125
+
126
+ PARAMETERS
127
+
128
+ <systemName>
129
+
130
+ If you're not sure if you've already created a system, use:
131
+
132
+ stormmq-list-systems <userName>
133
+
134
+ Note: A systemName can not contain a '/' or ':'
135
+
136
+ <companyName>
137
+
138
+ For ordinary users, this is the same as your userName. If you're
139
+ not sure of your companyName, you can retrieve it with:
140
+
141
+ stormmq-list-companies <userName>
142
+
143
+ <environmentName>
144
+
145
+ One of:
146
+
147
+ * development
148
+ * testing
149
+ * production
150
+
151
+ for the default system created when you signed up, or for any
152
+ system created by stormmq-create-system <userName>
153
+ (except advanced use).
154
+
155
+ <amqpUserName>
156
+
157
+ This is your userName for the default system we created when you
158
+ signed up, or for any system created by
159
+ stormmq-create-system <userName> (except advanced use).
160
+
161
+ <amqpUserPassword>
162
+
163
+ Retrieve this using:
164
+
165
+ stormmq-get-amqpuser-password <userName> <companyName> <systemName> \\
166
+ <environmentName> <amqpUserName>
167
+
168
+ --help, -h
169
+
170
+ Displays this help page then quits.
171
+
172
+ --debug, -d
173
+
174
+ Display dialogue between client and server.
175
+
176
+ --host
177
+
178
+ Specify the amqp server to connect to. Defaults to:
179
+
180
+ amqp.stormmq.com
181
+
182
+ --port
183
+
184
+ Specify the port on the amqp server to connect to.
185
+
186
+ RESULT
187
+
188
+ Outputs test results to STDOUT.
189
+
190
+ NOTES
191
+
192
+ For a default system, you'll just need your userName.
193
+
194
+ COPYRIGHT
195
+
196
+ Copyright (c) 2010, Tony Byrne & StormMQ Ltd.
197
+ All rights reserved.
198
+
199
+ EOM
200
+ end
201
+
202
+ end
203
+
204
+ StormMQ::Application::AMQPEchoTest.run
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #--
4
+ # Copyright (c) 2010, Tony Byrne & StormMQ Ltd.
5
+ # All rights reserved.
6
+ #
7
+ # Please refer to the LICENSE file that accompanies this source
8
+ # for terms of use and redistribution.
9
+ #++
10
+
11
+ $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
12
+
13
+ require 'stormmq/application'
14
+
15
+ class StormMQ::Application::CreateSystem < StormMQ::Application
16
+
17
+ def initialize
18
+ synopsis "--help | <userName> | <userName> <systemName> | <userName> <systemName> <companyName>"
19
+ options :help
20
+ expected_args [1,4]
21
+ end
22
+
23
+ def main
24
+ user = argv[0]
25
+ system = argv[1] || user
26
+ company = argv[2] || user
27
+ template = argv[3]
28
+
29
+ if template
30
+ json = read_template(template)
31
+ else
32
+ json = default_template(user, company, system)
33
+ end
34
+
35
+ self.rest_client(user).create_system(company, system, json)
36
+ end
37
+
38
+ def read_template(path)
39
+ IO.read(path)
40
+ end
41
+
42
+ def default_template(user, company, system)
43
+ <<-EOT
44
+ {
45
+ "companyName" : "#{user}",
46
+ "systemName" : "#{system}",
47
+ "environments" :
48
+ [
49
+ {
50
+ "environmentName" : "development",
51
+ "clusterName" : "free-1",
52
+ "permittedStormMQUserNames" :
53
+ [
54
+ "#{user}"
55
+ ]
56
+ },
57
+ {
58
+ "environmentName" : "testing",
59
+ "clusterName" : "free-1",
60
+ "permittedStormMQUserNames" :
61
+ [
62
+ "#{user}"
63
+ ]
64
+ },
65
+ {
66
+ "environmentName" : "production",
67
+ "clusterName" : "free-1",
68
+ "permittedStormMQUserNames" :
69
+ [
70
+ "#{user}"
71
+ ]
72
+ }
73
+ ],
74
+ "amqpUserPermissions" :
75
+ {
76
+ "#{user}" :
77
+ {
78
+ "create" : ".*",
79
+ "read" : ".*",
80
+ "write" : ".*"
81
+ }
82
+ }
83
+ }
84
+ EOT
85
+ end
86
+
87
+ def man
88
+ <<-EOM
89
+ NAME
90
+
91
+ #{File.basename(__FILE__)}
92
+
93
+ PURPOSE
94
+
95
+ A system is a logical view of resources in our Messaging Cloud.
96
+ Typically you'd only need one system, eg 'AccountRocks',
97
+ 'InflationSwapCalculator', 'Jibbit-X', etc. A system has
98
+ environments.
99
+
100
+ A company-system-environment triplet matches an AMQP Virtual Host.
101
+ E.g., if your company is widgetcorp, your system is accountrock
102
+ and you want to use an environment of development, your AMQP
103
+ virtual host name is widgetcorp/accountrock/development.
104
+
105
+ If you've just signed up as an ordinary user, then we've already
106
+ created a system called <userName>for you (see stormmq-list-systems),
107
+ with an AMQP virtual host called /<userName>/<userName>/development,
108
+ accessible at amqp.stormmq.com
109
+
110
+ All AMQP virtual hosts are virtually hosted on
111
+ amqp.stormmq.com.
112
+
113
+ To find the passwords to log onto them with AMQP, use
114
+ stormmq-get-amqpuser-password.
115
+
116
+ USAGE
117
+
118
+ #{File.basename(__FILE__)} --help
119
+ #{File.basename(__FILE__)} <userName>
120
+ #{File.basename(__FILE__)} <userName> <systemName>
121
+ #{File.basename(__FILE__)} <userName> <systemName> <companyName>
122
+ #{File.basename(__FILE__)} <userName> <systemName> <companyName> </path/to/json/template>
123
+
124
+ The second form assumes your companyName and systemName is the same
125
+ as your userName. This is true for ordinary users who've just
126
+ signed up.
127
+
128
+ The third form assumes your companyName is the same as your
129
+ userName. This is true for ordinary users.
130
+
131
+ The fifth form is for advanced use only.
132
+
133
+ PARAMETERS
134
+
135
+ <userName>
136
+
137
+ The user name you log into the site with.
138
+
139
+ <systemName>
140
+
141
+ If you're not sure if you've already created a system, use:
142
+
143
+ stormmq-list-systems <userName>
144
+
145
+ A systemName can not contain a '/' or ':'
146
+
147
+ <companyName>
148
+
149
+ For ordinary users, this is the same as your userName. If you're
150
+ not sure of your companyName, you can retrieve it with:
151
+
152
+ stormmq-list-companies <userName>
153
+
154
+ </path/to/json/template>
155
+
156
+ This is a template used to create a system. Use this to create
157
+ systems with:
158
+
159
+ * Environments using contended or dedicated clusters.
160
+ * Multiple AMQP users.
161
+ * Restrictions on whom can access production passwords.
162
+ * Bespoke per-queue or per-exchange permissions.
163
+
164
+ Environment variables will be substituted in the template
165
+ (specified using ${<NAME>}). If using strings you'll need to
166
+ make sure they are properly JSON escaped.
167
+
168
+ --help, -h
169
+
170
+ Displays this help page then quits.
171
+
172
+ RESULT
173
+
174
+ Outputs a simple JSON object if accepted, or nothing if the system
175
+ already exists with identical settings
176
+
177
+ REST API
178
+
179
+ Equivalent is PUT /companies/<companyName>/<systemName>.
180
+
181
+ NOTES
182
+
183
+ If the system already exists with a different set up, then resources
184
+ will be created, modified and destroyed as needed. Be careful!
185
+
186
+ If using the advanced form, note that your companyName and systemName
187
+ on the command line must match the values used in the JSON template.
188
+
189
+ To find you companyName, use:
190
+
191
+ stormmq-list-companies
192
+
193
+ To delete your default system, use:
194
+
195
+ stormmq-delete-system <userName>
196
+
197
+ COPYRIGHT
198
+
199
+ Copyright (c) 2010, Tony Byrne & StormMQ Ltd.
200
+ All rights reserved.
201
+
202
+ SELF TEST
203
+
204
+ #{self_test}
205
+
206
+ EOM
207
+ end
208
+
209
+ end
210
+
211
+ StormMQ::Application::CreateSystem.run