aws 1.11.8 → 1.11.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/awsbase/right_awsbase.rb +145 -141
- data/lib/right_aws.rb +1 -1
- metadata +3 -3
@@ -25,14 +25,14 @@
|
|
25
25
|
module RightAws
|
26
26
|
require 'digest/md5'
|
27
27
|
require 'pp'
|
28
|
-
|
28
|
+
|
29
29
|
class AwsUtils #:nodoc:
|
30
30
|
@@digest1 = OpenSSL::Digest::Digest.new("sha1")
|
31
31
|
@@digest256 = nil
|
32
32
|
if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00908000
|
33
33
|
@@digest256 = OpenSSL::Digest::Digest.new("sha256") rescue nil # Some installation may not support sha256
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def self.sign(aws_secret_access_key, auth_string)
|
37
37
|
Base64.encode64(OpenSSL::HMAC.digest(@@digest1, aws_secret_access_key, auth_string)).strip
|
38
38
|
end
|
@@ -93,11 +93,11 @@ module RightAws
|
|
93
93
|
end
|
94
94
|
|
95
95
|
# From Amazon's SQS Dev Guide, a brief description of how to escape:
|
96
|
-
# "URL encode the computed signature and other query parameters as specified in
|
97
|
-
# RFC1738, section 2.2. In addition, because the + character is interpreted as a blank space
|
98
|
-
# by Sun Java classes that perform URL decoding, make sure to encode the + character
|
96
|
+
# "URL encode the computed signature and other query parameters as specified in
|
97
|
+
# RFC1738, section 2.2. In addition, because the + character is interpreted as a blank space
|
98
|
+
# by Sun Java classes that perform URL decoding, make sure to encode the + character
|
99
99
|
# although it is not required by RFC1738."
|
100
|
-
# Avoid using CGI::escape to escape URIs.
|
100
|
+
# Avoid using CGI::escape to escape URIs.
|
101
101
|
# CGI::escape will escape characters in the protocol, host, and port
|
102
102
|
# sections of the URI. Only target chars in the query
|
103
103
|
# string should be escaped.
|
@@ -105,19 +105,19 @@ module RightAws
|
|
105
105
|
e = URI.escape(raw)
|
106
106
|
e.gsub(/\+/, "%2b")
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
def self.allow_only(allowed_keys, params)
|
110
110
|
bogus_args = []
|
111
111
|
params.keys.each {|p| bogus_args.push(p) unless allowed_keys.include?(p) }
|
112
112
|
raise AwsError.new("The following arguments were given but are not legal for the function call #{caller_method}: #{bogus_args.inspect}") if bogus_args.length > 0
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
def self.mandatory_arguments(required_args, params)
|
116
116
|
rargs = required_args.dup
|
117
117
|
params.keys.each {|p| rargs.delete(p)}
|
118
118
|
raise AwsError.new("The following mandatory arguments were not provided to #{caller_method}: #{rargs.inspect}") if rargs.length > 0
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
def self.caller_method
|
122
122
|
caller[1]=~/`(.*?)'/
|
123
123
|
$1
|
@@ -137,16 +137,16 @@ module RightAws
|
|
137
137
|
|
138
138
|
class AwsNoChange < RuntimeError
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
class RightAwsBase
|
142
142
|
|
143
143
|
# Amazon HTTP Error handling
|
144
144
|
|
145
145
|
# Text, if found in an error message returned by AWS, indicates that this may be a transient
|
146
146
|
# error. Transient errors are automatically retried with exponential back-off.
|
147
|
-
AMAZON_PROBLEMS = [ 'internal service error',
|
148
|
-
'is currently unavailable',
|
149
|
-
'no response from',
|
147
|
+
AMAZON_PROBLEMS = [ 'internal service error',
|
148
|
+
'is currently unavailable',
|
149
|
+
'no response from',
|
150
150
|
'Please try again',
|
151
151
|
'InternalError',
|
152
152
|
'ServiceUnavailable', #from SQS docs
|
@@ -155,24 +155,24 @@ module RightAws
|
|
155
155
|
'InsufficientInstanceCapacity'
|
156
156
|
]
|
157
157
|
@@amazon_problems = AMAZON_PROBLEMS
|
158
|
-
# Returns a list of Amazon service responses which are known to be transient problems.
|
159
|
-
# We have to re-request if we get any of them, because the problem will probably disappear.
|
158
|
+
# Returns a list of Amazon service responses which are known to be transient problems.
|
159
|
+
# We have to re-request if we get any of them, because the problem will probably disappear.
|
160
160
|
# By default this method returns the same value as the AMAZON_PROBLEMS const.
|
161
161
|
def self.amazon_problems
|
162
162
|
@@amazon_problems
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
# Sets the list of Amazon side problems. Use in conjunction with the
|
166
166
|
# getter to append problems.
|
167
167
|
def self.amazon_problems=(problems_list)
|
168
168
|
@@amazon_problems = problems_list
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
end
|
172
172
|
|
173
173
|
module RightAwsBaseInterface
|
174
174
|
DEFAULT_SIGNATURE_VERSION = '2'
|
175
|
-
|
175
|
+
|
176
176
|
@@caching = false
|
177
177
|
def self.caching
|
178
178
|
@@caching
|
@@ -246,11 +246,11 @@ module RightAws
|
|
246
246
|
end
|
247
247
|
end
|
248
248
|
|
249
|
-
# Returns +true+ if the describe_xxx responses are being cached
|
249
|
+
# Returns +true+ if the describe_xxx responses are being cached
|
250
250
|
def caching?
|
251
251
|
@params.key?(:cache) ? @params[:cache] : @@caching
|
252
252
|
end
|
253
|
-
|
253
|
+
|
254
254
|
# Check if the aws function response hits the cache or not.
|
255
255
|
# If the cache hits:
|
256
256
|
# - raises an +AwsNoChange+ exception if +do_raise+ == +:raise+.
|
@@ -266,9 +266,9 @@ module RightAws
|
|
266
266
|
# check for changes
|
267
267
|
unless @cache[function] && @cache[function][:response_md5] == response_md5
|
268
268
|
# well, the response is new, reset cache data
|
269
|
-
update_cache(function, {:response_md5 => response_md5,
|
270
|
-
:timestamp => Time.now,
|
271
|
-
:hits => 0,
|
269
|
+
update_cache(function, {:response_md5 => response_md5,
|
270
|
+
:timestamp => Time.now,
|
271
|
+
:hits => 0,
|
272
272
|
:parsed => nil})
|
273
273
|
else
|
274
274
|
# aha, cache hits, update the data and throw an exception if needed
|
@@ -284,16 +284,16 @@ module RightAws
|
|
284
284
|
end
|
285
285
|
result
|
286
286
|
end
|
287
|
-
|
287
|
+
|
288
288
|
def update_cache(function, hash)
|
289
289
|
(@cache[function.to_sym] ||= {}).merge!(hash) if caching?
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
def on_exception(options={:raise=>true, :log=>true}) # :nodoc:
|
293
293
|
raise if $!.is_a?(AwsNoChange)
|
294
294
|
AwsError::on_aws_exception(self, options)
|
295
295
|
end
|
296
|
-
|
296
|
+
|
297
297
|
# Return +true+ if this instance works in multi_thread mode and +false+ otherwise.
|
298
298
|
def multi_thread
|
299
299
|
@params[:multi_thread]
|
@@ -327,7 +327,7 @@ module RightAws
|
|
327
327
|
check_result = @error_handler.check(request)
|
328
328
|
if check_result
|
329
329
|
@error_handler = nil
|
330
|
-
return check_result
|
330
|
+
return check_result
|
331
331
|
end
|
332
332
|
request_text_data = "#{request[:server]}:#{request[:port]}#{request[:request].path}"
|
333
333
|
raise AwsError.new(@last_errors, @last_response.code, @last_request_id, request_text_data)
|
@@ -360,7 +360,7 @@ module RightAws
|
|
360
360
|
check_result = @error_handler.check(request)
|
361
361
|
if check_result
|
362
362
|
@error_handler = nil
|
363
|
-
return check_result
|
363
|
+
return check_result
|
364
364
|
end
|
365
365
|
request_text_data = "#{request[:server]}:#{request[:port]}#{request[:request].path}"
|
366
366
|
raise AwsError.new(@last_errors, @last_response.code, @last_request_id, request_text_data)
|
@@ -400,37 +400,41 @@ module RightAws
|
|
400
400
|
# Attribute inherited by RuntimeError:
|
401
401
|
# message - the text of the error, generally as returned by AWS in its XML response.
|
402
402
|
class AwsError < RuntimeError
|
403
|
-
|
403
|
+
|
404
404
|
# either an array of errors where each item is itself an array of [code, message]),
|
405
405
|
# or an error string if the error was raised manually, as in <tt>AwsError.new('err_text')</tt>
|
406
406
|
attr_reader :errors
|
407
|
-
|
407
|
+
|
408
408
|
# Request id (if exists)
|
409
409
|
attr_reader :request_id
|
410
|
-
|
410
|
+
|
411
411
|
# Response HTTP error code
|
412
412
|
attr_reader :http_code
|
413
|
-
|
414
|
-
|
413
|
+
|
414
|
+
# Raw request text data to AWS
|
415
|
+
attr_reader :request_data
|
416
|
+
|
417
|
+
def initialize(errors=nil, http_code=nil, request_id=nil, request_data=nil)
|
415
418
|
@errors = errors
|
416
419
|
@request_id = request_id
|
417
420
|
@http_code = http_code
|
421
|
+
@request_data = request_data
|
418
422
|
msg = @errors.is_a?(Array) ? @errors.map{|code, msg| "#{code}: #{msg}"}.join("; ") : @errors.to_s
|
419
423
|
msg += "\nREQUEST(#{@request_data})" unless @request_data.nil?
|
420
424
|
super(msg)
|
421
425
|
end
|
422
|
-
|
426
|
+
|
423
427
|
# Does any of the error messages include the regexp +pattern+?
|
424
428
|
# Used to determine whether to retry request.
|
425
429
|
def include?(pattern)
|
426
430
|
if @errors.is_a?(Array)
|
427
|
-
@errors.each{ |code, msg| return true if code =~ pattern }
|
431
|
+
@errors.each{ |code, msg| return true if code =~ pattern }
|
428
432
|
else
|
429
|
-
return true if @errors_str =~ pattern
|
433
|
+
return true if @errors_str =~ pattern
|
430
434
|
end
|
431
435
|
false
|
432
436
|
end
|
433
|
-
|
437
|
+
|
434
438
|
# Generic handler for AwsErrors. +aws+ is the RightAws::S3, RightAws::EC2, or RightAws::SQS
|
435
439
|
# object that caused the exception (it must provide last_request and last_response). Supported
|
436
440
|
# boolean options are:
|
@@ -454,7 +458,7 @@ module RightAws
|
|
454
458
|
raise if options[:raise] # re-raise an exception
|
455
459
|
return nil
|
456
460
|
end
|
457
|
-
|
461
|
+
|
458
462
|
# True if e is an AWS system error, i.e. something that is for sure not the caller's fault.
|
459
463
|
# Used to force logging.
|
460
464
|
def self.system_error?(e)
|
@@ -465,9 +469,9 @@ module RightAws
|
|
465
469
|
|
466
470
|
|
467
471
|
class AWSErrorHandler
|
468
|
-
# 0-100 (%)
|
469
|
-
DEFAULT_CLOSE_ON_4XX_PROBABILITY = 10
|
470
|
-
|
472
|
+
# 0-100 (%)
|
473
|
+
DEFAULT_CLOSE_ON_4XX_PROBABILITY = 10
|
474
|
+
|
471
475
|
@@reiteration_start_delay = 0.2
|
472
476
|
def self.reiteration_start_delay
|
473
477
|
@@reiteration_start_delay
|
@@ -483,42 +487,42 @@ module RightAws
|
|
483
487
|
def self.reiteration_time=(reiteration_time)
|
484
488
|
@@reiteration_time = reiteration_time
|
485
489
|
end
|
486
|
-
|
487
|
-
@@close_on_error = true
|
488
|
-
def self.close_on_error
|
489
|
-
@@close_on_error
|
490
|
-
end
|
491
|
-
def self.close_on_error=(close_on_error)
|
492
|
-
@@close_on_error = close_on_error
|
493
|
-
end
|
494
|
-
|
495
|
-
@@close_on_4xx_probability = DEFAULT_CLOSE_ON_4XX_PROBABILITY
|
496
|
-
def self.close_on_4xx_probability
|
497
|
-
@@close_on_4xx_probability
|
498
|
-
end
|
499
|
-
def self.close_on_4xx_probability=(close_on_4xx_probability)
|
500
|
-
@@close_on_4xx_probability = close_on_4xx_probability
|
501
|
-
end
|
502
|
-
|
503
|
-
# params:
|
504
|
-
# :reiteration_time
|
505
|
-
# :errors_list
|
506
|
-
# :close_on_error = true | false
|
507
|
-
# :close_on_4xx_probability = 1-100
|
508
|
-
def initialize(aws, parser, params={}) #:nodoc:
|
490
|
+
|
491
|
+
@@close_on_error = true
|
492
|
+
def self.close_on_error
|
493
|
+
@@close_on_error
|
494
|
+
end
|
495
|
+
def self.close_on_error=(close_on_error)
|
496
|
+
@@close_on_error = close_on_error
|
497
|
+
end
|
498
|
+
|
499
|
+
@@close_on_4xx_probability = DEFAULT_CLOSE_ON_4XX_PROBABILITY
|
500
|
+
def self.close_on_4xx_probability
|
501
|
+
@@close_on_4xx_probability
|
502
|
+
end
|
503
|
+
def self.close_on_4xx_probability=(close_on_4xx_probability)
|
504
|
+
@@close_on_4xx_probability = close_on_4xx_probability
|
505
|
+
end
|
506
|
+
|
507
|
+
# params:
|
508
|
+
# :reiteration_time
|
509
|
+
# :errors_list
|
510
|
+
# :close_on_error = true | false
|
511
|
+
# :close_on_4xx_probability = 1-100
|
512
|
+
def initialize(aws, parser, params={}) #:nodoc:
|
509
513
|
@aws = aws # Link to RightEc2 | RightSqs | RightS3 instance
|
510
514
|
@parser = parser # parser to parse Amazon response
|
511
515
|
@started_at = Time.now
|
512
|
-
@stop_at = @started_at + (params[:reiteration_time] || @@reiteration_time)
|
513
|
-
@errors_list = params[:errors_list] || []
|
516
|
+
@stop_at = @started_at + (params[:reiteration_time] || @@reiteration_time)
|
517
|
+
@errors_list = params[:errors_list] || []
|
514
518
|
@reiteration_delay = @@reiteration_start_delay
|
515
519
|
@retries = 0
|
516
|
-
# close current HTTP(S) connection on 5xx, errors from list and 4xx errors
|
517
|
-
@close_on_error = params[:close_on_error].nil? ? @@close_on_error : params[:close_on_error]
|
518
|
-
@close_on_4xx_probability = params[:close_on_4xx_probability] || @@close_on_4xx_probability
|
520
|
+
# close current HTTP(S) connection on 5xx, errors from list and 4xx errors
|
521
|
+
@close_on_error = params[:close_on_error].nil? ? @@close_on_error : params[:close_on_error]
|
522
|
+
@close_on_4xx_probability = params[:close_on_4xx_probability] || @@close_on_4xx_probability
|
519
523
|
end
|
520
|
-
|
521
|
-
# Returns false if
|
524
|
+
|
525
|
+
# Returns false if
|
522
526
|
def check(request) #:nodoc:
|
523
527
|
result = false
|
524
528
|
error_found = false
|
@@ -531,7 +535,7 @@ module RightAws
|
|
531
535
|
# is this a redirect?
|
532
536
|
# yes!
|
533
537
|
if response.is_a?(Net::HTTPRedirection)
|
534
|
-
redirect_detected = true
|
538
|
+
redirect_detected = true
|
535
539
|
else
|
536
540
|
# no, it's an error ...
|
537
541
|
@aws.logger.warn("##### #{@aws.class.name} returned an error: #{response.code} #{response.message}\n#{response.body} #####")
|
@@ -575,18 +579,18 @@ module RightAws
|
|
575
579
|
end
|
576
580
|
# check the time has gone from the first error come
|
577
581
|
if redirect_detected || error_found
|
578
|
-
# Close the connection to the server and recreate a new one.
|
579
|
-
# It may have a chance that one server is a semi-down and reconnection
|
580
|
-
# will help us to connect to the other server
|
582
|
+
# Close the connection to the server and recreate a new one.
|
583
|
+
# It may have a chance that one server is a semi-down and reconnection
|
584
|
+
# will help us to connect to the other server
|
581
585
|
if !redirect_detected && @close_on_error
|
582
|
-
@aws.connection.finish "#{self.class.name}: error match to pattern '#{error_match}'"
|
583
|
-
end
|
584
|
-
|
586
|
+
@aws.connection.finish "#{self.class.name}: error match to pattern '#{error_match}'"
|
587
|
+
end
|
588
|
+
|
585
589
|
if (Time.now < @stop_at)
|
586
590
|
@retries += 1
|
587
591
|
unless redirect_detected
|
588
592
|
@aws.logger.warn("##### Retry ##{@retries} is being performed. Sleeping for #{@reiteration_delay} sec. Whole time: #{Time.now-@started_at} sec ####")
|
589
|
-
sleep @reiteration_delay
|
593
|
+
sleep @reiteration_delay
|
590
594
|
@reiteration_delay *= 2
|
591
595
|
|
592
596
|
# Always make sure that the fp is set to point to the beginning(?)
|
@@ -605,67 +609,67 @@ module RightAws
|
|
605
609
|
result = @aws.request_info(request, @parser)
|
606
610
|
else
|
607
611
|
@aws.logger.warn("##### Ooops, time is over... ####")
|
608
|
-
end
|
609
|
-
# aha, this is unhandled error:
|
610
|
-
elsif @close_on_error
|
611
|
-
# Is this a 5xx error ?
|
612
|
-
if @aws.last_response.code.to_s[/^5\d\d$/]
|
613
|
-
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}'"
|
614
|
-
# Is this a 4xx error ?
|
615
|
-
elsif @aws.last_response.code.to_s[/^4\d\d$/] && @close_on_4xx_probability > rand(100)
|
616
|
-
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}', " +
|
617
|
-
"probability: #{@close_on_4xx_probability}%"
|
612
|
+
end
|
613
|
+
# aha, this is unhandled error:
|
614
|
+
elsif @close_on_error
|
615
|
+
# Is this a 5xx error ?
|
616
|
+
if @aws.last_response.code.to_s[/^5\d\d$/]
|
617
|
+
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}'"
|
618
|
+
# Is this a 4xx error ?
|
619
|
+
elsif @aws.last_response.code.to_s[/^4\d\d$/] && @close_on_4xx_probability > rand(100)
|
620
|
+
@aws.connection.finish "#{self.class.name}: code: #{@aws.last_response.code}: '#{@aws.last_response.message}', " +
|
621
|
+
"probability: #{@close_on_4xx_probability}%"
|
618
622
|
end
|
619
623
|
end
|
620
624
|
result
|
621
625
|
end
|
622
|
-
|
626
|
+
|
623
627
|
end
|
624
628
|
|
625
629
|
|
626
630
|
#-----------------------------------------------------------------
|
627
631
|
|
628
632
|
class RightSaxParserCallback #:nodoc:
|
629
|
-
def self.include_callback
|
630
|
-
include XML::SaxParser::Callbacks
|
631
|
-
end
|
632
|
-
def initialize(right_aws_parser)
|
633
|
-
@right_aws_parser = right_aws_parser
|
634
|
-
end
|
635
|
-
def on_start_element(name, attr_hash)
|
636
|
-
@right_aws_parser.tag_start(name, attr_hash)
|
637
|
-
end
|
638
|
-
def on_characters(chars)
|
639
|
-
@right_aws_parser.text(chars)
|
640
|
-
end
|
641
|
-
def on_end_element(name)
|
642
|
-
@right_aws_parser.tag_end(name)
|
643
|
-
end
|
644
|
-
def on_start_document; end
|
645
|
-
def on_comment(msg); end
|
646
|
-
def on_processing_instruction(target, data); end
|
647
|
-
def on_cdata_block(cdata); end
|
648
|
-
def on_end_document; end
|
649
|
-
end
|
650
|
-
|
633
|
+
def self.include_callback
|
634
|
+
include XML::SaxParser::Callbacks
|
635
|
+
end
|
636
|
+
def initialize(right_aws_parser)
|
637
|
+
@right_aws_parser = right_aws_parser
|
638
|
+
end
|
639
|
+
def on_start_element(name, attr_hash)
|
640
|
+
@right_aws_parser.tag_start(name, attr_hash)
|
641
|
+
end
|
642
|
+
def on_characters(chars)
|
643
|
+
@right_aws_parser.text(chars)
|
644
|
+
end
|
645
|
+
def on_end_element(name)
|
646
|
+
@right_aws_parser.tag_end(name)
|
647
|
+
end
|
648
|
+
def on_start_document; end
|
649
|
+
def on_comment(msg); end
|
650
|
+
def on_processing_instruction(target, data); end
|
651
|
+
def on_cdata_block(cdata); end
|
652
|
+
def on_end_document; end
|
653
|
+
end
|
654
|
+
|
651
655
|
class RightAWSParser #:nodoc:
|
652
|
-
# default parsing library
|
653
|
-
DEFAULT_XML_LIBRARY = 'rexml'
|
654
|
-
# a list of supported parsers
|
655
|
-
@@supported_xml_libs = [DEFAULT_XML_LIBRARY, 'libxml']
|
656
|
-
|
657
|
-
@@xml_lib = DEFAULT_XML_LIBRARY # xml library name: 'rexml' | 'libxml'
|
656
|
+
# default parsing library
|
657
|
+
DEFAULT_XML_LIBRARY = 'rexml'
|
658
|
+
# a list of supported parsers
|
659
|
+
@@supported_xml_libs = [DEFAULT_XML_LIBRARY, 'libxml']
|
660
|
+
|
661
|
+
@@xml_lib = DEFAULT_XML_LIBRARY # xml library name: 'rexml' | 'libxml'
|
658
662
|
def self.xml_lib
|
659
663
|
@@xml_lib
|
660
664
|
end
|
661
665
|
def self.xml_lib=(new_lib_name)
|
662
666
|
@@xml_lib = new_lib_name
|
663
667
|
end
|
664
|
-
|
668
|
+
|
665
669
|
attr_accessor :result
|
666
670
|
attr_reader :xmlpath
|
667
671
|
attr_accessor :xml_lib
|
668
|
-
|
672
|
+
|
669
673
|
def initialize(params={})
|
670
674
|
@xmlpath = ''
|
671
675
|
@result = false
|
@@ -697,52 +701,52 @@ module RightAws
|
|
697
701
|
# Get response body
|
698
702
|
xml_text = xml_text.body unless xml_text.is_a?(String)
|
699
703
|
@xml_lib = params[:xml_lib] || @xml_lib
|
700
|
-
# check that we had no problems with this library otherwise use default
|
701
|
-
@xml_lib = DEFAULT_XML_LIBRARY unless @@supported_xml_libs.include?(@xml_lib)
|
704
|
+
# check that we had no problems with this library otherwise use default
|
705
|
+
@xml_lib = DEFAULT_XML_LIBRARY unless @@supported_xml_libs.include?(@xml_lib)
|
702
706
|
# load xml library
|
703
707
|
if @xml_lib=='libxml' && !defined?(XML::SaxParser)
|
704
708
|
begin
|
705
709
|
require 'xml/libxml'
|
706
|
-
# is it new ? - Setup SaxParserCallback
|
710
|
+
# is it new ? - Setup SaxParserCallback
|
707
711
|
if XML::Parser::VERSION >= '0.5.1.0'
|
708
|
-
RightSaxParserCallback.include_callback
|
709
|
-
end
|
712
|
+
RightSaxParserCallback.include_callback
|
713
|
+
end
|
710
714
|
rescue LoadError => e
|
711
|
-
@@supported_xml_libs.delete(@xml_lib)
|
712
|
-
@xml_lib = DEFAULT_XML_LIBRARY
|
715
|
+
@@supported_xml_libs.delete(@xml_lib)
|
716
|
+
@xml_lib = DEFAULT_XML_LIBRARY
|
713
717
|
if @logger
|
714
718
|
@logger.error e.inspect
|
715
719
|
@logger.error e.backtrace
|
716
|
-
@logger.info "Can not load 'libxml' library. '#{DEFAULT_XML_LIBRARY}' is used for parsing."
|
720
|
+
@logger.info "Can not load 'libxml' library. '#{DEFAULT_XML_LIBRARY}' is used for parsing."
|
717
721
|
end
|
718
722
|
end
|
719
723
|
end
|
720
724
|
# Parse the xml text
|
721
725
|
case @xml_lib
|
722
|
-
when 'libxml'
|
723
|
-
xml = XML::SaxParser.new
|
724
|
-
xml.string = xml_text
|
725
|
-
# check libxml-ruby version
|
726
|
+
when 'libxml'
|
727
|
+
xml = XML::SaxParser.new
|
728
|
+
xml.string = xml_text
|
729
|
+
# check libxml-ruby version
|
726
730
|
if XML::Parser::VERSION >= '0.5.1.0'
|
727
|
-
xml.callbacks = RightSaxParserCallback.new(self)
|
728
|
-
else
|
729
|
-
xml.on_start_element{|name, attr_hash| self.tag_start(name, attr_hash)}
|
730
|
-
xml.on_characters{ |text| self.text(text)}
|
731
|
-
xml.on_end_element{ |name| self.tag_end(name)}
|
732
|
-
end
|
731
|
+
xml.callbacks = RightSaxParserCallback.new(self)
|
732
|
+
else
|
733
|
+
xml.on_start_element{|name, attr_hash| self.tag_start(name, attr_hash)}
|
734
|
+
xml.on_characters{ |text| self.text(text)}
|
735
|
+
xml.on_end_element{ |name| self.tag_end(name)}
|
736
|
+
end
|
733
737
|
xml.parse
|
734
738
|
else
|
735
739
|
REXML::Document.parse_stream(xml_text, self)
|
736
740
|
end
|
737
741
|
end
|
738
|
-
# Parser must have a lots of methods
|
742
|
+
# Parser must have a lots of methods
|
739
743
|
# (see /usr/lib/ruby/1.8/rexml/parsers/streamparser.rb)
|
740
744
|
# We dont need most of them in RightAWSParser and method_missing helps us
|
741
745
|
# to skip their definition
|
742
746
|
def method_missing(method, *params)
|
743
747
|
# if the method is one of known - just skip it ...
|
744
|
-
return if [:comment, :attlistdecl, :notationdecl, :elementdecl,
|
745
|
-
:entitydecl, :cdata, :xmldecl, :attlistdecl, :instruction,
|
748
|
+
return if [:comment, :attlistdecl, :notationdecl, :elementdecl,
|
749
|
+
:entitydecl, :cdata, :xmldecl, :attlistdecl, :instruction,
|
746
750
|
:doctype].include?(method)
|
747
751
|
# ... else - call super to raise an exception
|
748
752
|
super(method, params)
|
data/lib/right_aws.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.11.
|
4
|
+
version: 1.11.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Reeder
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 2.0.0
|
24
24
|
version:
|
25
25
|
description: |-
|
26
26
|
The RightScale AWS gems have been designed to provide a robust, fast, and secure interface to Amazon EC2, EBS, S3, SQS, SDB, and CloudFront.
|