mu 5.7.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Mu_Gem.html +1591 -0
- data/bin/mu +11 -0
- data/lib/mu.rb +65 -0
- data/lib/mu/api/ddt.rb +233 -0
- data/lib/mu/api/homepage.rb +54 -0
- data/lib/mu/api/muapi.rb +231 -0
- data/lib/mu/api/netconfig.rb +233 -0
- data/lib/mu/api/scale.rb +199 -0
- data/lib/mu/api/system.rb +40 -0
- data/lib/mu/client.rb +31 -0
- data/lib/mu/command.rb +28 -0
- data/lib/mu/command/api.rb +95 -0
- data/lib/mu/command/cmd_appid.rb +486 -0
- data/lib/mu/command/cmd_cli.rb +151 -0
- data/lib/mu/command/cmd_ddt.rb +449 -0
- data/lib/mu/command/cmd_homepage.rb +146 -0
- data/lib/mu/command/cmd_muapi.rb +361 -0
- data/lib/mu/command/cmd_netconfig.rb +262 -0
- data/lib/mu/command/cmd_runscale.rb +533 -0
- data/lib/mu/command/cmd_runscenario.rb +258 -0
- data/lib/mu/command/cmd_runverify.rb +336 -0
- data/lib/mu/command/cmd_scale.rb +333 -0
- data/lib/mu/command/cmd_system.rb +127 -0
- data/lib/mu/command/curl.rb +246 -0
- data/lib/mu/command/help.rb +29 -0
- data/lib/mu/curl/error.rb +54 -0
- data/lib/mu/curl/verify.rb +137 -0
- data/lib/mu/helper.rb +55 -0
- data/lib/mu/http_helper.rb +232 -0
- data/rdoc/classes/Mu.html +305 -0
- data/rdoc/classes/Mu/Client.html +265 -0
- data/rdoc/classes/Mu/Command.html +208 -0
- data/rdoc/classes/Mu/Command/API.html +524 -0
- data/rdoc/classes/Mu/Command/Cmd_appid.html +934 -0
- data/rdoc/classes/Mu/Command/Cmd_cli.html +515 -0
- data/rdoc/classes/Mu/Command/Cmd_ddt.html +1169 -0
- data/rdoc/classes/Mu/Command/Cmd_homepage.html +489 -0
- data/rdoc/classes/Mu/Command/Cmd_muapi.html +968 -0
- data/rdoc/classes/Mu/Command/Cmd_netconfig.html +743 -0
- data/rdoc/classes/Mu/Command/Cmd_runscale.html +970 -0
- data/rdoc/classes/Mu/Command/Cmd_runscenario.html +530 -0
- data/rdoc/classes/Mu/Command/Cmd_runverify.html +621 -0
- data/rdoc/classes/Mu/Command/Cmd_scale.html +939 -0
- data/rdoc/classes/Mu/Command/Cmd_system.html +426 -0
- data/rdoc/classes/Mu/Command/Curl.html +524 -0
- data/rdoc/classes/Mu/Command/Help.html +166 -0
- data/rdoc/classes/Mu/Curl.html +116 -0
- data/rdoc/classes/Mu/Curl/Error.html +157 -0
- data/rdoc/classes/Mu/Curl/Error/Authorize.html +178 -0
- data/rdoc/classes/Mu/Curl/Error/Connect.html +149 -0
- data/rdoc/classes/Mu/Curl/Error/DNS.html +113 -0
- data/rdoc/classes/Mu/Curl/Error/Region.html +160 -0
- data/rdoc/classes/Mu/Curl/Error/Status.html +149 -0
- data/rdoc/classes/Mu/Curl/Error/Timeout.html +149 -0
- data/rdoc/classes/Mu/Curl/Verify.html +282 -0
- data/rdoc/classes/Mu/Curl/Verify/Request.html +227 -0
- data/rdoc/classes/Mu/Curl/Verify/Response.html +187 -0
- data/rdoc/classes/Mu/Curl/Verify/Result.html +188 -0
- data/rdoc/classes/Mu/Ddt.html +914 -0
- data/rdoc/classes/Mu/Helper.html +308 -0
- data/rdoc/classes/Mu/Homepage.html +377 -0
- data/rdoc/classes/Mu/HttpHelper.html +639 -0
- data/rdoc/classes/Mu/Muapi.html +816 -0
- data/rdoc/classes/Mu/Netconfig.html +781 -0
- data/rdoc/classes/Mu/Scale.html +832 -0
- data/rdoc/classes/Mu/System.html +281 -0
- data/rdoc/classes/Object.html +148 -0
- data/rdoc/classes/TCTestMu.html +1793 -0
- data/rdoc/classes/Test.html +107 -0
- data/rdoc/classes/Test/Unit.html +107 -0
- data/rdoc/classes/Test/Unit/TestCase.html +113 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/lib/mu/api/ddt_rb.html +101 -0
- data/rdoc/files/lib/mu/api/homepage_rb.html +101 -0
- data/rdoc/files/lib/mu/api/muapi_rb.html +101 -0
- data/rdoc/files/lib/mu/api/netconfig_rb.html +101 -0
- data/rdoc/files/lib/mu/api/scale_rb.html +101 -0
- data/rdoc/files/lib/mu/api/system_rb.html +101 -0
- data/rdoc/files/lib/mu/client_rb.html +101 -0
- data/rdoc/files/lib/mu/command/api_rb.html +101 -0
- data/rdoc/files/lib/mu/command/cmd_appid_rb.html +119 -0
- data/rdoc/files/lib/mu/command/cmd_cli_rb.html +108 -0
- data/rdoc/files/lib/mu/command/cmd_ddt_rb.html +117 -0
- data/rdoc/files/lib/mu/command/cmd_homepage_rb.html +115 -0
- data/rdoc/files/lib/mu/command/cmd_muapi_rb.html +116 -0
- data/rdoc/files/lib/mu/command/cmd_netconfig_rb.html +116 -0
- data/rdoc/files/lib/mu/command/cmd_runscale_rb.html +119 -0
- data/rdoc/files/lib/mu/command/cmd_runscenario_rb.html +115 -0
- data/rdoc/files/lib/mu/command/cmd_runverify_rb.html +117 -0
- data/rdoc/files/lib/mu/command/cmd_scale_rb.html +115 -0
- data/rdoc/files/lib/mu/command/cmd_system_rb.html +116 -0
- data/rdoc/files/lib/mu/command/curl_rb.html +101 -0
- data/rdoc/files/lib/mu/command/help_rb.html +101 -0
- data/rdoc/files/lib/mu/command_rb.html +107 -0
- data/rdoc/files/lib/mu/curl/error_rb.html +101 -0
- data/rdoc/files/lib/mu/curl/verify_rb.html +101 -0
- data/rdoc/files/lib/mu/helper_rb.html +101 -0
- data/rdoc/files/lib/mu/http_helper_rb.html +101 -0
- data/rdoc/files/lib/mu_rb.html +121 -0
- data/rdoc/files/test/helper_rb.html +112 -0
- data/rdoc/files/test/tc_test_mu_rb.html +111 -0
- data/rdoc/fr_class_index.html +68 -0
- data/rdoc/fr_file_index.html +55 -0
- data/rdoc/fr_method_index.html +374 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/test/data/app_id_stats.csv +1 -0
- data/test/data/data_cgi.msl +94 -0
- data/test/data/data_cgi.xml +322 -0
- data/test/data/default_test.csv +3 -0
- data/test/data/ftp_with_channel.xml +1643 -0
- data/test/data/irc.xml +3837 -0
- data/test/data/scale_configuration.json +25 -0
- data/test/data/test_data_cgi_error.xml +35 -0
- data/test/helper.rb +18 -0
- data/test/tc_test_mu.rb +716 -0
- metadata +322 -0
@@ -0,0 +1,246 @@
|
|
1
|
+
class Mu
|
2
|
+
class Command
|
3
|
+
class Curl < Command
|
4
|
+
def cmd_help argv
|
5
|
+
help
|
6
|
+
end
|
7
|
+
|
8
|
+
def authorize_error e
|
9
|
+
base_url = "#{e.scheme}://#{e.host}:#{e.port}"
|
10
|
+
puts
|
11
|
+
error "You haven't verified that you are the dev/ops for #{e.host}"
|
12
|
+
puts
|
13
|
+
end
|
14
|
+
|
15
|
+
def cmd_run argv
|
16
|
+
args = parse_cli argv
|
17
|
+
if args['help']
|
18
|
+
return help
|
19
|
+
end
|
20
|
+
|
21
|
+
if not args['pattern']
|
22
|
+
verify args
|
23
|
+
return
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :cmd_default, :cmd_run
|
28
|
+
|
29
|
+
private
|
30
|
+
def verify args
|
31
|
+
begin
|
32
|
+
job = ::Mu::Curl::Verify.execute args
|
33
|
+
result = job.result
|
34
|
+
print_verify_result args, result
|
35
|
+
rescue ::Mu::Curl::Error::Authorize => e
|
36
|
+
authorize_error e
|
37
|
+
rescue ::Mu::Curl::Error::Region => e
|
38
|
+
error "#{e.region}: #{e.message}"
|
39
|
+
rescue ::Mu::Curl::Error => e
|
40
|
+
error e.message
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def print_verify_result args, result
|
45
|
+
rtt = result.duration
|
46
|
+
if rtt < 1.0
|
47
|
+
rtt = (rtt * 1000).floor.to_s + ' ms';
|
48
|
+
else
|
49
|
+
rtt = ("%.2f" % rtt) + ' sec';
|
50
|
+
end
|
51
|
+
|
52
|
+
puts "-" * 70
|
53
|
+
msg "#{result.region}: Response time of #{rtt}"
|
54
|
+
puts "-" * 70
|
55
|
+
puts
|
56
|
+
|
57
|
+
if args['dump-header'] || args['verbose']
|
58
|
+
puts "> " + result.request.line
|
59
|
+
result.request.headers.each_pair { |k, v| puts "> #{k}: #{v}\r\n" }
|
60
|
+
puts
|
61
|
+
|
62
|
+
content = result.request.content
|
63
|
+
if not content.empty?
|
64
|
+
if /^[[:print:]]+$/ =~ content
|
65
|
+
puts content
|
66
|
+
else
|
67
|
+
puts Hexy.new(content).to_s
|
68
|
+
end
|
69
|
+
puts
|
70
|
+
end
|
71
|
+
|
72
|
+
puts "< " + result.response.line
|
73
|
+
result.response.headers.each_pair { |k, v| puts "> #{k}: #{v}\r\n" }
|
74
|
+
puts
|
75
|
+
end
|
76
|
+
|
77
|
+
content = result.response.content
|
78
|
+
if not content.empty?
|
79
|
+
if /^[[:print:]]+$/ =~ content
|
80
|
+
puts content
|
81
|
+
else
|
82
|
+
puts Hexy.new(content).to_s
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def help
|
88
|
+
helps = [
|
89
|
+
{ :short => '-A', :long => '--user-agent', :value => '<string>', :help => 'User-Agent to send to server' },
|
90
|
+
{ :short => '-b', :long => '--cookie', :value => 'name=<string>', :help => 'Cookie to send to the server (multiple)' },
|
91
|
+
{ :short => '-d', :long => '--data', :value => '<string>', :help => 'Data to send in a PUT or POST request' },
|
92
|
+
{ :short => '-D', :long => '--dump-header', :value => '<file>', :help => 'Print the request/response headers' },
|
93
|
+
{ :short => '-e', :long => '--referer', :value => '<string>', :help => 'Referer URL' },
|
94
|
+
{ :short => '-h', :long => '--help', :value => '', :help => 'Help on command line options' },
|
95
|
+
{ :short => '-H', :long => '--header', :value => '<string>', :help => 'Custom header to pass to server' },
|
96
|
+
{ :short => '-p', :long => '--pattern', :value => '<s>-<e>:<d>', :help => 'Ramp from s to e concurrent requests in d secs' },
|
97
|
+
{ :short => '-r', :long => '--region', :value => '<string>', :help => 'Choose one of us-east or us-west' },
|
98
|
+
{ :short => '-s', :long => '--status', :value => '<number>', :help => 'Assert on the HTTP response status code' },
|
99
|
+
{ :short => '-T', :long => '--timeout', :value => '<ms>', :help => 'Wait time for both connect and responses' },
|
100
|
+
{ :short => '-u', :long => '--user', :value => '<user[:pass]>', :help => 'User and password for authentication' },
|
101
|
+
{ :short => '-X', :long => '--request', :value => '<string>', :help => 'Request method to use (GET, HEAD, PUT, etc.)' },
|
102
|
+
{ :short => '-v', :long => '--verbose', :value => '', :help => 'Print the request/response headers' },
|
103
|
+
{ :short => '-1', :long => '--tlsv1', :value => '', :help => 'Use TLSv1 (SSL)' },
|
104
|
+
{ :short => '-2', :long => '--sslv2', :value => '', :help => 'Use SSLv2 (SSL)' },
|
105
|
+
{ :short => '-3', :long => '--sslv3', :value => '', :help => 'Use SSLv3 (SSL)' }
|
106
|
+
]
|
107
|
+
|
108
|
+
max_long_size = helps.inject(0) { |memo, obj| [ obj[:long].size, memo ].max }
|
109
|
+
max_value_size = helps.inject(0) { |memo, obj| [ obj[:value].size, memo ].max }
|
110
|
+
puts
|
111
|
+
msg "Usage: mu curl <options> <url>"
|
112
|
+
puts
|
113
|
+
helps.each do |h|
|
114
|
+
msg "%-*s %*s %-*s %s" % [max_long_size, h[:long], 2, h[:short], max_value_size, h[:value], h[:help]]
|
115
|
+
end
|
116
|
+
puts
|
117
|
+
end
|
118
|
+
|
119
|
+
def parse_cli argv
|
120
|
+
hash = Hash.new
|
121
|
+
while not argv.empty?
|
122
|
+
break if argv.first[0,1] != '-'
|
123
|
+
|
124
|
+
k = argv.shift
|
125
|
+
if [ '-A', '--user-agent' ].member? k
|
126
|
+
hash['user-agent'] = shift(k, argv)
|
127
|
+
next
|
128
|
+
end
|
129
|
+
|
130
|
+
if [ '-b', '--cookie' ].member? k
|
131
|
+
# TODO: support cookie jars
|
132
|
+
hash['cookies'] ||= []
|
133
|
+
hash['cookies'] << shift(k, argv)
|
134
|
+
next
|
135
|
+
end
|
136
|
+
|
137
|
+
if [ '-d', '--data' ].member? k
|
138
|
+
# TODO: Read from a file using the @syntax
|
139
|
+
hash['content'] ||= Hash.new
|
140
|
+
hash['content']['data'] ||= []
|
141
|
+
hash['content']['data'] << shift(k, argv)
|
142
|
+
next
|
143
|
+
end
|
144
|
+
|
145
|
+
if [ '-D', '--dump-header' ].member? k
|
146
|
+
hash['dump-header'] = shift(k, argv)
|
147
|
+
next
|
148
|
+
end
|
149
|
+
|
150
|
+
if [ '-e', '--referer'].member? k
|
151
|
+
hash['referer'] = shift(k, argv)
|
152
|
+
next
|
153
|
+
end
|
154
|
+
|
155
|
+
if [ '-h', '--help' ].member? k
|
156
|
+
hash['help'] = true
|
157
|
+
next
|
158
|
+
end
|
159
|
+
|
160
|
+
if [ '-H', '--header' ].member? k
|
161
|
+
hash['headers'] ||= []
|
162
|
+
hash['headers'].push shift(k, argv)
|
163
|
+
next
|
164
|
+
end
|
165
|
+
|
166
|
+
if [ '-p', '--pattern' ].member? k
|
167
|
+
v = shift(k, argv)
|
168
|
+
if not /^(\d+)-(\d+):(\d+)$/ =~ v
|
169
|
+
raise "invalid ramp pattern"
|
170
|
+
end
|
171
|
+
hash['pattern'] = {
|
172
|
+
'iterations' => 1,
|
173
|
+
'intervals' => [{
|
174
|
+
'iterations' => 1,
|
175
|
+
'start' => $1.to_i,
|
176
|
+
'end' => $2.to_i,
|
177
|
+
'duration' => $3.to_i
|
178
|
+
}]
|
179
|
+
}
|
180
|
+
next
|
181
|
+
end
|
182
|
+
|
183
|
+
if [ '-r', '--region' ].member? k
|
184
|
+
v = shift(k, argv)
|
185
|
+
if !v.include?("us-west") and !v.include?("us-east")
|
186
|
+
raise 'region must be one of us-west or us-east'
|
187
|
+
end
|
188
|
+
hash['region'] = v
|
189
|
+
next
|
190
|
+
end
|
191
|
+
|
192
|
+
if [ '-s', '--status' ].member? k
|
193
|
+
hash['status'] = shift(k, argv).to_i
|
194
|
+
next
|
195
|
+
end
|
196
|
+
|
197
|
+
if [ '-T', '--timeout' ].member? k
|
198
|
+
hash['timeout'] = shift(k, argv).to_i
|
199
|
+
next
|
200
|
+
end
|
201
|
+
|
202
|
+
if [ '-u', '--user' ].member? k
|
203
|
+
hash['user'] = shift(k, argv)
|
204
|
+
next
|
205
|
+
end
|
206
|
+
|
207
|
+
if [ '-X', '--request' ].member? k
|
208
|
+
hash['request'] = shift(k, argv)
|
209
|
+
next
|
210
|
+
end
|
211
|
+
|
212
|
+
if [ '-v', '--verbose' ].member? k
|
213
|
+
hash['verbose'] = true
|
214
|
+
next
|
215
|
+
end
|
216
|
+
|
217
|
+
if [ '-1', '--tlsv1' ].member? k
|
218
|
+
hash['ssl'] = 'tlsv1'
|
219
|
+
next
|
220
|
+
end
|
221
|
+
|
222
|
+
if [ '-2', '--sslv2' ].member? k
|
223
|
+
hash['ssl'] = 'sslv2'
|
224
|
+
next
|
225
|
+
end
|
226
|
+
|
227
|
+
if [ '-3', '--sslv3' ].member? k
|
228
|
+
hash['ssl'] = 'sslv2'
|
229
|
+
next
|
230
|
+
end
|
231
|
+
|
232
|
+
raise ArgumentError, "Unknown option #{k}"
|
233
|
+
end
|
234
|
+
|
235
|
+
if not hash['help']
|
236
|
+
url = argv.shift
|
237
|
+
raise 'no URL specified!' if url.nil?
|
238
|
+
hash['url'] = url
|
239
|
+
end
|
240
|
+
|
241
|
+
hash
|
242
|
+
end
|
243
|
+
|
244
|
+
end # Curl
|
245
|
+
end # Command
|
246
|
+
end # Mu
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Mu
|
2
|
+
class Command
|
3
|
+
class Help < Command
|
4
|
+
def cmd_default argv
|
5
|
+
puts
|
6
|
+
puts "Usage: mu <command>:<option>"
|
7
|
+
helps = [
|
8
|
+
{ :cmd => 'mu help', :help => "Display this help" },
|
9
|
+
{ :cmd => 'mu cmd_appid:help', :help => 'Show help on using the appid application for running multi-host msl files at scale'},
|
10
|
+
{ :cmd => 'mu cmd_cli:help', :help => 'Show help on using the Mu CLI Api through the command-line' },
|
11
|
+
{ :cmd => 'mu cmd_ddt:help', :help => 'Show help on using the Studio Verify Api through the command-line' },
|
12
|
+
{ :cmd => 'mu cmd_homepage:help', :help => 'Show help on using the Homepage Api through the command-line' },
|
13
|
+
{ :cmd => 'mu cmd_muapi:help', :help => 'Show help on using the Mu Api for fuzzing, templates, backup and archive' },
|
14
|
+
{ :cmd => 'mu cmd_netconfig:help', :help => 'Show help on using the Netconfig Api through the command-line'},
|
15
|
+
{ :cmd => 'mu cmd_runscale:help', :help => 'Show help on running the Studio Scale app'},
|
16
|
+
{ :cmd => 'mu cmd_runscenario:help', :help => 'Show help on running the Scenario Editor Verify app' },
|
17
|
+
{ :cmd => 'mu cmd_runverify:help', :help => 'Show help on running the Studio Verify app' },
|
18
|
+
{ :cmd => 'mu cmd_scale:help', :help => 'Show help on using the Scale Api through the command-line' },
|
19
|
+
{ :cmd => 'mu cmd_system:help', :help => 'Show help on using the System Api through the command-line' },
|
20
|
+
]
|
21
|
+
max_cmd_size = helps.inject(0) { |memo, obj| [ obj[:cmd].size, memo ].max } + 4
|
22
|
+
helps.each do |h|
|
23
|
+
puts "%*s - %s" % [max_cmd_size, h[:cmd], h[:help]]
|
24
|
+
end
|
25
|
+
puts
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end # Command
|
29
|
+
end # Mu
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Mu
|
2
|
+
module Curl
|
3
|
+
class Error < StandardError
|
4
|
+
def initialize json={}
|
5
|
+
super json['reason'] || "Hmmm, something went wrong. Try again in a little bit?"
|
6
|
+
end
|
7
|
+
|
8
|
+
class Authorize < Error
|
9
|
+
attr_reader :scheme, :host, :port, :uuid
|
10
|
+
|
11
|
+
def initialize json
|
12
|
+
@scheme = json['scheme']
|
13
|
+
@host = json['host']
|
14
|
+
@port = json['port']
|
15
|
+
@uuid = json['uuid']
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Region < Error
|
21
|
+
attr_reader :region
|
22
|
+
|
23
|
+
def initialize json
|
24
|
+
@region = json['region']
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class DNS < Region
|
30
|
+
end
|
31
|
+
|
32
|
+
class Connect < Region
|
33
|
+
def initialize json
|
34
|
+
json['reason'] = "Can't connect to this server"
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Timeout < Region
|
40
|
+
def initialize json
|
41
|
+
json['reason'] = "Response timed out. Try increasing --timeout"
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Status < Region
|
47
|
+
def initialize json
|
48
|
+
json['reason'] = "Assertion on status failed"
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end # Curl
|
54
|
+
end # Mu
|
@@ -0,0 +1,137 @@
|
|
1
|
+
class Mu
|
2
|
+
module Curl
|
3
|
+
class Verify
|
4
|
+
class Request
|
5
|
+
def self.parse data
|
6
|
+
ios = StringIO.new data.unpack('m')[0]
|
7
|
+
rqrs = { :line => '', :headers => [], :content => '' }
|
8
|
+
while true
|
9
|
+
line = ios.readline
|
10
|
+
break if not line or line == "\r\n"
|
11
|
+
if rqrs[:line].empty?
|
12
|
+
rqrs[:line] = line.chomp
|
13
|
+
else
|
14
|
+
if /^([^:]+):(.*)/ =~ line
|
15
|
+
key = $1
|
16
|
+
val = $2.strip
|
17
|
+
rqrs[:headers] << { :line => line.chomp, :key => key, :val => val }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
rqrs[:content] = ios.read
|
23
|
+
return rqrs
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :line
|
27
|
+
attr_reader :method
|
28
|
+
attr_reader :url
|
29
|
+
attr_reader :headers
|
30
|
+
attr_reader :content
|
31
|
+
|
32
|
+
def initialize json
|
33
|
+
rq = Request.parse json['bytes'][0]['data']
|
34
|
+
@line = rq[:line]
|
35
|
+
@method, @url, _ = rq[:line].split(/\s+/, 3)
|
36
|
+
@content = rq[:content]
|
37
|
+
@headers = Hash.new
|
38
|
+
rq[:headers].each { |h| @headers[h[:key]] = h[:val] }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Response
|
43
|
+
attr_reader :line
|
44
|
+
attr_reader :status
|
45
|
+
attr_reader :message
|
46
|
+
attr_reader :headers
|
47
|
+
attr_reader :content
|
48
|
+
|
49
|
+
def initialize json
|
50
|
+
rs = Request.parse json['bytes'][1]['data']
|
51
|
+
@line = rs[:line]
|
52
|
+
_, @status, @message = rs[:line].split(/\s+/, 3)
|
53
|
+
@status = @status.to_i
|
54
|
+
@content = rs[:content]
|
55
|
+
@headers = Hash.new
|
56
|
+
rs[:headers].each { |h| @headers[h[:key]] = h[:val] }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Result
|
61
|
+
attr_reader :region
|
62
|
+
attr_reader :duration
|
63
|
+
attr_reader :connect
|
64
|
+
attr_reader :request
|
65
|
+
attr_reader :response
|
66
|
+
|
67
|
+
def initialize json
|
68
|
+
result = json['result']
|
69
|
+
stats = result['statistics']
|
70
|
+
|
71
|
+
@region = json['region']
|
72
|
+
@duration = stats['duration']['avg']
|
73
|
+
@connect = stats['steps'][0]['duration']['avg']
|
74
|
+
@request = Request.new result
|
75
|
+
@response = Response.new result
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.execute args
|
80
|
+
args.delete 'pattern'
|
81
|
+
|
82
|
+
res = Command::API.client.curl args
|
83
|
+
if res['error']
|
84
|
+
if res['error'] == 'authorize'
|
85
|
+
raise Error::Authorize.new(res)
|
86
|
+
else
|
87
|
+
raise Error.new(res)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
return self.new(res['job_id'])
|
92
|
+
end
|
93
|
+
|
94
|
+
attr_reader :job_id
|
95
|
+
|
96
|
+
def initialize job_id
|
97
|
+
@job_id = job_id
|
98
|
+
end
|
99
|
+
|
100
|
+
def result
|
101
|
+
while true
|
102
|
+
sleep 2.0
|
103
|
+
|
104
|
+
job = Command::API.client.job_status job_id
|
105
|
+
if job['error']
|
106
|
+
raise Error
|
107
|
+
end
|
108
|
+
|
109
|
+
result = job['result']
|
110
|
+
next if job['status'] == 'queued'
|
111
|
+
next if job['status'] == 'running' and not result
|
112
|
+
|
113
|
+
if result['error']
|
114
|
+
result['region'] = job['region']
|
115
|
+
if result['dns']
|
116
|
+
raise Error::DNS.new(result)
|
117
|
+
elsif result['step'] == 0
|
118
|
+
raise Error::Connect.new(result)
|
119
|
+
elsif result['step'] == 2
|
120
|
+
raise Error::Timeout.new(result)
|
121
|
+
elsif result['assert'] == 0
|
122
|
+
raise Error::Status.new(result)
|
123
|
+
else
|
124
|
+
raise Error
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
return Result.new(job)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def abort
|
133
|
+
Command::API.client.abort_job job_id rescue nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end # Curl
|
137
|
+
end # Mu
|