gotime_aws 2.5.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +119 -0
- data/lib/acf/acf_interface.rb +444 -0
- data/lib/awsbase/aws_response_array.rb +30 -0
- data/lib/awsbase/awsbase.rb +611 -0
- data/lib/awsbase/benchmark_fix.rb +39 -0
- data/lib/awsbase/errors.rb +296 -0
- data/lib/awsbase/parsers.rb +227 -0
- data/lib/awsbase/require_relative.rb +20 -0
- data/lib/awsbase/utils.rb +255 -0
- data/lib/ec2/ec2.rb +2294 -0
- data/lib/ec2/mon_interface.rb +244 -0
- data/lib/elb/elb_interface.rb +366 -0
- data/lib/gotime_aws.rb +33 -0
- data/lib/iam/iam.rb +126 -0
- data/lib/rds/rds.rb +222 -0
- data/lib/right_aws.rb +57 -0
- data/lib/s3/bucket.rb +278 -0
- data/lib/s3/grantee.rb +238 -0
- data/lib/s3/key.rb +281 -0
- data/lib/s3/s3.rb +347 -0
- data/lib/s3/s3_interface.rb +1279 -0
- data/lib/sdb/active_sdb.rb +989 -0
- data/lib/sdb/sdb_interface.rb +890 -0
- data/lib/ses/ses.rb +123 -0
- data/lib/sqs/sqs.rb +307 -0
- data/lib/sqs/sqs_interface.rb +483 -0
- metadata +107 -0
data/lib/ses/ses.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require_relative "../awsbase/awsbase"
|
2
|
+
module Aws
|
3
|
+
|
4
|
+
require 'xmlsimple'
|
5
|
+
|
6
|
+
class Ses < AwsBase
|
7
|
+
|
8
|
+
include AwsBaseInterface
|
9
|
+
|
10
|
+
API_VERSION = "2010-12-01"
|
11
|
+
DEFAULT_HOST = "email.us-east-1.amazonaws.com"
|
12
|
+
DEFAULT_PATH = '/'
|
13
|
+
DEFAULT_PROTOCOL = 'https'
|
14
|
+
DEFAULT_PORT = 443
|
15
|
+
|
16
|
+
def self.connection_name
|
17
|
+
:ses_connection
|
18
|
+
end
|
19
|
+
|
20
|
+
@@bench = AwsBenchmarkingBlock.new
|
21
|
+
|
22
|
+
def self.bench
|
23
|
+
@@bench
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.bench_xml
|
27
|
+
@@bench.xml
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.bench_ec2
|
31
|
+
@@bench.service
|
32
|
+
end
|
33
|
+
|
34
|
+
# Current API version (sometimes we have to check it outside the GEM).
|
35
|
+
@@api = ENV['SES_API_VERSION'] || API_VERSION
|
36
|
+
|
37
|
+
def self.api
|
38
|
+
@@api
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
43
|
+
init({:name => 'SES',
|
44
|
+
:default_host => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).host : DEFAULT_HOST,
|
45
|
+
:default_port => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).port : DEFAULT_PORT,
|
46
|
+
:default_service => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).path : DEFAULT_PATH,
|
47
|
+
:default_protocol => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).scheme : DEFAULT_PROTOCOL,
|
48
|
+
:api_version => API_VERSION,
|
49
|
+
:signature_version=>'3'},
|
50
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
51
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
52
|
+
params)
|
53
|
+
end
|
54
|
+
|
55
|
+
def do_request(action, params, options={})
|
56
|
+
link = generate_request(action, params)
|
57
|
+
puts "request=" + link[:request].inspect
|
58
|
+
resp = request_info_xml_simple3(self, link,
|
59
|
+
:group_tags =>{"LoadBalancersDescriptions"=>"LoadBalancersDescription",
|
60
|
+
"DBParameterGroups" =>"DBParameterGroup",
|
61
|
+
"DBSecurityGroups" =>"DBSecurityGroup",
|
62
|
+
"EC2SecurityGroups" =>"EC2SecurityGroup",
|
63
|
+
"IPRanges" =>"IPRange"},
|
64
|
+
:force_array =>["DBInstances",
|
65
|
+
"DBParameterGroups",
|
66
|
+
"DBSecurityGroups",
|
67
|
+
"EC2SecurityGroups",
|
68
|
+
"IPRanges"],
|
69
|
+
:pull_out_array =>options[:pull_out_array],
|
70
|
+
:pull_out_single=>options[:pull_out_single],
|
71
|
+
:wrapper =>options[:wrapper])
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
#-----------------------------------------------------------------
|
76
|
+
# REQUESTS
|
77
|
+
#-----------------------------------------------------------------
|
78
|
+
|
79
|
+
|
80
|
+
# options:
|
81
|
+
# :marker => value received from previous response if IsTruncated = true
|
82
|
+
# :max_items => number of items you want returned
|
83
|
+
# :path_previx => for filtering results, default is /
|
84
|
+
def get_send_quota(options={})
|
85
|
+
@logger.info("get_send_quota")
|
86
|
+
|
87
|
+
resp = do_request("GetSendQuota", options)
|
88
|
+
|
89
|
+
|
90
|
+
rescue Exception
|
91
|
+
on_exception
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# name: name of certificate
|
96
|
+
# public_key: public key certificate in PEM-encoded format
|
97
|
+
# private_key: private key in PEM-encoded format
|
98
|
+
# options:
|
99
|
+
# :path => specify a path you want it stored in
|
100
|
+
# :certificate_chain => contents of certificate chain
|
101
|
+
def upload_server_certificate(name, public_key, private_key, options={})
|
102
|
+
params = {}
|
103
|
+
params['ServerCertificateName'] = name
|
104
|
+
params['PrivateKey'] = private_key
|
105
|
+
params['CertificateBody'] = public_key
|
106
|
+
|
107
|
+
params['CertificateChain'] = options[:certificate_chain] if options[:certificate_chain]
|
108
|
+
params['Path'] = options[:path] if options[:path]
|
109
|
+
|
110
|
+
p params
|
111
|
+
|
112
|
+
resp = do_request("UploadServerCertificate", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
|
113
|
+
|
114
|
+
|
115
|
+
rescue Exception
|
116
|
+
on_exception
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
data/lib/sqs/sqs.rb
ADDED
@@ -0,0 +1,307 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2008 RightScale Inc
|
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.
|
22
|
+
#
|
23
|
+
|
24
|
+
module Aws
|
25
|
+
|
26
|
+
#
|
27
|
+
# Aws::Sqs -- RightScale's Amazon SQS interface, API version
|
28
|
+
# 2008-01-01 and later.
|
29
|
+
# The Aws::Sqs class provides a complete interface to the second generation of Amazon's Simple
|
30
|
+
# Queue Service.
|
31
|
+
# For explanations of the semantics
|
32
|
+
# of each call, please refer to Amazon's documentation at
|
33
|
+
# http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=31
|
34
|
+
#
|
35
|
+
#
|
36
|
+
# Aws::Sqs is built atop Aws::SqsInterface, a lower-level
|
37
|
+
# procedural API that may be appropriate for certain programs.
|
38
|
+
#
|
39
|
+
# Error handling: all operations raise an Aws::AwsError in case
|
40
|
+
# of problems. Note that transient errors are automatically retried.
|
41
|
+
#
|
42
|
+
# sqs = Aws::Sqs.new(aws_access_key_id, aws_secret_access_key)
|
43
|
+
# queue1 = sqs.queue('my_awesome_queue')
|
44
|
+
# ...
|
45
|
+
# queue2 = Aws::Sqs::Queue.create(sqs, 'my_cool_queue', true)
|
46
|
+
# puts queue2.size
|
47
|
+
# ...
|
48
|
+
# message1 = queue2.receive
|
49
|
+
# message1.visibility = 0
|
50
|
+
# puts message1
|
51
|
+
# ...
|
52
|
+
# queue2.clear(true)
|
53
|
+
# queue2.send_message('Ola-la!')
|
54
|
+
# message2 = queue2.pop
|
55
|
+
# ...
|
56
|
+
#
|
57
|
+
# NB: Second-generation SQS has eliminated the entire access grant mechanism present in Gen 1.
|
58
|
+
#
|
59
|
+
# Params is a hash:
|
60
|
+
#
|
61
|
+
# {:server => 'queue.amazonaws.com' # Amazon service host: 'queue.amazonaws.com' (default)
|
62
|
+
# :port => 443 # Amazon service port: 80 or 443 (default)
|
63
|
+
# :multi_thread => true|false # Multi-threaded (connection per each thread): true or false (default)
|
64
|
+
# :signature_version => '0' # The signature version : '0' or '1'(default)
|
65
|
+
# :logger => Logger Object} # Logger instance: logs to STDOUT if omitted }
|
66
|
+
class Sqs
|
67
|
+
attr_reader :interface
|
68
|
+
|
69
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
70
|
+
@interface = SqsInterface.new(aws_access_key_id, aws_secret_access_key, params)
|
71
|
+
end
|
72
|
+
|
73
|
+
def close_connection
|
74
|
+
@interface.close_connection
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# Retrieves a list of queues.
|
79
|
+
# Returns an +array+ of +Queue+ instances.
|
80
|
+
#
|
81
|
+
# Aws::Sqs.queues #=> array of queues
|
82
|
+
#
|
83
|
+
def queues(prefix=nil)
|
84
|
+
@interface.list_queues(prefix).map do |url|
|
85
|
+
Queue.new(self, url)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns Queue instance by queue name.
|
90
|
+
# If the queue does not exist at Amazon SQS and +create+ is true, the method creates it.
|
91
|
+
#
|
92
|
+
# Aws::Sqs.queue('my_awesome_queue') #=> #<Aws::Sqs::Queue:0xb7b626e4 ... >
|
93
|
+
#
|
94
|
+
def queue(queue_name, create=true, visibility=nil)
|
95
|
+
if create
|
96
|
+
url = @interface.create_queue(queue_name, visibility) # this returns the url even if it exists
|
97
|
+
else
|
98
|
+
url = @interface.queue_url_by_name(queue_name)
|
99
|
+
end
|
100
|
+
|
101
|
+
url ? Queue.new(self, url) : nil
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
class Queue
|
106
|
+
attr_reader :name, :url, :sqs
|
107
|
+
|
108
|
+
# Returns Queue instance by queue name.
|
109
|
+
# If the queue does not exist at Amazon SQS and +create+ is true, the method creates it.
|
110
|
+
#
|
111
|
+
# Aws::Sqs::Queue.create(sqs, 'my_awesome_queue') #=> #<Aws::Sqs::Queue:0xb7b626e4 ... >
|
112
|
+
#
|
113
|
+
def self.create(sqs, url_or_name, create=true, visibility=nil)
|
114
|
+
sqs.queue(url_or_name, create, visibility)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Creates new Queue instance.
|
118
|
+
# Does not create a queue at Amazon.
|
119
|
+
#
|
120
|
+
# queue = Aws::Sqs::Queue.new(sqs, 'my_awesome_queue')
|
121
|
+
#
|
122
|
+
def initialize(sqs, url_or_name)
|
123
|
+
@sqs = sqs
|
124
|
+
@url = @sqs.interface.queue_url_by_name(url_or_name)
|
125
|
+
raise ResourceNotFoundError, "Queue '#{url_or_name}' not found." unless @url
|
126
|
+
@name = @sqs.interface.queue_name_by_url(@url)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Retrieves queue size.
|
130
|
+
#
|
131
|
+
# queue.size #=> 1
|
132
|
+
#
|
133
|
+
def size
|
134
|
+
@sqs.interface.get_queue_length(@url)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Clears queue, deleting only the visible messages. Any message within its visibility
|
138
|
+
# timeout will not be deleted, and will re-appear in the queue in the
|
139
|
+
# future when the timeout expires.
|
140
|
+
#
|
141
|
+
# To delete all messages in a queue and eliminate the chance of any
|
142
|
+
# messages re-appearing in the future, it's best to delete the queue and
|
143
|
+
# re-create it as a new queue. Note that doing this will take at least 60
|
144
|
+
# s since SQS does not allow re-creation of a queue within this interval.
|
145
|
+
#
|
146
|
+
# queue.clear() #=> true
|
147
|
+
#
|
148
|
+
def clear()
|
149
|
+
@sqs.interface.clear_queue(@url)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Deletes queue. Any messages in the queue will be permanently lost.
|
153
|
+
# Returns +true+.
|
154
|
+
#
|
155
|
+
# NB: Use with caution; severe data loss is possible!
|
156
|
+
#
|
157
|
+
# queue.delete(true) #=> true
|
158
|
+
#
|
159
|
+
def delete(force=false)
|
160
|
+
@sqs.interface.delete_queue(@url)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Sends new message to queue.
|
164
|
+
# Returns new Message instance that has been sent to queue.
|
165
|
+
def send_message(message)
|
166
|
+
message = message.to_s
|
167
|
+
res = @sqs.interface.send_message(@url, message)
|
168
|
+
msg = Message.new(self, res['MessageId'], nil, message)
|
169
|
+
msg.send_checksum = res['MD5OfMessageBody']
|
170
|
+
msg.sent_at = Time.now
|
171
|
+
msg
|
172
|
+
end
|
173
|
+
|
174
|
+
alias_method :push, :send_message
|
175
|
+
|
176
|
+
# Retrieves several messages from queue.
|
177
|
+
# Returns an array of Message instances.
|
178
|
+
#
|
179
|
+
# queue.receive_messages(2,10) #=> array of messages
|
180
|
+
#
|
181
|
+
def receive_messages(number_of_messages=1, visibility=nil)
|
182
|
+
list = @sqs.interface.receive_message(@url, number_of_messages, visibility)
|
183
|
+
list.map! do |entry|
|
184
|
+
msg = Message.new(self, entry['MessageId'], entry['ReceiptHandle'],
|
185
|
+
entry['Body'], visibility)
|
186
|
+
msg.received_at = Time.now
|
187
|
+
msg.receive_checksum = entry['MD5OfBody']
|
188
|
+
msg
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Retrieves first accessible message from queue.
|
193
|
+
# Returns Message instance or +nil+ it the queue is empty.
|
194
|
+
#
|
195
|
+
# queue.receive #=> #<Aws::Sqs::Message:0xb7bf0884 ... >
|
196
|
+
#
|
197
|
+
def receive(visibility=nil)
|
198
|
+
list = receive_messages(1, visibility)
|
199
|
+
list.empty? ? nil : list[0]
|
200
|
+
end
|
201
|
+
|
202
|
+
# Pops (and deletes) first accessible message from queue.
|
203
|
+
# Returns Message instance or +nil+ if the queue is empty.
|
204
|
+
#
|
205
|
+
# queue.pop #=> #<Aws::Sqs::Message:0xb7bf0884 ... >
|
206
|
+
#
|
207
|
+
def pop
|
208
|
+
list = @sqs.interface.pop_messages(@url, 1)
|
209
|
+
return nil if list.empty?
|
210
|
+
entry = list[0]
|
211
|
+
msg = Message.new(self, entry['MessageId'], entry['ReceiptHandle'],
|
212
|
+
entry['Body'], visibility)
|
213
|
+
msg.received_at = Time.now
|
214
|
+
msg.receive_checksum = entry['MD5OfBody']
|
215
|
+
msg
|
216
|
+
end
|
217
|
+
|
218
|
+
# Retrieves +VisibilityTimeout+ value for the queue.
|
219
|
+
# Returns new timeout value.
|
220
|
+
#
|
221
|
+
# queue.visibility #=> 30
|
222
|
+
#
|
223
|
+
def visibility
|
224
|
+
@sqs.interface.get_queue_attributes(@url, 'VisibilityTimeout')['VisibilityTimeout']
|
225
|
+
end
|
226
|
+
|
227
|
+
# Sets new +VisibilityTimeout+ for the queue.
|
228
|
+
# Returns new timeout value.
|
229
|
+
#
|
230
|
+
# queue.visibility #=> 30
|
231
|
+
# queue.visibility = 33
|
232
|
+
# queue.visibility #=> 33
|
233
|
+
#
|
234
|
+
def visibility=(visibility_timeout)
|
235
|
+
@sqs.interface.set_queue_attributes(@url, 'VisibilityTimeout', visibility_timeout)
|
236
|
+
visibility_timeout
|
237
|
+
end
|
238
|
+
|
239
|
+
# Sets new queue attribute value.
|
240
|
+
# Not all attributes may be changed: +ApproximateNumberOfMessages+ (for example) is a read only attribute.
|
241
|
+
# Returns a value to be assigned to attribute.
|
242
|
+
# Currently, 'VisibilityTimeout' is the only settable queue attribute.
|
243
|
+
# Attempting to set non-existent attributes generates an indignant
|
244
|
+
# exception.
|
245
|
+
#
|
246
|
+
# queue.set_attribute('VisibilityTimeout', '100') #=> '100'
|
247
|
+
# queue.get_attribute('VisibilityTimeout') #=> '100'
|
248
|
+
#
|
249
|
+
def set_attribute(attribute, value)
|
250
|
+
@sqs.interface.set_queue_attributes(@url, attribute, value)
|
251
|
+
value
|
252
|
+
end
|
253
|
+
|
254
|
+
# Retrieves queue attributes.
|
255
|
+
# At this moment Amazon supports +VisibilityTimeout+ and +ApproximateNumberOfMessages+ only.
|
256
|
+
# If the name of attribute is set, returns its value. Otherwise, returns a hash of attributes.
|
257
|
+
#
|
258
|
+
# queue.get_attribute('VisibilityTimeout') #=> {"VisibilityTimeout"=>"45"}
|
259
|
+
#
|
260
|
+
def get_attribute(attribute='All')
|
261
|
+
attributes = @sqs.interface.get_queue_attributes(@url, attribute)
|
262
|
+
attribute=='All' ? attributes : attributes[attribute]
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
class Message
|
267
|
+
attr_reader :queue, :id, :body, :visibility, :receipt_handle
|
268
|
+
attr_accessor :sent_at, :received_at, :send_checksum, :receive_checksum
|
269
|
+
|
270
|
+
def initialize(queue, id=nil, rh = nil, body=nil, visibility=nil)
|
271
|
+
@queue = queue
|
272
|
+
@id = id
|
273
|
+
@receipt_handle = rh
|
274
|
+
@body = body
|
275
|
+
@visibility = visibility
|
276
|
+
@sent_at = nil
|
277
|
+
@received_at = nil
|
278
|
+
@send_checksum = nil
|
279
|
+
@receive_checksum = nil
|
280
|
+
end
|
281
|
+
|
282
|
+
# Returns +Message+ instance body.
|
283
|
+
def to_s
|
284
|
+
@body
|
285
|
+
end
|
286
|
+
|
287
|
+
# Removes message from queue.
|
288
|
+
# Returns +true+.
|
289
|
+
def delete
|
290
|
+
@queue.sqs.interface.delete_message(@queue.url, @receipt_handle) if @receipt_handle
|
291
|
+
end
|
292
|
+
|
293
|
+
# Updates visibility timeout.
|
294
|
+
def visibility=(visibility_timeout)
|
295
|
+
if @receipt_handle
|
296
|
+
@queue.sqs.interface.change_message_visibility(
|
297
|
+
@queue.url, @receipt_handle, visibility_timeout
|
298
|
+
)
|
299
|
+
@visibility = visibility_timeout
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
|
306
|
+
end
|
307
|
+
end
|