gotime_aws 2.5.6
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 +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/README.markdown
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Appoxy AWS Library
|
2
|
+
|
3
|
+
A Ruby gem for all Amazon Web Services.
|
4
|
+
|
5
|
+
Brought to you by: [](http://www.appoxy.com)
|
6
|
+
|
7
|
+
## Discussion Group
|
8
|
+
|
9
|
+
[http://groups.google.com/group/ruby-aws](http://groups.google.com/group/ruby-aws)
|
10
|
+
|
11
|
+
## Documentation
|
12
|
+
|
13
|
+
[Ruby Docs](http://rubydoc.info/gems/aws/2.4.5/frames)
|
14
|
+
|
15
|
+
## Appoxy Amazon Web Services Ruby Gems
|
16
|
+
|
17
|
+
Published by [Appoxy LLC](http://www.appoxy.com), under the MIT License. Special thanks to RightScale from which this project is forked.
|
18
|
+
|
19
|
+
## INSTALL:
|
20
|
+
|
21
|
+
gem install aws
|
22
|
+
|
23
|
+
Then `require 'aws'` in your application.
|
24
|
+
|
25
|
+
## DESCRIPTION:
|
26
|
+
|
27
|
+
The AWS gems have been designed to provide a robust, fast, and secure interface to Amazon EC2, EBS, S3, SQS, SDB, and
|
28
|
+
CloudFront.
|
29
|
+
The AWS gems comprise:
|
30
|
+
|
31
|
+
- Aws::Ec2 -- interface to Amazon EC2 (Elastic Compute Cloud) and the associated EBS (Elastic Block Store)
|
32
|
+
- Aws::S3 and Aws::S3Interface -- interface to Amazon S3 (Simple Storage Service)
|
33
|
+
- Aws::Sqs and Aws::SqsInterface -- interface to Amazon SQS (Simple Queue Service)
|
34
|
+
- Aws::SdbInterface -- interface to Amazon SDB (SimpleDB). See [SimpleRecord for an ActiveRecord like gem](https://github.com/appoxy/simple_record).
|
35
|
+
- Aws::AcfInterface -- interface to Amazon CloudFront, a content distribution service
|
36
|
+
- Aws::ElbInterface -- interface to Amazon Load Balancing service
|
37
|
+
- Aws::MonInterface -- interface to Amazon CloudWatch monitoring service
|
38
|
+
- Aws::Iam -- for AWS Identity and Access Management
|
39
|
+
|
40
|
+
To use a single piece intead of loading all of then, you can require it explicitly for example: `require 'aws/sqs'`.
|
41
|
+
|
42
|
+
## FEATURES:
|
43
|
+
|
44
|
+
- Full programmmatic access to EC2, EBS, S3, SQS, SDB, ELB, and CloudFront.
|
45
|
+
- Complete error handling: all operations check for errors and report complete
|
46
|
+
error information by raising an AwsError.
|
47
|
+
- Persistent HTTP connections with robust network-level retry layer using
|
48
|
+
RightHttpConnection). This includes socket timeouts and retries.
|
49
|
+
- Robust HTTP-level retry layer. Certain (user-adjustable) HTTP errors returned
|
50
|
+
by Amazon's services are classified as temporary errors.
|
51
|
+
These errors are automaticallly retried using exponentially increasing intervals.
|
52
|
+
The number of retries is user-configurable.
|
53
|
+
- Fast REXML-based parsing of responses (as fast as a pure Ruby solution allows).
|
54
|
+
- Uses libxml (if available) for faster response parsing.
|
55
|
+
- Support for large S3 list operations. Buckets and key subfolders containing
|
56
|
+
many (> 1000) keys are listed in entirety. Operations based on list (like
|
57
|
+
bucket clear) work on arbitrary numbers of keys.
|
58
|
+
- Support for streaming GETs from S3, and streaming PUTs to S3 if the data source is a file.
|
59
|
+
- Support for single-threaded usage, multithreaded usage, as well as usage with multiple
|
60
|
+
AWS accounts.
|
61
|
+
- Support for both first- and second-generation SQS (API versions 2007-05-01
|
62
|
+
and 2008-01-01). These versions of SQS are not compatible.
|
63
|
+
- Support for signature versions 0, 1 and 2 on all services.
|
64
|
+
- Interoperability with any cloud running Eucalyptus (http://eucalyptus.cs.ucsb.edu)
|
65
|
+
- Test suite (requires AWS account to do "live" testing).
|
66
|
+
|
67
|
+
## THREADING:
|
68
|
+
|
69
|
+
All AWS interfaces offer three threading options:
|
70
|
+
|
71
|
+
1. Use a single persistent HTTP connection per process. :single
|
72
|
+
2. Use a persistent HTTP connection per Ruby thread. :per_thread
|
73
|
+
3. Open a new connection for each request. :per_request
|
74
|
+
|
75
|
+
Either way, it doesn't matter how many (for example) Aws::S3 objects you create,
|
76
|
+
they all use the same per-program or per-thread
|
77
|
+
connection. The purpose of sharing the connection is to keep a single
|
78
|
+
persistent HTTP connection open to avoid paying connection
|
79
|
+
overhead on every request. However, if you have multiple concurrent
|
80
|
+
threads, you may want or need an HTTP connection per thread to enable
|
81
|
+
concurrent requests to AWS. The way this plays out in practice is:
|
82
|
+
|
83
|
+
1. If you have a non-multithreaded Ruby program, use the non-multithreaded setting.
|
84
|
+
2. If you have a multi-threaded Ruby program, use the multithreaded setting to enable
|
85
|
+
concurrent requests to S3 (or SQS, or SDB, or EC2).
|
86
|
+
3. For running under Mongrel/Rails, use the non-multithreaded setting even though
|
87
|
+
mongrel is multithreaded. This is because only one Rails handler is invoked at
|
88
|
+
time (i.e. it acts like a single-threaded program)
|
89
|
+
|
90
|
+
Note that due to limitations in the I/O of the Ruby interpreter you
|
91
|
+
may not get the degree of parallelism you may expect with the multi-threaded setting.
|
92
|
+
|
93
|
+
By default, EC2/S3/SQS/SDB/ACF interface instances are created in per_request mode. Set
|
94
|
+
params[:connection_mode] to :per_thread in the initialization arguments to use
|
95
|
+
multithreaded mode.
|
96
|
+
|
97
|
+
|
98
|
+
== LICENSE:
|
99
|
+
|
100
|
+
Copyright (c) 2007-2009 RightScale, Inc.
|
101
|
+
|
102
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
103
|
+
a copy of this software and associated documentation files (the
|
104
|
+
'Software'), to deal in the Software without restriction, including
|
105
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
106
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
107
|
+
permit persons to whom the Software is furnished to do so, subject to
|
108
|
+
the following conditions:
|
109
|
+
|
110
|
+
The above copyright notice and this permission notice shall be
|
111
|
+
included in all copies or substantial portions of the Software.
|
112
|
+
|
113
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
114
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
115
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
116
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
117
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
118
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
119
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,444 @@
|
|
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
|
+
# = Aws::AcfInterface -- RightScale Amazon's CloudFront interface
|
27
|
+
# The AcfInterface class provides a complete interface to Amazon's
|
28
|
+
# CloudFront service.
|
29
|
+
#
|
30
|
+
# For explanations of the semantics of each call, please refer to
|
31
|
+
# Amazon's documentation at
|
32
|
+
# http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=211
|
33
|
+
#
|
34
|
+
# Example:
|
35
|
+
#
|
36
|
+
# acf = Aws::AcfInterface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX')
|
37
|
+
#
|
38
|
+
# list = acf.list_distributions #=>
|
39
|
+
# [{:status => "Deployed",
|
40
|
+
# :domain_name => "d74zzrxmpmygb.6hops.net",
|
41
|
+
# :aws_id => "E4U91HCJHGXVC",
|
42
|
+
# :origin => "my-bucket.s3.amazonaws.com",
|
43
|
+
# :cnames => ["x1.my-awesome-site.net", "x1.my-awesome-site.net"]
|
44
|
+
# :comment => "My comments",
|
45
|
+
# :last_modified_time => Wed Sep 10 17:00:04 UTC 2008 }, ..., {...} ]
|
46
|
+
#
|
47
|
+
# distibution = list.first
|
48
|
+
#
|
49
|
+
# info = acf.get_distribution(distibution[:aws_id]) #=>
|
50
|
+
# {:enabled => true,
|
51
|
+
# :caller_reference => "200809102100536497863003",
|
52
|
+
# :e_tag => "E39OHHU1ON65SI",
|
53
|
+
# :status => "Deployed",
|
54
|
+
# :domain_name => "d3dxv71tbbt6cd.6hops.net",
|
55
|
+
# :cnames => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
|
56
|
+
# :aws_id => "E2REJM3VUN5RSI",
|
57
|
+
# :comment => "Woo-Hoo!",
|
58
|
+
# :origin => "my-bucket.s3.amazonaws.com",
|
59
|
+
# :last_modified_time => Wed Sep 10 17:00:54 UTC 2008 }
|
60
|
+
#
|
61
|
+
# config = acf.get_distribution_config(distibution[:aws_id]) #=>
|
62
|
+
# {:enabled => true,
|
63
|
+
# :caller_reference => "200809102100536497863003",
|
64
|
+
# :e_tag => "E39OHHU1ON65SI",
|
65
|
+
# :cnames => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
|
66
|
+
# :comment => "Woo-Hoo!",
|
67
|
+
# :origin => "my-bucket.s3.amazonaws.com"}
|
68
|
+
#
|
69
|
+
# config[:comment] = 'Olah-lah!'
|
70
|
+
# config[:enabled] = false
|
71
|
+
# config[:cnames] << "web3.my-awesome-site.net"
|
72
|
+
#
|
73
|
+
# acf.set_distribution_config(distibution[:aws_id], config) #=> true
|
74
|
+
#
|
75
|
+
class AcfInterface < AwsBase
|
76
|
+
|
77
|
+
include AwsBaseInterface
|
78
|
+
|
79
|
+
API_VERSION = "2010-08-01"
|
80
|
+
DEFAULT_HOST = 'cloudfront.amazonaws.com'
|
81
|
+
DEFAULT_PORT = 443
|
82
|
+
DEFAULT_PROTOCOL = 'https'
|
83
|
+
DEFAULT_PATH = '/'
|
84
|
+
|
85
|
+
|
86
|
+
def self.connection_name
|
87
|
+
:acf_connection
|
88
|
+
end
|
89
|
+
|
90
|
+
@@bench = AwsBenchmarkingBlock.new
|
91
|
+
|
92
|
+
def self.bench
|
93
|
+
@@bench
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.bench_xml
|
97
|
+
@@bench.xml
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.bench_service
|
101
|
+
@@bench.service
|
102
|
+
end
|
103
|
+
|
104
|
+
# Create a new handle to a CloudFront account. All handles share the same per process or per thread
|
105
|
+
# HTTP connection to CloudFront. Each handle is for a specific account. The params have the
|
106
|
+
# following options:
|
107
|
+
# * <tt>:server</tt>: CloudFront service host, default: DEFAULT_HOST
|
108
|
+
# * <tt>:port</tt>: CloudFront service port, default: DEFAULT_PORT
|
109
|
+
# * <tt>:protocol</tt>: 'http' or 'https', default: DEFAULT_PROTOCOL
|
110
|
+
# * <tt>:multi_thread</tt>: true=HTTP connection per thread, false=per process
|
111
|
+
# * <tt>:logger</tt>: for log messages, default: Rails.logger else STDOUT
|
112
|
+
# * <tt>:cache</tt>: true/false: caching for list_distributions method, default: false.
|
113
|
+
#
|
114
|
+
# acf = Aws::AcfInterface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX',
|
115
|
+
# {:multi_thread => true, :logger => Logger.new('/tmp/x.log')}) #=> #<Aws::AcfInterface::0xb7b3c30c>
|
116
|
+
#
|
117
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
118
|
+
init({:name => 'ACF',
|
119
|
+
:default_host => ENV['ACF_URL'] ? URI.parse(ENV['ACF_URL']).host : DEFAULT_HOST,
|
120
|
+
:default_port => ENV['ACF_URL'] ? URI.parse(ENV['ACF_URL']).port : DEFAULT_PORT,
|
121
|
+
:default_service => ENV['ACF_URL'] ? URI.parse(ENV['ACF_URL']).path : DEFAULT_PATH,
|
122
|
+
:default_protocol => ENV['ACF_URL'] ? URI.parse(ENV['ACF_URL']).scheme : DEFAULT_PROTOCOL},
|
123
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
124
|
+
aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY'],
|
125
|
+
params)
|
126
|
+
end
|
127
|
+
|
128
|
+
#-----------------------------------------------------------------
|
129
|
+
# Requests
|
130
|
+
#-----------------------------------------------------------------
|
131
|
+
|
132
|
+
# Generates request hash for REST API.
|
133
|
+
def generate_request(method, path, body=nil, headers={}) # :nodoc:
|
134
|
+
headers['content-type'] ||= 'text/xml' if body
|
135
|
+
headers['date'] = Time.now.httpdate
|
136
|
+
# Auth
|
137
|
+
signature = Utils::sign(@aws_secret_access_key, headers['date'])
|
138
|
+
headers['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
|
139
|
+
# Request
|
140
|
+
path = "#{@params[:default_service]}/#{API_VERSION}/#{path}"
|
141
|
+
request = Net::HTTP.const_get(method.capitalize).new(path)
|
142
|
+
request.body = body if body
|
143
|
+
# Set request headers
|
144
|
+
headers.each { |key, value| request[key.to_s] = value }
|
145
|
+
# prepare output hash
|
146
|
+
{:request => request,
|
147
|
+
:server => @params[:server],
|
148
|
+
:port => @params[:port],
|
149
|
+
:protocol => @params[:protocol]}
|
150
|
+
end
|
151
|
+
|
152
|
+
# Sends request to Amazon and parses the response.
|
153
|
+
# Raises AwsError if any banana happened.
|
154
|
+
# todo: remove this and switch to using request_info2
|
155
|
+
def request_info(request, parser, options={}, &block) # :nodoc:
|
156
|
+
conn = get_conn(self.class.connection_name, @params, @logger)
|
157
|
+
request_info_impl(conn, @@bench, request, parser, options, &block)
|
158
|
+
end
|
159
|
+
|
160
|
+
#-----------------------------------------------------------------
|
161
|
+
# Helpers:
|
162
|
+
#-----------------------------------------------------------------
|
163
|
+
|
164
|
+
def self.escape(text) # :nodoc:
|
165
|
+
REXML::Text::normalize(text)
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.unescape(text) # :nodoc:
|
169
|
+
REXML::Text::unnormalize(text)
|
170
|
+
end
|
171
|
+
|
172
|
+
def xmlns # :nodoc:
|
173
|
+
%Q{"http://#{@params[:server]}/doc/#{API_VERSION}/"}
|
174
|
+
end
|
175
|
+
|
176
|
+
def generate_call_reference # :nodoc:
|
177
|
+
result = Time.now.strftime('%Y%m%d%H%M%S')
|
178
|
+
10.times { result << rand(10).to_s }
|
179
|
+
result
|
180
|
+
end
|
181
|
+
|
182
|
+
def merge_headers(hash) # :nodoc:
|
183
|
+
hash[:location] = @last_response['Location'] if @last_response['Location']
|
184
|
+
hash[:e_tag] = @last_response['ETag'] if @last_response['ETag']
|
185
|
+
hash
|
186
|
+
end
|
187
|
+
|
188
|
+
#-----------------------------------------------------------------
|
189
|
+
# API Calls:
|
190
|
+
#-----------------------------------------------------------------
|
191
|
+
|
192
|
+
# List distributions.
|
193
|
+
# Returns an array of distributions or Aws::AwsError exception.
|
194
|
+
#
|
195
|
+
# acf.list_distributions #=>
|
196
|
+
# [{:status => "Deployed",
|
197
|
+
# :domain_name => "d74zzrxmpmygb.6hops.net",
|
198
|
+
# :aws_id => "E4U91HCJHGXVC",
|
199
|
+
# :cnames => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
|
200
|
+
# :origin => "my-bucket.s3.amazonaws.com",
|
201
|
+
# :comment => "My comments",
|
202
|
+
# :last_modified_time => Wed Sep 10 17:00:04 UTC 2008 }, ..., {...} ]
|
203
|
+
#
|
204
|
+
def list_distributions
|
205
|
+
request_hash = generate_request('GET', 'distribution')
|
206
|
+
request_cache_or_info :list_distributions, request_hash, AcfDistributionListParser, @@bench
|
207
|
+
end
|
208
|
+
|
209
|
+
def list_streaming_distributions
|
210
|
+
request_hash = generate_request('GET', 'streaming-distribution')
|
211
|
+
request_cache_or_info :list_streaming_distributions, request_hash, AcfStreamingDistributionListParser, @@bench
|
212
|
+
end
|
213
|
+
|
214
|
+
# Create a new distribution.
|
215
|
+
# Returns the just created distribution or Aws::AwsError exception.
|
216
|
+
#
|
217
|
+
# acf.create_distribution('bucket-for-k-dzreyev.s3.amazonaws.com', 'Woo-Hoo!', true, ['web1.my-awesome-site.net'] ) #=>
|
218
|
+
# {:comment => "Woo-Hoo!",
|
219
|
+
# :enabled => true,
|
220
|
+
# :location => "https://cloudfront.amazonaws.com/2008-06-30/distribution/E2REJM3VUN5RSI",
|
221
|
+
# :status => "InProgress",
|
222
|
+
# :aws_id => "E2REJM3VUN5RSI",
|
223
|
+
# :domain_name => "d3dxv71tbbt6cd.6hops.net",
|
224
|
+
# :origin => "my-bucket.s3.amazonaws.com",
|
225
|
+
# :cnames => ["web1.my-awesome-site.net"]
|
226
|
+
# :last_modified_time => Wed Sep 10 17:00:54 UTC 2008,
|
227
|
+
# :caller_reference => "200809102100536497863003"}
|
228
|
+
#
|
229
|
+
def create_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil, default_root_object=nil)
|
230
|
+
body = distribution_config_for(origin, comment, enabled, cnames, caller_reference, false, default_root_object)
|
231
|
+
request_hash = generate_request('POST', 'distribution', body.strip)
|
232
|
+
merge_headers(request_info(request_hash, AcfDistributionParser.new))
|
233
|
+
end
|
234
|
+
|
235
|
+
def create_streaming_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil, default_root_object=nil)
|
236
|
+
body = distribution_config_for(origin, comment, enabled, cnames, caller_reference, true, default_root_object)
|
237
|
+
request_hash = generate_request('POST', 'streaming-distribution', body.strip)
|
238
|
+
merge_headers(request_info(request_hash, AcfDistributionParser.new))
|
239
|
+
end
|
240
|
+
|
241
|
+
def distribution_config_for(origin, comment='', enabled=true, cnames=[], caller_reference=nil, streaming = false, default_root_object=nil)
|
242
|
+
rootElement = streaming ? "StreamingDistributionConfig" : "DistributionConfig"
|
243
|
+
# join CNAMES
|
244
|
+
cnames_str = ''
|
245
|
+
unless cnames.nil? || cnames.empty?
|
246
|
+
cnames.to_a.each { |cname| cnames_str += "\n <CNAME>#{cname}</CNAME>" }
|
247
|
+
end
|
248
|
+
caller_reference ||= generate_call_reference
|
249
|
+
root_ob = default_root_object ? "<DefaultRootObject>#{config[:default_root_object]}</DefaultRootObject>" : ""
|
250
|
+
body = <<-EOXML
|
251
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
252
|
+
<#{rootElement} xmlns=#{xmlns}>
|
253
|
+
<Origin>#{origin}</Origin>
|
254
|
+
<CallerReference>#{caller_reference}</CallerReference>
|
255
|
+
#{cnames_str.lstrip}
|
256
|
+
<Comment>#{AcfInterface::escape(comment.to_s)}</Comment>
|
257
|
+
<Enabled>#{enabled}</Enabled>
|
258
|
+
#{root_ob}
|
259
|
+
</#{rootElement}>
|
260
|
+
EOXML
|
261
|
+
end
|
262
|
+
|
263
|
+
# Get a distribution's information.
|
264
|
+
# Returns a distribution's information or Aws::AwsError exception.
|
265
|
+
#
|
266
|
+
# acf.get_distribution('E2REJM3VUN5RSI') #=>
|
267
|
+
# {:enabled => true,
|
268
|
+
# :caller_reference => "200809102100536497863003",
|
269
|
+
# :e_tag => "E39OHHU1ON65SI",
|
270
|
+
# :status => "Deployed",
|
271
|
+
# :domain_name => "d3dxv71tbbt6cd.6hops.net",
|
272
|
+
# :cnames => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
|
273
|
+
# :aws_id => "E2REJM3VUN5RSI",
|
274
|
+
# :comment => "Woo-Hoo!",
|
275
|
+
# :origin => "my-bucket.s3.amazonaws.com",
|
276
|
+
# :last_modified_time => Wed Sep 10 17:00:54 UTC 2008 }
|
277
|
+
#
|
278
|
+
def get_distribution(aws_id)
|
279
|
+
request_hash = generate_request('GET', "distribution/#{aws_id}")
|
280
|
+
merge_headers(request_info(request_hash, AcfDistributionParser.new))
|
281
|
+
end
|
282
|
+
|
283
|
+
def get_streaming_distribution(aws_id)
|
284
|
+
request_hash = generate_request('GET', "streaming-distribution/#{aws_id}")
|
285
|
+
merge_headers(request_info(request_hash, AcfDistributionParser.new))
|
286
|
+
end
|
287
|
+
|
288
|
+
# Get a distribution's configuration.
|
289
|
+
# Returns a distribution's configuration or Aws::AwsError exception.
|
290
|
+
#
|
291
|
+
# acf.get_distribution_config('E2REJM3VUN5RSI') #=>
|
292
|
+
# {:enabled => true,
|
293
|
+
# :caller_reference => "200809102100536497863003",
|
294
|
+
# :e_tag => "E39OHHU1ON65SI",
|
295
|
+
# :cnames => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
|
296
|
+
# :comment => "Woo-Hoo!",
|
297
|
+
# :origin => "my-bucket.s3.amazonaws.com"}
|
298
|
+
#
|
299
|
+
def get_distribution_config(aws_id)
|
300
|
+
request_hash = generate_request('GET', "distribution/#{aws_id}/config")
|
301
|
+
merge_headers(request_info(request_hash, AcfDistributionConfigParser.new))
|
302
|
+
end
|
303
|
+
|
304
|
+
# Set a distribution's configuration
|
305
|
+
# (the :origin and the :caller_reference cannot be changed).
|
306
|
+
# Returns +true+ on success or Aws::AwsError exception.
|
307
|
+
#
|
308
|
+
# config = acf.get_distribution_config('E2REJM3VUN5RSI') #=>
|
309
|
+
# {:enabled => true,
|
310
|
+
# :caller_reference => "200809102100536497863003",
|
311
|
+
# :e_tag => "E39OHHU1ON65SI",
|
312
|
+
# :cnames => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
|
313
|
+
# :comment => "Woo-Hoo!",
|
314
|
+
# :origin => "my-bucket.s3.amazonaws.com",
|
315
|
+
# :default_root_object =>
|
316
|
+
# }
|
317
|
+
# config[:comment] = 'Olah-lah!'
|
318
|
+
# config[:enabled] = false
|
319
|
+
# acf.set_distribution_config('E2REJM3VUN5RSI', config) #=> true
|
320
|
+
#
|
321
|
+
def set_distribution_config(aws_id, config)
|
322
|
+
body = distribution_config_for(config[:origin], config[:comment], config[:enabled], config[:cnames], config[:caller_reference], false)
|
323
|
+
request_hash = generate_request('PUT', "distribution/#{aws_id}/config", body.strip,
|
324
|
+
'If-Match' => config[:e_tag])
|
325
|
+
request_info(request_hash, RightHttp2xxParser.new)
|
326
|
+
end
|
327
|
+
|
328
|
+
def set_streaming_distribution_config(aws_id, config)
|
329
|
+
body = distribution_config_for(config[:origin], config[:comment], config[:enabled], config[:cnames], config[:caller_reference], true)
|
330
|
+
request_hash = generate_request('PUT', "streaming-distribution/#{aws_id}/config", body.strip,
|
331
|
+
'If-Match' => config[:e_tag])
|
332
|
+
request_info(request_hash, RightHttp2xxParser.new)
|
333
|
+
end
|
334
|
+
|
335
|
+
# Delete a distribution. The enabled distribution cannot be deleted.
|
336
|
+
# Returns +true+ on success or Aws::AwsError exception.
|
337
|
+
#
|
338
|
+
# acf.delete_distribution('E2REJM3VUN5RSI', 'E39OHHU1ON65SI') #=> true
|
339
|
+
#
|
340
|
+
def delete_distribution(aws_id, e_tag)
|
341
|
+
request_hash = generate_request('DELETE', "distribution/#{aws_id}", nil,
|
342
|
+
'If-Match' => e_tag)
|
343
|
+
request_info(request_hash, RightHttp2xxParser.new)
|
344
|
+
end
|
345
|
+
|
346
|
+
def delete_streaming_distribution(aws_id, e_tag)
|
347
|
+
request_hash = generate_request('DELETE', "streaming-distribution/#{aws_id}", nil,
|
348
|
+
'If-Match' => e_tag)
|
349
|
+
request_info(request_hash, RightHttp2xxParser.new)
|
350
|
+
end
|
351
|
+
|
352
|
+
#-----------------------------------------------------------------
|
353
|
+
# PARSERS:
|
354
|
+
#-----------------------------------------------------------------
|
355
|
+
|
356
|
+
# Parses attributes common to many CF distribution API calls
|
357
|
+
class AcfBaseDistributionParser < AwsParser # :nodoc:
|
358
|
+
def reset
|
359
|
+
@distribution = {:cnames => []}
|
360
|
+
@result = []
|
361
|
+
end
|
362
|
+
|
363
|
+
def tagend(name)
|
364
|
+
case name
|
365
|
+
when 'Id' then
|
366
|
+
@distribution[:aws_id] = @text
|
367
|
+
when 'Status' then
|
368
|
+
@distribution[:status] = @text
|
369
|
+
when 'LastModifiedTime' then
|
370
|
+
@distribution[:last_modified_time] = Time.parse(@text)
|
371
|
+
when 'DomainName' then
|
372
|
+
@distribution[:domain_name] = @text
|
373
|
+
when 'Origin' then
|
374
|
+
@distribution[:origin] = @text
|
375
|
+
when 'CallerReference' then
|
376
|
+
@distribution[:caller_reference] = @text
|
377
|
+
when 'Comment' then
|
378
|
+
@distribution[:comment] = AcfInterface::unescape(@text)
|
379
|
+
when 'Enabled' then
|
380
|
+
@distribution[:enabled] = @text == 'true' ? true : false
|
381
|
+
when 'CNAME' then
|
382
|
+
@distribution[:cnames] << @text
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
class AcfDistributionParser < AcfBaseDistributionParser # :nodoc:
|
388
|
+
def tagend(name)
|
389
|
+
super
|
390
|
+
@result = @distribution
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
class AcfDistributionListParser < AcfBaseDistributionParser # :nodoc:
|
395
|
+
def tagstart(name, attributes)
|
396
|
+
@distribution = {:cnames => []} if name == 'DistributionSummary'
|
397
|
+
end
|
398
|
+
|
399
|
+
def tagend(name)
|
400
|
+
super(name)
|
401
|
+
case name
|
402
|
+
when 'DistributionSummary' then
|
403
|
+
@result << @distribution
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
class AcfDistributionConfigParser < AwsParser # :nodoc:
|
409
|
+
def reset
|
410
|
+
@result = {:cnames => []}
|
411
|
+
end
|
412
|
+
|
413
|
+
def tagend(name)
|
414
|
+
case name
|
415
|
+
when 'Origin' then
|
416
|
+
@result[:origin] = @text
|
417
|
+
when 'CallerReference' then
|
418
|
+
@result[:caller_reference] = @text
|
419
|
+
when 'Comment' then
|
420
|
+
@result[:comment] = AcfInterface::unescape(@text)
|
421
|
+
when 'Enabled' then
|
422
|
+
@result[:enabled] = @text == 'true' ? true : false
|
423
|
+
when 'CNAME' then
|
424
|
+
@result[:cnames] << @text
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
class AcfStreamingDistributionListParser < AcfBaseDistributionParser # :nodoc:
|
430
|
+
def tagstart(name, attributes)
|
431
|
+
@distribution = {:cnames => []} if name == 'StreamingDistributionSummary'
|
432
|
+
end
|
433
|
+
|
434
|
+
def tagend(name)
|
435
|
+
super(name)
|
436
|
+
case name
|
437
|
+
when 'StreamingDistributionSummary' then
|
438
|
+
@result << @distribution
|
439
|
+
end
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
end
|
444
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Aws
|
2
|
+
|
3
|
+
# This class is a special array to hold a bit of extra information about a response like:
|
4
|
+
# <ResponseMetadata>
|
5
|
+
# <RequestId>4f1fae46-bf3d-11de-a88b-7b5b3d23b3a7</RequestId>
|
6
|
+
# </ResponseMetadata>
|
7
|
+
#
|
8
|
+
# Which can be accessed directly from the array using array.response_metadata
|
9
|
+
#
|
10
|
+
class AwsResponseArray < Array
|
11
|
+
|
12
|
+
attr_accessor :response_metadata
|
13
|
+
|
14
|
+
def initialize(response_metadata)
|
15
|
+
@response_metadata = response_metadata
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
# Used when pulling out a single response object
|
21
|
+
class AwsResponseObjectHash < Hash
|
22
|
+
|
23
|
+
attr_accessor :response_metadata
|
24
|
+
|
25
|
+
def initialize(response_metadata)
|
26
|
+
@response_metadata = response_metadata
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|