aws 2.4.5 → 2.5.0
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/README.markdown +9 -75
- data/lib/acf/acf_interface.rb +6 -4
- data/lib/aws.rb +2 -1
- data/lib/awsbase/awsbase.rb +98 -65
- data/lib/awsbase/errors.rb +9 -5
- data/lib/awsbase/parsers.rb +226 -226
- data/lib/awsbase/utils.rb +255 -207
- data/lib/ec2/ec2.rb +243 -105
- data/lib/ec2/mon_interface.rb +2 -1
- data/lib/iam/iam.rb +31 -25
- data/lib/right_aws.rb +1 -1
- data/lib/s3/bucket.rb +7 -8
- data/lib/s3/grantee.rb +238 -238
- data/lib/s3/key.rb +281 -281
- data/lib/s3/s3.rb +2 -1
- data/lib/s3/s3_interface.rb +45 -35
- data/lib/sdb/active_sdb.rb +19 -22
- data/lib/sdb/sdb_interface.rb +4 -5
- data/lib/ses/ses.rb +123 -0
- data/lib/sqs/sqs.rb +5 -0
- data/lib/sqs/sqs_interface.rb +3 -3
- metadata +53 -104
- data/lib/awsbase/support.rb +0 -142
- data/test/acf/test_acf.rb +0 -148
- data/test/acf/test_helper.rb +0 -2
- data/test/ec2/test_ec2.rb +0 -205
- data/test/ec2/test_helper.rb +0 -2
- data/test/ec2/test_mon.rb +0 -17
- data/test/elb/test_elb.rb +0 -51
- data/test/http_connection.rb +0 -87
- data/test/iam/test_iam.rb +0 -36
- data/test/rds/test_rds.rb +0 -181
- data/test/s3/s3_test_base.rb +0 -23
- data/test/s3/test_helper.rb +0 -3
- data/test/s3/test_s3.rb +0 -162
- data/test/s3/test_s3_class.rb +0 -179
- data/test/s3/test_s3_rights.rb +0 -139
- data/test/s3/test_s3_stubbed.rb +0 -97
- data/test/sdb/test_active_sdb.rb +0 -338
- data/test/sdb/test_helper.rb +0 -3
- data/test/sdb/test_sdb.rb +0 -220
- data/test/sqs/test_helper.rb +0 -2
- data/test/sqs/test_sqs.rb +0 -232
- data/test/test_credentials.rb +0 -54
- data/test/ts_right_aws.rb +0 -13
data/lib/awsbase/errors.rb
CHANGED
@@ -31,7 +31,7 @@ module Aws
|
|
31
31
|
@http_code = http_code
|
32
32
|
@request_data = request_data
|
33
33
|
@response = response
|
34
|
-
msg = @errors.is_a?(Array) ? @errors.map { |code,
|
34
|
+
msg = @errors.is_a?(Array) ? @errors.map { |code, m| "#{code}: #{m}" }.join("; ") : @errors.to_s
|
35
35
|
msg += "\nREQUEST=#{@request_data} " unless @request_data.nil?
|
36
36
|
msg += "\nREQUEST ID=#{@request_id} " unless @request_id.nil?
|
37
37
|
super(msg)
|
@@ -39,11 +39,15 @@ module Aws
|
|
39
39
|
|
40
40
|
# Does any of the error messages include the regexp +pattern+?
|
41
41
|
# Used to determine whether to retry request.
|
42
|
-
def include?(
|
42
|
+
def include?(pattern_or_string)
|
43
|
+
if pattern_or_string.is_a?(String)
|
44
|
+
puts 'convert to pattern'
|
45
|
+
pattern_or_string = /#{pattern_or_string}/
|
46
|
+
end
|
43
47
|
if @errors.is_a?(Array)
|
44
|
-
@errors.each { |code, msg| return true if code =~
|
48
|
+
@errors.each { |code, msg| return true if code =~ pattern_or_string }
|
45
49
|
else
|
46
|
-
return true if @errors_str =~
|
50
|
+
return true if @errors_str =~ pattern_or_string
|
47
51
|
end
|
48
52
|
false
|
49
53
|
end
|
@@ -289,4 +293,4 @@ module Aws
|
|
289
293
|
|
290
294
|
end
|
291
295
|
|
292
|
-
end
|
296
|
+
end
|
data/lib/awsbase/parsers.rb
CHANGED
@@ -1,227 +1,227 @@
|
|
1
|
-
module Aws
|
2
|
-
|
3
|
-
#-----------------------------------------------------------------
|
4
|
-
|
5
|
-
class RightSaxParserCallback #:nodoc:
|
6
|
-
def self.include_callback
|
7
|
-
include XML::SaxParser::Callbacks
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(right_aws_parser)
|
11
|
-
@right_aws_parser = right_aws_parser
|
12
|
-
end
|
13
|
-
|
14
|
-
def on_start_element(name, attr_hash)
|
15
|
-
@right_aws_parser.tag_start(name, attr_hash)
|
16
|
-
end
|
17
|
-
|
18
|
-
def on_characters(chars)
|
19
|
-
@right_aws_parser.text(chars)
|
20
|
-
end
|
21
|
-
|
22
|
-
def on_end_element(name)
|
23
|
-
@right_aws_parser.tag_end(name)
|
24
|
-
end
|
25
|
-
|
26
|
-
def on_start_document;
|
27
|
-
end
|
28
|
-
|
29
|
-
def on_comment(msg)
|
30
|
-
;
|
31
|
-
end
|
32
|
-
|
33
|
-
def on_processing_instruction(target, data)
|
34
|
-
;
|
35
|
-
end
|
36
|
-
|
37
|
-
def on_cdata_block(cdata)
|
38
|
-
;
|
39
|
-
end
|
40
|
-
|
41
|
-
def on_end_document;
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class AwsParser #:nodoc:
|
46
|
-
# default parsing library
|
47
|
-
DEFAULT_XML_LIBRARY = 'rexml'
|
48
|
-
# a list of supported parsers
|
49
|
-
@@supported_xml_libs = [DEFAULT_XML_LIBRARY, 'libxml']
|
50
|
-
|
51
|
-
@@xml_lib = DEFAULT_XML_LIBRARY # xml library name: 'rexml' | 'libxml'
|
52
|
-
def self.xml_lib
|
53
|
-
@@xml_lib
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.xml_lib=(new_lib_name)
|
57
|
-
@@xml_lib = new_lib_name
|
58
|
-
end
|
59
|
-
|
60
|
-
attr_accessor :result
|
61
|
-
attr_reader :xmlpath
|
62
|
-
attr_accessor :xml_lib
|
63
|
-
|
64
|
-
def initialize(params={})
|
65
|
-
@xmlpath = ''
|
66
|
-
@result = false
|
67
|
-
@text = ''
|
68
|
-
@xml_lib = params[:xml_lib] || @@xml_lib
|
69
|
-
@logger = params[:logger]
|
70
|
-
reset
|
71
|
-
end
|
72
|
-
|
73
|
-
def tag_start(name, attributes)
|
74
|
-
@text = ''
|
75
|
-
tagstart(name, attributes)
|
76
|
-
@xmlpath += @xmlpath.empty? ? name : "/#{name}"
|
77
|
-
end
|
78
|
-
|
79
|
-
def tag_end(name)
|
80
|
-
if @xmlpath =~ /^(.*?)\/?#{name}$/
|
81
|
-
@xmlpath = $1
|
82
|
-
end
|
83
|
-
tagend(name)
|
84
|
-
end
|
85
|
-
|
86
|
-
def text(text)
|
87
|
-
@text += text
|
88
|
-
tagtext(text)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Parser method.
|
92
|
-
# Params:
|
93
|
-
# xml_text - xml message text(String) or Net:HTTPxxx instance (response)
|
94
|
-
# params[:xml_lib] - library name: 'rexml' | 'libxml'
|
95
|
-
def parse(xml_text, params={})
|
96
|
-
# Get response body
|
97
|
-
unless xml_text.is_a?(String)
|
98
|
-
xml_text = xml_text.body.respond_to?(:force_encoding) ? xml_text.body.force_encoding("UTF-8") : xml_text.body
|
99
|
-
end
|
100
|
-
|
101
|
-
@xml_lib = params[:xml_lib] || @xml_lib
|
102
|
-
# check that we had no problems with this library otherwise use default
|
103
|
-
@xml_lib = DEFAULT_XML_LIBRARY unless @@supported_xml_libs.include?(@xml_lib)
|
104
|
-
# load xml library
|
105
|
-
if @xml_lib=='libxml' && !defined?(XML::SaxParser)
|
106
|
-
begin
|
107
|
-
require 'xml/libxml'
|
108
|
-
# is it new ? - Setup SaxParserCallback
|
109
|
-
if XML::Parser::VERSION >= '0.5.1.0'
|
110
|
-
RightSaxParserCallback.include_callback
|
111
|
-
end
|
112
|
-
rescue LoadError => e
|
113
|
-
@@supported_xml_libs.delete(@xml_lib)
|
114
|
-
@xml_lib = DEFAULT_XML_LIBRARY
|
115
|
-
if @logger
|
116
|
-
@logger.error e.inspect
|
117
|
-
@logger.error e.backtrace
|
118
|
-
@logger.info "Can not load 'libxml' library. '#{DEFAULT_XML_LIBRARY}' is used for parsing."
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
# Parse the xml text
|
123
|
-
case @xml_lib
|
124
|
-
when 'libxml'
|
125
|
-
xml = XML::SaxParser.string(xml_text)
|
126
|
-
# check libxml-ruby version
|
127
|
-
if XML::Parser::VERSION >= '0.5.1.0'
|
128
|
-
xml.callbacks = RightSaxParserCallback.new(self)
|
129
|
-
else
|
130
|
-
xml.on_start_element { |name, attr_hash| self.tag_start(name, attr_hash) }
|
131
|
-
xml.on_characters { |text| self.text(text) }
|
132
|
-
xml.on_end_element { |name| self.tag_end(name) }
|
133
|
-
end
|
134
|
-
xml.parse
|
135
|
-
else
|
136
|
-
REXML::Document.parse_stream(xml_text, self)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Parser must have a lots of methods
|
141
|
-
# (see /usr/lib/ruby/1.8/rexml/parsers/streamparser.rb)
|
142
|
-
# We dont need most of them in AwsParser and method_missing helps us
|
143
|
-
# to skip their definition
|
144
|
-
def method_missing(method, *params)
|
145
|
-
# if the method is one of known - just skip it ...
|
146
|
-
return if [:comment, :attlistdecl, :notationdecl, :elementdecl,
|
147
|
-
:entitydecl, :cdata, :xmldecl, :attlistdecl, :instruction,
|
148
|
-
:doctype].include?(method)
|
149
|
-
# ... else - call super to raise an exception
|
150
|
-
super(method, params)
|
151
|
-
end
|
152
|
-
|
153
|
-
# the functions to be overriden by children (if nessesery)
|
154
|
-
def reset;
|
155
|
-
end
|
156
|
-
|
157
|
-
def tagstart(name, attributes)
|
158
|
-
;
|
159
|
-
end
|
160
|
-
|
161
|
-
def tagend(name)
|
162
|
-
;
|
163
|
-
end
|
164
|
-
|
165
|
-
def tagtext(text)
|
166
|
-
;
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
#-----------------------------------------------------------------
|
171
|
-
# PARSERS: Errors
|
172
|
-
#-----------------------------------------------------------------
|
173
|
-
|
174
|
-
#<Error>
|
175
|
-
# <Code>TemporaryRedirect</Code>
|
176
|
-
# <Message>Please re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests.</Message>
|
177
|
-
# <RequestId>FD8D5026D1C5ABA3</RequestId>
|
178
|
-
# <Endpoint>bucket-for-k.s3-external-3.amazonaws.com</Endpoint>
|
179
|
-
# <HostId>ItJy8xPFPli1fq/JR3DzQd3iDvFCRqi1LTRmunEdM1Uf6ZtW2r2kfGPWhRE1vtaU</HostId>
|
180
|
-
# <Bucket>bucket-for-k</Bucket>
|
181
|
-
#</Error>
|
182
|
-
|
183
|
-
class RightErrorResponseParser < AwsParser #:nodoc:
|
184
|
-
attr_accessor :errors # array of hashes: error/message
|
185
|
-
attr_accessor :requestID
|
186
|
-
# attr_accessor :endpoint, :host_id, :bucket
|
187
|
-
def parse(response)
|
188
|
-
super
|
189
|
-
end
|
190
|
-
|
191
|
-
def tagend(name)
|
192
|
-
case name
|
193
|
-
when 'RequestID';
|
194
|
-
@requestID = @text
|
195
|
-
when 'Code';
|
196
|
-
@code = @text
|
197
|
-
when 'Message';
|
198
|
-
@message = @text
|
199
|
-
# when 'Endpoint' ; @endpoint = @text
|
200
|
-
# when 'HostId' ; @host_id = @text
|
201
|
-
# when 'Bucket' ; @bucket = @text
|
202
|
-
when 'Error';
|
203
|
-
@errors << [@code, @message]
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
def reset
|
208
|
-
@errors = []
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
# Dummy parser - does nothing
|
213
|
-
# Returns the original params back
|
214
|
-
class RightDummyParser # :nodoc:
|
215
|
-
attr_accessor :result
|
216
|
-
|
217
|
-
def parse(response, params={})
|
218
|
-
@result = [response, params]
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
class RightHttp2xxParser < AwsParser # :nodoc:
|
223
|
-
def parse(response)
|
224
|
-
@result = response.is_a?(Net::HTTPSuccess)
|
225
|
-
end
|
226
|
-
end
|
1
|
+
module Aws
|
2
|
+
|
3
|
+
#-----------------------------------------------------------------
|
4
|
+
|
5
|
+
class RightSaxParserCallback #:nodoc:
|
6
|
+
def self.include_callback
|
7
|
+
include XML::SaxParser::Callbacks
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(right_aws_parser)
|
11
|
+
@right_aws_parser = right_aws_parser
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_start_element(name, attr_hash)
|
15
|
+
@right_aws_parser.tag_start(name, attr_hash)
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_characters(chars)
|
19
|
+
@right_aws_parser.text(chars)
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_end_element(name)
|
23
|
+
@right_aws_parser.tag_end(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def on_start_document;
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_comment(msg)
|
30
|
+
;
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_processing_instruction(target, data)
|
34
|
+
;
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_cdata_block(cdata)
|
38
|
+
;
|
39
|
+
end
|
40
|
+
|
41
|
+
def on_end_document;
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class AwsParser #:nodoc:
|
46
|
+
# default parsing library
|
47
|
+
DEFAULT_XML_LIBRARY = 'rexml'
|
48
|
+
# a list of supported parsers
|
49
|
+
@@supported_xml_libs = [DEFAULT_XML_LIBRARY, 'libxml']
|
50
|
+
|
51
|
+
@@xml_lib = DEFAULT_XML_LIBRARY # xml library name: 'rexml' | 'libxml'
|
52
|
+
def self.xml_lib
|
53
|
+
@@xml_lib
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.xml_lib=(new_lib_name)
|
57
|
+
@@xml_lib = new_lib_name
|
58
|
+
end
|
59
|
+
|
60
|
+
attr_accessor :result
|
61
|
+
attr_reader :xmlpath
|
62
|
+
attr_accessor :xml_lib
|
63
|
+
|
64
|
+
def initialize(params={})
|
65
|
+
@xmlpath = ''
|
66
|
+
@result = false
|
67
|
+
@text = ''
|
68
|
+
@xml_lib = params[:xml_lib] || @@xml_lib
|
69
|
+
@logger = params[:logger]
|
70
|
+
reset
|
71
|
+
end
|
72
|
+
|
73
|
+
def tag_start(name, attributes)
|
74
|
+
@text = ''
|
75
|
+
tagstart(name, attributes)
|
76
|
+
@xmlpath += @xmlpath.empty? ? name : "/#{name}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def tag_end(name)
|
80
|
+
if @xmlpath =~ /^(.*?)\/?#{name}$/
|
81
|
+
@xmlpath = $1
|
82
|
+
end
|
83
|
+
tagend(name)
|
84
|
+
end
|
85
|
+
|
86
|
+
def text(text)
|
87
|
+
@text += text
|
88
|
+
tagtext(text)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Parser method.
|
92
|
+
# Params:
|
93
|
+
# xml_text - xml message text(String) or Net:HTTPxxx instance (response)
|
94
|
+
# params[:xml_lib] - library name: 'rexml' | 'libxml'
|
95
|
+
def parse(xml_text, params={})
|
96
|
+
# Get response body
|
97
|
+
unless xml_text.is_a?(String)
|
98
|
+
xml_text = xml_text.body.respond_to?(:force_encoding) ? xml_text.body.force_encoding("UTF-8") : xml_text.body
|
99
|
+
end
|
100
|
+
|
101
|
+
@xml_lib = params[:xml_lib] || @xml_lib
|
102
|
+
# check that we had no problems with this library otherwise use default
|
103
|
+
@xml_lib = DEFAULT_XML_LIBRARY unless @@supported_xml_libs.include?(@xml_lib)
|
104
|
+
# load xml library
|
105
|
+
if @xml_lib=='libxml' && !defined?(XML::SaxParser)
|
106
|
+
begin
|
107
|
+
require 'xml/libxml'
|
108
|
+
# is it new ? - Setup SaxParserCallback
|
109
|
+
if XML::Parser::VERSION >= '0.5.1.0'
|
110
|
+
RightSaxParserCallback.include_callback
|
111
|
+
end
|
112
|
+
rescue LoadError => e
|
113
|
+
@@supported_xml_libs.delete(@xml_lib)
|
114
|
+
@xml_lib = DEFAULT_XML_LIBRARY
|
115
|
+
if @logger
|
116
|
+
@logger.error e.inspect
|
117
|
+
@logger.error e.backtrace
|
118
|
+
@logger.info "Can not load 'libxml' library. '#{DEFAULT_XML_LIBRARY}' is used for parsing."
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
# Parse the xml text
|
123
|
+
case @xml_lib
|
124
|
+
when 'libxml'
|
125
|
+
xml = XML::SaxParser.string(xml_text)
|
126
|
+
# check libxml-ruby version
|
127
|
+
if XML::Parser::VERSION >= '0.5.1.0'
|
128
|
+
xml.callbacks = RightSaxParserCallback.new(self)
|
129
|
+
else
|
130
|
+
xml.on_start_element { |name, attr_hash| self.tag_start(name, attr_hash) }
|
131
|
+
xml.on_characters { |text| self.text(text) }
|
132
|
+
xml.on_end_element { |name| self.tag_end(name) }
|
133
|
+
end
|
134
|
+
xml.parse
|
135
|
+
else
|
136
|
+
REXML::Document.parse_stream(xml_text, self)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Parser must have a lots of methods
|
141
|
+
# (see /usr/lib/ruby/1.8/rexml/parsers/streamparser.rb)
|
142
|
+
# We dont need most of them in AwsParser and method_missing helps us
|
143
|
+
# to skip their definition
|
144
|
+
def method_missing(method, *params)
|
145
|
+
# if the method is one of known - just skip it ...
|
146
|
+
return if [:comment, :attlistdecl, :notationdecl, :elementdecl,
|
147
|
+
:entitydecl, :cdata, :xmldecl, :attlistdecl, :instruction,
|
148
|
+
:doctype].include?(method)
|
149
|
+
# ... else - call super to raise an exception
|
150
|
+
super(method, params)
|
151
|
+
end
|
152
|
+
|
153
|
+
# the functions to be overriden by children (if nessesery)
|
154
|
+
def reset;
|
155
|
+
end
|
156
|
+
|
157
|
+
def tagstart(name, attributes)
|
158
|
+
;
|
159
|
+
end
|
160
|
+
|
161
|
+
def tagend(name)
|
162
|
+
;
|
163
|
+
end
|
164
|
+
|
165
|
+
def tagtext(text)
|
166
|
+
;
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
#-----------------------------------------------------------------
|
171
|
+
# PARSERS: Errors
|
172
|
+
#-----------------------------------------------------------------
|
173
|
+
|
174
|
+
#<Error>
|
175
|
+
# <Code>TemporaryRedirect</Code>
|
176
|
+
# <Message>Please re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests.</Message>
|
177
|
+
# <RequestId>FD8D5026D1C5ABA3</RequestId>
|
178
|
+
# <Endpoint>bucket-for-k.s3-external-3.amazonaws.com</Endpoint>
|
179
|
+
# <HostId>ItJy8xPFPli1fq/JR3DzQd3iDvFCRqi1LTRmunEdM1Uf6ZtW2r2kfGPWhRE1vtaU</HostId>
|
180
|
+
# <Bucket>bucket-for-k</Bucket>
|
181
|
+
#</Error>
|
182
|
+
|
183
|
+
class RightErrorResponseParser < AwsParser #:nodoc:
|
184
|
+
attr_accessor :errors # array of hashes: error/message
|
185
|
+
attr_accessor :requestID
|
186
|
+
# attr_accessor :endpoint, :host_id, :bucket
|
187
|
+
def parse(response)
|
188
|
+
super
|
189
|
+
end
|
190
|
+
|
191
|
+
def tagend(name)
|
192
|
+
case name
|
193
|
+
when 'RequestID';
|
194
|
+
@requestID = @text
|
195
|
+
when 'Code';
|
196
|
+
@code = @text
|
197
|
+
when 'Message';
|
198
|
+
@message = @text
|
199
|
+
# when 'Endpoint' ; @endpoint = @text
|
200
|
+
# when 'HostId' ; @host_id = @text
|
201
|
+
# when 'Bucket' ; @bucket = @text
|
202
|
+
when 'Error';
|
203
|
+
@errors << [@code, @message]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def reset
|
208
|
+
@errors = []
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# Dummy parser - does nothing
|
213
|
+
# Returns the original params back
|
214
|
+
class RightDummyParser # :nodoc:
|
215
|
+
attr_accessor :result
|
216
|
+
|
217
|
+
def parse(response, params={})
|
218
|
+
@result = [response, params]
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
class RightHttp2xxParser < AwsParser # :nodoc:
|
223
|
+
def parse(response)
|
224
|
+
@result = response.is_a?(Net::HTTPSuccess)
|
225
|
+
end
|
226
|
+
end
|
227
227
|
end
|