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/lib/iam/iam.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
module Aws
|
2
|
+
|
3
|
+
require 'xmlsimple'
|
4
|
+
|
5
|
+
class Iam < AwsBase
|
6
|
+
|
7
|
+
include AwsBaseInterface
|
8
|
+
|
9
|
+
API_VERSION = "2010-05-08"
|
10
|
+
DEFAULT_HOST = "iam.amazonaws.com"
|
11
|
+
DEFAULT_PATH = '/'
|
12
|
+
DEFAULT_PROTOCOL = 'https'
|
13
|
+
DEFAULT_PORT = 443
|
14
|
+
|
15
|
+
def self.connection_name
|
16
|
+
:iam_connection
|
17
|
+
end
|
18
|
+
|
19
|
+
@@bench = AwsBenchmarkingBlock.new
|
20
|
+
|
21
|
+
def self.bench
|
22
|
+
@@bench
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.bench_xml
|
26
|
+
@@bench.xml
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.bench_ec2
|
30
|
+
@@bench.service
|
31
|
+
end
|
32
|
+
|
33
|
+
# Current API version (sometimes we have to check it outside the GEM).
|
34
|
+
@@api = ENV['IAM_API_VERSION'] || API_VERSION
|
35
|
+
|
36
|
+
def self.api
|
37
|
+
@@api
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
42
|
+
init({:name => 'IAM',
|
43
|
+
:default_host => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).host : DEFAULT_HOST,
|
44
|
+
:default_port => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).port : DEFAULT_PORT,
|
45
|
+
:default_service => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).path : DEFAULT_PATH,
|
46
|
+
:default_protocol => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).scheme : DEFAULT_PROTOCOL,
|
47
|
+
:api_version => API_VERSION},
|
48
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
49
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
50
|
+
params)
|
51
|
+
end
|
52
|
+
|
53
|
+
def do_request(action, params, options={})
|
54
|
+
link = generate_request(action, params)
|
55
|
+
p link[:request]
|
56
|
+
resp = request_info_xml_simple(:iam_connection, @params, link, @logger,
|
57
|
+
:group_tags =>{"LoadBalancersDescriptions"=>"LoadBalancersDescription",
|
58
|
+
"DBParameterGroups" =>"DBParameterGroup",
|
59
|
+
"DBSecurityGroups" =>"DBSecurityGroup",
|
60
|
+
"EC2SecurityGroups" =>"EC2SecurityGroup",
|
61
|
+
"IPRanges" =>"IPRange"},
|
62
|
+
:force_array =>["DBInstances",
|
63
|
+
"DBParameterGroups",
|
64
|
+
"DBSecurityGroups",
|
65
|
+
"EC2SecurityGroups",
|
66
|
+
"IPRanges"],
|
67
|
+
:pull_out_array =>options[:pull_out_array],
|
68
|
+
:pull_out_single=>options[:pull_out_single],
|
69
|
+
:wrapper =>options[:wrapper])
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
#-----------------------------------------------------------------
|
74
|
+
# REQUESTS
|
75
|
+
#-----------------------------------------------------------------
|
76
|
+
|
77
|
+
|
78
|
+
# options:
|
79
|
+
# :marker => value received from previous response if IsTruncated = true
|
80
|
+
# :max_items => number of items you want returned
|
81
|
+
# :path_previx => for filtering results, default is /
|
82
|
+
def list_server_certificates(options={})
|
83
|
+
@logger.info("Listing server certificates...")
|
84
|
+
|
85
|
+
params = {}
|
86
|
+
params['Marker'] = options[:marker] if options[:marker]
|
87
|
+
params['MaxItems'] = options[:max_items] if options[:max_items]
|
88
|
+
params['PathPrefix'] = options[:path_prefix] if options[:path_prefix]
|
89
|
+
|
90
|
+
resp = do_request("ListServerCertificates", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
|
91
|
+
|
92
|
+
|
93
|
+
rescue Exception
|
94
|
+
on_exception
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# name: name of certificate
|
99
|
+
# public_key: public key certificate in PEM-encoded format
|
100
|
+
# private_key: private key in PEM-encoded format
|
101
|
+
# options:
|
102
|
+
# :path => specify a path you want it stored in
|
103
|
+
# :certificate_chain => contents of certificate chain
|
104
|
+
def upload_server_certificate(name, public_key, private_key, options={})
|
105
|
+
params = {}
|
106
|
+
params['ServerCertificateName'] = name
|
107
|
+
params['PrivateKey'] = private_key
|
108
|
+
params['CertificateBody'] = public_key
|
109
|
+
|
110
|
+
params['CertificateChain'] = options[:certificate_chain] if options[:certificate_chain]
|
111
|
+
params['Path'] = options[:path] if options[:path]
|
112
|
+
|
113
|
+
p params
|
114
|
+
|
115
|
+
resp = do_request("UploadServerCertificate", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
|
116
|
+
|
117
|
+
|
118
|
+
rescue Exception
|
119
|
+
on_exception
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
end
|
data/lib/rds/rds.rb
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
module Aws
|
2
|
+
require 'xmlsimple'
|
3
|
+
|
4
|
+
# API Reference: http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/
|
5
|
+
class Rds < AwsBase
|
6
|
+
include AwsBaseInterface
|
7
|
+
|
8
|
+
|
9
|
+
# Amazon API version being used
|
10
|
+
API_VERSION = nil
|
11
|
+
DEFAULT_HOST = "rds.amazonaws.com"
|
12
|
+
DEFAULT_PATH = '/'
|
13
|
+
DEFAULT_PROTOCOL = 'https'
|
14
|
+
DEFAULT_PORT = 443
|
15
|
+
|
16
|
+
@@api = ENV['RDS_API_VERSION'] || API_VERSION
|
17
|
+
|
18
|
+
|
19
|
+
def self.connection_name
|
20
|
+
:rds_connection
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.api
|
24
|
+
@@api
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
@@bench = AwsBenchmarkingBlock.new
|
29
|
+
|
30
|
+
def self.bench
|
31
|
+
@@bench
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.bench_xml
|
35
|
+
@@bench.xml
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def self.bench_ec2
|
40
|
+
@@bench.service
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
45
|
+
uri = ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']) : nil
|
46
|
+
init({:name => 'RDS',
|
47
|
+
:default_host => uri ? uri.host : DEFAULT_HOST,
|
48
|
+
:default_port => uri ? uri.port : DEFAULT_PORT,
|
49
|
+
:default_service => uri ? uri.path : DEFAULT_PATH,
|
50
|
+
:default_protocol => uri ? uri.scheme : DEFAULT_PROTOCOL,
|
51
|
+
:api_version => API_VERSION},
|
52
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
53
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
54
|
+
params)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def do_request(action, params, options={})
|
59
|
+
link = generate_request(action, params)
|
60
|
+
resp = request_info_xml_simple(self.class.connection_name, @params, link, @logger,
|
61
|
+
:group_tags =>{"DBInstances" =>"DBInstance",
|
62
|
+
"DBParameterGroups"=>"DBParameterGroup",
|
63
|
+
"DBSecurityGroups" =>"DBSecurityGroup",
|
64
|
+
"EC2SecurityGroups"=>"EC2SecurityGroup",
|
65
|
+
"IPRanges" =>"IPRange"},
|
66
|
+
:force_array =>["DBInstances",
|
67
|
+
"DBParameterGroups",
|
68
|
+
"DBSecurityGroups",
|
69
|
+
"EC2SecurityGroups",
|
70
|
+
"IPRanges"],
|
71
|
+
:pull_out_array =>options[:pull_out_array],
|
72
|
+
:pull_out_single=>options[:pull_out_single],
|
73
|
+
:wrapper =>options[:wrapper])
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
#-----------------------------------------------------------------
|
78
|
+
# REQUESTS
|
79
|
+
#-----------------------------------------------------------------
|
80
|
+
|
81
|
+
#
|
82
|
+
# identifier: db instance identifier. Must be unique per account per zone.
|
83
|
+
# instance_class: db.m1.small | db.m1.large | db.m1.xlarge | db.m2.2xlarge | db.m2.4xlarge
|
84
|
+
# See this for other values: http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/
|
85
|
+
#
|
86
|
+
# options:
|
87
|
+
# db_name: if you want a database created at the same time as the instance, specify :db_name option.
|
88
|
+
# availability_zone: default is random zone.
|
89
|
+
def create_db_instance(identifier, instance_class, allocated_storage, master_username, master_password, options={})
|
90
|
+
params = {}
|
91
|
+
params['DBInstanceIdentifier'] = identifier
|
92
|
+
params['DBInstanceClass'] = instance_class
|
93
|
+
params['AllocatedStorage'] = allocated_storage
|
94
|
+
params['MasterUsername'] = master_username
|
95
|
+
params['MasterUserPassword'] = master_password
|
96
|
+
|
97
|
+
params['Engine'] = options[:engine] || "MySQL5.1"
|
98
|
+
params['DBName'] = options[:db_name] if options[:db_name]
|
99
|
+
params['AvailabilityZone'] = options[:availability_zone] if options[:availability_zone]
|
100
|
+
params['PreferredMaintenanceWindow'] = options[:preferred_maintenance_window] if options[:preferred_maintenance_window]
|
101
|
+
params['BackupRetentionPeriod'] = options[:preferred_retention_period] if options[:preferred_retention_period]
|
102
|
+
params['PreferredBackupWindow'] = options[:preferred_backup_window] if options[:preferred_backup_window]
|
103
|
+
|
104
|
+
@logger.info("Creating DB Instance called #{identifier}")
|
105
|
+
|
106
|
+
link = do_request("CreateDBInstance", params, :pull_out_single=>[:create_db_instance_result, :db_instance])
|
107
|
+
|
108
|
+
rescue Exception
|
109
|
+
on_exception
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
# options:
|
114
|
+
# DBInstanceIdentifier
|
115
|
+
# MaxRecords
|
116
|
+
# Marker
|
117
|
+
#
|
118
|
+
# Returns array of instances as hashes.
|
119
|
+
# Response metadata can be retreived by calling array.response_metadata on the returned array.
|
120
|
+
def describe_db_instances(options={})
|
121
|
+
params = {}
|
122
|
+
params['DBInstanceIdentifier'] = options[:db_instance_identifier] if options[:db_instance_identifier]
|
123
|
+
params['MaxRecords'] = options[:max_records] if options[:max_records]
|
124
|
+
params['Marker'] = options[:marker] if options[:marker]
|
125
|
+
|
126
|
+
resp = do_request("DescribeDBInstances", params, :pull_out_array=>[:describe_db_instances_result, :db_instances])
|
127
|
+
|
128
|
+
rescue Exception
|
129
|
+
on_exception
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
# identifier: identifier of db instance to delete.
|
134
|
+
# final_snapshot_identifier: if specified, RDS will crate a final snapshot before deleting so you can restore it later.
|
135
|
+
def delete_db_instance(identifier, final_snapshot_identifier=nil)
|
136
|
+
@logger.info("Deleting DB Instance - " + identifier.to_s)
|
137
|
+
|
138
|
+
params = {}
|
139
|
+
params['DBInstanceIdentifier'] = identifier
|
140
|
+
if final_snapshot_identifier
|
141
|
+
params['FinalDBSnapshotIdentifier'] = final_snapshot_identifier
|
142
|
+
else
|
143
|
+
params['SkipFinalSnapshot'] = true
|
144
|
+
end
|
145
|
+
|
146
|
+
link = do_request("DeleteDBInstance", params, :pull_out_single=>[:delete_db_instance_result, :db_instance])
|
147
|
+
|
148
|
+
rescue Exception
|
149
|
+
on_exception
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
def create_db_security_group(group_name, description, options={})
|
154
|
+
params = {}
|
155
|
+
params['DBSecurityGroupName'] = group_name
|
156
|
+
params['DBSecurityGroupDescription'] = description
|
157
|
+
|
158
|
+
link = do_request("CreateDBSecurityGroup", params, :pull_out_single => [:create_db_security_group_result, :db_security_group])
|
159
|
+
|
160
|
+
rescue Exception
|
161
|
+
on_exception
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
def delete_db_security_group(group_name, options={})
|
166
|
+
params = {}
|
167
|
+
params['DBSecurityGroupName'] = group_name
|
168
|
+
|
169
|
+
link = do_request("DeleteDBSecurityGroup", params)
|
170
|
+
|
171
|
+
rescue Exception
|
172
|
+
on_exception
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
def describe_db_security_groups(options={})
|
177
|
+
params = {}
|
178
|
+
params['DBSecurityGroupName'] = options[:DBSecurityGroupName] if options[:DBSecurityGroupName]
|
179
|
+
params['MaxRecords'] = options[:MaxRecords] if options[:MaxRecords]
|
180
|
+
|
181
|
+
link = do_request("DescribeDBSecurityGroups", params, :pull_out_array=>[:describe_db_security_groups_result, :db_security_groups], :wrapper=>:db_security_group)
|
182
|
+
|
183
|
+
|
184
|
+
rescue Exception
|
185
|
+
on_exception
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
def authorize_db_security_group_ingress_ec2group(group_name, ec2_group_name, ec2_group_owner_id, options={})
|
190
|
+
params = {}
|
191
|
+
params['DBSecurityGroupName'] = group_name
|
192
|
+
params['EC2SecurityGroupOwnerId'] = ec2_group_owner_id
|
193
|
+
params['EC2SecurityGroupName'] = ec2_group_name
|
194
|
+
link = do_request("AuthorizeDBSecurityGroupIngress", params)
|
195
|
+
rescue Exception
|
196
|
+
on_exception
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
def authorize_db_security_group_ingress_range(group_name, ip_range, options={})
|
201
|
+
params = {}
|
202
|
+
params['DBSecurityGroupName'] = group_name
|
203
|
+
params['CIDRIP'] = ip_range
|
204
|
+
link = do_request("AuthorizeDBSecurityGroupIngress", params)
|
205
|
+
rescue Exception
|
206
|
+
on_exception
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
def revoke_db_security_group_ingress(group_name, ip_range, options={})
|
211
|
+
params = {}
|
212
|
+
params['DBSecurityGroupName'] = group_name
|
213
|
+
params['CIDRIP'] = ip_range
|
214
|
+
link = do_request("RevokeDBSecurityGroupIngress", params)
|
215
|
+
rescue Exception
|
216
|
+
on_exception
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
data/lib/right_aws.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2007-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
|
+
require 'benchmark'
|
25
|
+
require 'net/https'
|
26
|
+
require 'uri'
|
27
|
+
require 'time'
|
28
|
+
require "cgi"
|
29
|
+
require "base64"
|
30
|
+
require "rexml/document"
|
31
|
+
require "openssl"
|
32
|
+
require "digest/sha1"
|
33
|
+
|
34
|
+
require 'rubygems'
|
35
|
+
require 'right_http_connection'
|
36
|
+
|
37
|
+
$:.unshift(File.dirname(__FILE__))
|
38
|
+
require 'awsbase/benchmark_fix'
|
39
|
+
#require 'awsbase/support'
|
40
|
+
require 'awsbase/awsbase'
|
41
|
+
require 'ec2/ec2'
|
42
|
+
require 'ec2/mon_interface'
|
43
|
+
require 's3/s3_interface'
|
44
|
+
require 's3/s3'
|
45
|
+
require 'sqs/sqs_interface'
|
46
|
+
require 'sqs/sqs'
|
47
|
+
require 'sdb/sdb_interface'
|
48
|
+
require 'acf/acf_interface'
|
49
|
+
require 'elb/elb_interface'
|
50
|
+
|
51
|
+
|
52
|
+
# backwards compatible.
|
53
|
+
# @deprecated
|
54
|
+
module RightAws
|
55
|
+
include Aws
|
56
|
+
extend Aws
|
57
|
+
end
|
data/lib/s3/bucket.rb
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
module Aws
|
2
|
+
|
3
|
+
|
4
|
+
class S3::Bucket
|
5
|
+
attr_reader :s3, :name, :owner, :creation_date
|
6
|
+
|
7
|
+
# Create a Bucket instance.
|
8
|
+
# If the bucket does not exist and +create+ is set, a new bucket
|
9
|
+
# is created on S3. Launching this method with +create+=+true+ may
|
10
|
+
# affect on the bucket's ACL if the bucket already exists.
|
11
|
+
# Returns Bucket instance or +nil+ if the bucket does not exist
|
12
|
+
# and +create+ is not set.
|
13
|
+
#
|
14
|
+
# s3 = Aws::S3.new(aws_access_key_id, aws_secret_access_key)
|
15
|
+
# ...
|
16
|
+
# bucket1 = Aws::S3::Bucket.create(s3, 'my_awesome_bucket_1')
|
17
|
+
# bucket1.keys #=> exception here if the bucket does not exists
|
18
|
+
# ...
|
19
|
+
# bucket2 = Aws::S3::Bucket.create(s3, 'my_awesome_bucket_2', true)
|
20
|
+
# bucket2.keys #=> list of keys
|
21
|
+
# # create a bucket at the European location with public read access
|
22
|
+
# bucket3 = Aws::S3::Bucket.create(s3,'my-awesome-bucket-3', true, 'public-read', :location => :eu)
|
23
|
+
#
|
24
|
+
# see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html
|
25
|
+
# (section: Canned Access Policies)
|
26
|
+
#
|
27
|
+
def self.create(s3, name, create=false, perms=nil, headers={})
|
28
|
+
s3.bucket(name, create, perms, headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Create a bucket instance. In normal use this method should
|
33
|
+
# not be called directly.
|
34
|
+
# Use Aws::S3::Bucket.create or Aws::S3.bucket instead.
|
35
|
+
def initialize(s3, name, creation_date=nil, owner=nil)
|
36
|
+
@s3 = s3
|
37
|
+
@name = name
|
38
|
+
@owner = owner
|
39
|
+
@creation_date = creation_date
|
40
|
+
if @creation_date && !@creation_date.is_a?(Time)
|
41
|
+
@creation_date = Time.parse(@creation_date)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Return bucket name as a String.
|
46
|
+
#
|
47
|
+
# bucket = Aws::S3.bucket('my_awesome_bucket')
|
48
|
+
# puts bucket #=> 'my_awesome_bucket'
|
49
|
+
#
|
50
|
+
def to_s
|
51
|
+
@name.to_s
|
52
|
+
end
|
53
|
+
|
54
|
+
alias_method :full_name, :to_s
|
55
|
+
|
56
|
+
# Return a public link to bucket.
|
57
|
+
#
|
58
|
+
# bucket.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket'
|
59
|
+
#
|
60
|
+
def public_link
|
61
|
+
params = @s3.interface.params
|
62
|
+
"#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name}"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns the bucket location
|
66
|
+
def location
|
67
|
+
@location ||= @s3.interface.bucket_location(@name)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Retrieves the logging configuration for a bucket.
|
71
|
+
# Returns a hash of {:enabled, :targetbucket, :targetprefix}
|
72
|
+
#
|
73
|
+
# bucket.logging_info()
|
74
|
+
# => {:enabled=>true, :targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/"}
|
75
|
+
def logging_info
|
76
|
+
@s3.interface.get_logging_parse(:bucket => @name)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Enables S3 server access logging on a bucket. The target bucket must have been properly configured to receive server
|
80
|
+
# access logs.
|
81
|
+
# Params:
|
82
|
+
# :targetbucket - either the target bucket object or the name of the target bucket
|
83
|
+
# :targetprefix - the prefix under which all logs should be stored
|
84
|
+
#
|
85
|
+
# bucket.enable_logging(:targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/")
|
86
|
+
# => true
|
87
|
+
def enable_logging(params)
|
88
|
+
Utils.mandatory_arguments([:targetbucket, :targetprefix], params)
|
89
|
+
Utils.allow_only([:targetbucket, :targetprefix], params)
|
90
|
+
xmldoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><LoggingEnabled><TargetBucket>#{params[:targetbucket]}</TargetBucket><TargetPrefix>#{params[:targetprefix]}</TargetPrefix></LoggingEnabled></BucketLoggingStatus>"
|
91
|
+
@s3.interface.put_logging(:bucket => @name, :xmldoc => xmldoc)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Disables S3 server access logging on a bucket. Takes no arguments.
|
95
|
+
def disable_logging
|
96
|
+
xmldoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"></BucketLoggingStatus>"
|
97
|
+
@s3.interface.put_logging(:bucket => @name, :xmldoc => xmldoc)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Retrieve a group of keys from Amazon.
|
101
|
+
# +options+ is a hash: { 'prefix'=>'', 'marker'=>'', 'max-keys'=>5, 'delimiter'=>'' }).
|
102
|
+
# Retrieves meta-headers information if +head+ it +true+.
|
103
|
+
# Returns an array of Key instances.
|
104
|
+
#
|
105
|
+
# bucket.keys #=> # returns all keys from bucket
|
106
|
+
# bucket.keys('prefix' => 'logs') #=> # returns all keys that starts with 'logs'
|
107
|
+
#
|
108
|
+
def keys(options={}, head=false)
|
109
|
+
keys_and_service(options, head)[0]
|
110
|
+
end
|
111
|
+
|
112
|
+
# Same as +keys+ method but return an array of [keys, service_data].
|
113
|
+
# where +service_data+ is a hash with additional output information.
|
114
|
+
#
|
115
|
+
# keys, service = bucket.keys_and_service({'max-keys'=> 2, 'prefix' => 'logs'})
|
116
|
+
# p keys #=> # 2 keys array
|
117
|
+
# p service #=> {"max-keys"=>"2", "prefix"=>"logs", "name"=>"my_awesome_bucket", "marker"=>"", "is_truncated"=>true}
|
118
|
+
#
|
119
|
+
def keys_and_service(options={}, head=false)
|
120
|
+
opt = {}; options.each { |key, value| opt[key.to_s] = value }
|
121
|
+
service_data = {}
|
122
|
+
service_list = {}
|
123
|
+
list = []
|
124
|
+
@s3.interface.incrementally_list_bucket(@name, opt) do |thislist|
|
125
|
+
service_list = thislist
|
126
|
+
thislist[:contents].each do |entry|
|
127
|
+
owner = S3::Owner.new(entry[:owner_id], entry[:owner_display_name])
|
128
|
+
key = S3::Key.new(self, entry[:key], nil, {}, {}, entry[:last_modified], entry[:e_tag], entry[:size], entry[:storage_class], owner)
|
129
|
+
key.head if head
|
130
|
+
list << key
|
131
|
+
end
|
132
|
+
end
|
133
|
+
service_list.each_key do |key|
|
134
|
+
service_data[key] = service_list[key] unless (key == :contents || key == :common_prefixes)
|
135
|
+
end
|
136
|
+
[list, service_data]
|
137
|
+
end
|
138
|
+
|
139
|
+
# Retrieve key information from Amazon.
|
140
|
+
# The +key_name+ is a +String+ or Key instance.
|
141
|
+
# Retrieves meta-header information if +head+ is +true+.
|
142
|
+
# Returns new Key instance.
|
143
|
+
#
|
144
|
+
# key = bucket.key('logs/today/1.log', true) #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
145
|
+
# # is the same as:
|
146
|
+
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
|
147
|
+
# key.head
|
148
|
+
#
|
149
|
+
def key(key_name, head=false)
|
150
|
+
raise 'Key name can not be empty.' if Aws::Utils.blank?(key_name)
|
151
|
+
key_instance = nil
|
152
|
+
# if this key exists - find it ....
|
153
|
+
keys({'prefix'=>key_name}, head).each do |key|
|
154
|
+
if key.name == key_name.to_s
|
155
|
+
key_instance = key
|
156
|
+
break
|
157
|
+
end
|
158
|
+
end
|
159
|
+
# .... else this key is unknown
|
160
|
+
unless key_instance
|
161
|
+
key_instance = S3::Key.create(self, key_name.to_s)
|
162
|
+
end
|
163
|
+
key_instance
|
164
|
+
end
|
165
|
+
|
166
|
+
# Store object data.
|
167
|
+
# The +key+ is a +String+ or Key instance.
|
168
|
+
# Returns +true+.
|
169
|
+
#
|
170
|
+
# bucket.put('logs/today/1.log', 'Olala!') #=> true
|
171
|
+
#
|
172
|
+
def put(key, data=nil, meta_headers={}, perms=nil, headers={})
|
173
|
+
key = S3::Key.create(self, key.to_s, data, meta_headers) unless key.is_a?(S3::Key)
|
174
|
+
key.put(data, perms, headers)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Retrieve object data from Amazon.
|
178
|
+
# The +key+ is a +String+ or Key.
|
179
|
+
# Returns data.
|
180
|
+
#
|
181
|
+
# data = bucket.get('logs/today/1.log') #=>
|
182
|
+
# puts data #=> 'sasfasfasdf'
|
183
|
+
#
|
184
|
+
def get(key, headers={})
|
185
|
+
key = S3::Key.create(self, key.to_s) unless key.is_a?(S3::Key)
|
186
|
+
key.get(headers)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Retrieve object data from Amazon.
|
190
|
+
# The +key+ is a +String+ or Key.
|
191
|
+
# Returns Key instance.
|
192
|
+
#
|
193
|
+
# key = bucket.get('logs/today/1.log') #=>
|
194
|
+
# puts key.data #=> 'sasfasfasdf'
|
195
|
+
#
|
196
|
+
def get_key(key, headers={})
|
197
|
+
key = S3::Key.create(self, key.to_s, headers) unless key.is_a?(S3::Key)
|
198
|
+
return key
|
199
|
+
end
|
200
|
+
|
201
|
+
# Rename object. Returns Aws::S3::Key instance.
|
202
|
+
#
|
203
|
+
# new_key = bucket.rename_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
204
|
+
# puts key.name #=> 'logs/today/2.log'
|
205
|
+
# key.exists? #=> true
|
206
|
+
#
|
207
|
+
def rename_key(old_key_or_name, new_name)
|
208
|
+
old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
|
209
|
+
old_key_or_name.rename(new_name)
|
210
|
+
old_key_or_name
|
211
|
+
end
|
212
|
+
|
213
|
+
# Create an object copy. Returns a destination Aws::S3::Key instance.
|
214
|
+
#
|
215
|
+
# new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
216
|
+
# puts key.name #=> 'logs/today/2.log'
|
217
|
+
# key.exists? #=> true
|
218
|
+
#
|
219
|
+
def copy_key(old_key_or_name, new_key_or_name)
|
220
|
+
old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
|
221
|
+
old_key_or_name.copy(new_key_or_name)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Move an object to other location. Returns a destination Aws::S3::Key instance.
|
225
|
+
#
|
226
|
+
# new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
227
|
+
# puts key.name #=> 'logs/today/2.log'
|
228
|
+
# key.exists? #=> true
|
229
|
+
#
|
230
|
+
def move_key(old_key_or_name, new_key_or_name)
|
231
|
+
old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
|
232
|
+
old_key_or_name.move(new_key_or_name)
|
233
|
+
end
|
234
|
+
|
235
|
+
# Remove all keys from a bucket.
|
236
|
+
# Returns +true+.
|
237
|
+
#
|
238
|
+
# bucket.clear #=> true
|
239
|
+
#
|
240
|
+
def clear
|
241
|
+
@s3.interface.clear_bucket(@name)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Delete all keys where the 'folder_key' can be interpreted
|
245
|
+
# as a 'folder' name.
|
246
|
+
# Returns an array of string keys that have been deleted.
|
247
|
+
#
|
248
|
+
# bucket.keys.map{|key| key.name}.join(', ') #=> 'test, test/2/34, test/3, test1, test1/logs'
|
249
|
+
# bucket.delete_folder('test') #=> ['test','test/2/34','test/3']
|
250
|
+
#
|
251
|
+
def delete_folder(folder, separator='/')
|
252
|
+
@s3.interface.delete_folder(@name, folder, separator)
|
253
|
+
end
|
254
|
+
|
255
|
+
# Delete a bucket. Bucket must be empty.
|
256
|
+
# If +force+ is set, clears and deletes the bucket.
|
257
|
+
# Returns +true+.
|
258
|
+
#
|
259
|
+
# bucket.delete(true) #=> true
|
260
|
+
#
|
261
|
+
def delete(force=false)
|
262
|
+
force ? @s3.interface.force_delete_bucket(@name) : @s3.interface.delete_bucket(@name)
|
263
|
+
end
|
264
|
+
|
265
|
+
# Deletes an object from s3 in this bucket.
|
266
|
+
def delete_key(key)
|
267
|
+
@s3.interface.delete(name, key)
|
268
|
+
end
|
269
|
+
|
270
|
+
# Return a list of grantees.
|
271
|
+
#
|
272
|
+
def grantees
|
273
|
+
S3::Grantee::grantees(self)
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|