aws 2.3.34 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/acf/{right_acf_interface.rb → acf_interface.rb} +87 -57
- data/lib/aws.rb +9 -9
- data/lib/awsbase/aws_response_array.rb +21 -21
- data/lib/awsbase/awsbase.rb +579 -0
- data/lib/awsbase/benchmark_fix.rb +2 -2
- data/lib/awsbase/errors.rb +288 -0
- data/lib/awsbase/parsers.rb +227 -0
- data/lib/awsbase/support.rb +114 -114
- data/lib/awsbase/utils.rb +207 -0
- data/lib/ec2/ec2.rb +2070 -0
- data/lib/ec2/mon_interface.rb +243 -0
- data/lib/elb/elb_interface.rb +278 -276
- data/lib/iam/iam.rb +111 -109
- data/lib/rds/rds.rb +3 -1
- data/lib/right_aws.rb +9 -9
- data/lib/s3/bucket.rb +265 -0
- data/lib/s3/grantee.rb +238 -0
- data/lib/s3/key.rb +281 -0
- data/lib/s3/s3.rb +346 -0
- data/lib/s3/s3_interface.rb +1275 -0
- data/lib/sdb/active_sdb.rb +2 -0
- data/lib/sdb/sdb_interface.rb +886 -0
- data/lib/sqs/{right_sqs.rb → sqs.rb} +10 -0
- data/lib/sqs/sqs_interface.rb +483 -0
- data/test/s3/s3_test_base.rb +23 -0
- data/test/s3/test_s3.rb +156 -419
- data/test/s3/test_s3_class.rb +179 -0
- data/test/s3/test_s3_rights.rb +139 -0
- data/test/sqs/test_sqs.rb +19 -0
- metadata +27 -15
- data/lib/awsbase/right_awsbase.rb +0 -1254
- data/lib/ec2/right_ec2.rb +0 -1884
- data/lib/ec2/right_mon_interface.rb +0 -232
- data/lib/s3/right_s3.rb +0 -1115
- data/lib/s3/right_s3_interface.rb +0 -1253
- data/lib/sdb/right_sdb_interface.rb +0 -881
- data/lib/sqs/right_sqs_interface.rb +0 -443
data/lib/iam/iam.rb
CHANGED
@@ -1,118 +1,120 @@
|
|
1
1
|
module Aws
|
2
2
|
|
3
|
-
|
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
|
-
@@bench = AwsBenchmarkingBlock.new
|
16
|
-
|
17
|
-
def self.bench_xml
|
18
|
-
@@bench.xml
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.bench_ec2
|
22
|
-
@@bench.service
|
23
|
-
end
|
24
|
-
|
25
|
-
# Current API version (sometimes we have to check it outside the GEM).
|
26
|
-
@@api = ENV['IAM_API_VERSION'] || API_VERSION
|
27
|
-
|
28
|
-
def self.api
|
29
|
-
@@api
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
34
|
-
init({:name => 'IAM',
|
35
|
-
:default_host => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).host : DEFAULT_HOST,
|
36
|
-
:default_port => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).port : DEFAULT_PORT,
|
37
|
-
:default_service => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).path : DEFAULT_PATH,
|
38
|
-
:default_protocol => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).scheme : DEFAULT_PROTOCOL,
|
39
|
-
:api_version => API_VERSION},
|
40
|
-
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
41
|
-
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
42
|
-
params)
|
43
|
-
end
|
44
|
-
|
45
|
-
def do_request(action, params, options={})
|
46
|
-
link = generate_request(action, params)
|
47
|
-
p link[:request]
|
48
|
-
resp = request_info_xml_simple(:iam_connection, @params, link, @logger,
|
49
|
-
:group_tags =>{"LoadBalancersDescriptions"=>"LoadBalancersDescription",
|
50
|
-
"DBParameterGroups" =>"DBParameterGroup",
|
51
|
-
"DBSecurityGroups" =>"DBSecurityGroup",
|
52
|
-
"EC2SecurityGroups" =>"EC2SecurityGroup",
|
53
|
-
"IPRanges" =>"IPRange"},
|
54
|
-
:force_array =>["DBInstances",
|
55
|
-
"DBParameterGroups",
|
56
|
-
"DBSecurityGroups",
|
57
|
-
"EC2SecurityGroups",
|
58
|
-
"IPRanges"],
|
59
|
-
:pull_out_array =>options[:pull_out_array],
|
60
|
-
:pull_out_single=>options[:pull_out_single],
|
61
|
-
:wrapper =>options[:wrapper])
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
#-----------------------------------------------------------------
|
66
|
-
# REQUESTS
|
67
|
-
#-----------------------------------------------------------------
|
68
|
-
|
69
|
-
|
70
|
-
# options:
|
71
|
-
# :marker => value received from previous response if IsTruncated = true
|
72
|
-
# :max_items => number of items you want returned
|
73
|
-
# :path_previx => for filtering results, default is /
|
74
|
-
def list_server_certificates(options={})
|
75
|
-
@logger.info("Listing server certificates...")
|
76
|
-
|
77
|
-
params = {}
|
78
|
-
params['Marker'] = options[:marker] if options[:marker]
|
79
|
-
params['MaxItems'] = options[:max_items] if options[:max_items]
|
80
|
-
params['PathPrefix'] = options[:path_prefix] if options[:path_prefix]
|
81
|
-
|
82
|
-
resp = do_request("ListServerCertificates", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
|
83
|
-
|
84
|
-
|
85
|
-
rescue Exception
|
86
|
-
on_exception
|
87
|
-
end
|
88
|
-
|
89
|
-
#
|
90
|
-
# name: name of certificate
|
91
|
-
# public_key: public key certificate in PEM-encoded format
|
92
|
-
# private_key: private key in PEM-encoded format
|
93
|
-
# options:
|
94
|
-
# :path => specify a path you want it stored in
|
95
|
-
# :certificate_chain => contents of certificate chain
|
96
|
-
def upload_server_certificate(name, public_key, private_key, options={})
|
97
|
-
params = {}
|
98
|
-
params['ServerCertificateName'] = name
|
99
|
-
params['PrivateKey'] = private_key
|
100
|
-
params['CertificateBody'] = public_key
|
101
|
-
|
102
|
-
params['CertificateChain'] = options[:certificate_chain] if options[:certificate_chain]
|
103
|
-
params['Path'] = options[:path] if options[:path]
|
3
|
+
require 'xmlsimple'
|
104
4
|
|
105
|
-
|
106
|
-
|
107
|
-
resp = do_request("UploadServerCertificate", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
|
108
|
-
|
109
|
-
|
110
|
-
rescue Exception
|
111
|
-
on_exception
|
112
|
-
end
|
5
|
+
class Iam < AwsBase
|
113
6
|
|
7
|
+
include AwsBaseInterface
|
114
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
|
+
@@bench = AwsBenchmarkingBlock.new
|
16
|
+
def self.bench
|
17
|
+
@@bench
|
18
|
+
end
|
19
|
+
def self.bench_xml
|
20
|
+
@@bench.xml
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.bench_ec2
|
24
|
+
@@bench.service
|
25
|
+
end
|
26
|
+
|
27
|
+
# Current API version (sometimes we have to check it outside the GEM).
|
28
|
+
@@api = ENV['IAM_API_VERSION'] || API_VERSION
|
29
|
+
|
30
|
+
def self.api
|
31
|
+
@@api
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
36
|
+
init({:name => 'IAM',
|
37
|
+
:default_host => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).host : DEFAULT_HOST,
|
38
|
+
:default_port => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).port : DEFAULT_PORT,
|
39
|
+
:default_service => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).path : DEFAULT_PATH,
|
40
|
+
:default_protocol => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).scheme : DEFAULT_PROTOCOL,
|
41
|
+
:api_version => API_VERSION},
|
42
|
+
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
|
43
|
+
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
44
|
+
params)
|
45
|
+
end
|
46
|
+
|
47
|
+
def do_request(action, params, options={})
|
48
|
+
link = generate_request(action, params)
|
49
|
+
p link[:request]
|
50
|
+
resp = request_info_xml_simple(:iam_connection, @params, link, @logger,
|
51
|
+
:group_tags =>{"LoadBalancersDescriptions"=>"LoadBalancersDescription",
|
52
|
+
"DBParameterGroups" =>"DBParameterGroup",
|
53
|
+
"DBSecurityGroups" =>"DBSecurityGroup",
|
54
|
+
"EC2SecurityGroups" =>"EC2SecurityGroup",
|
55
|
+
"IPRanges" =>"IPRange"},
|
56
|
+
:force_array =>["DBInstances",
|
57
|
+
"DBParameterGroups",
|
58
|
+
"DBSecurityGroups",
|
59
|
+
"EC2SecurityGroups",
|
60
|
+
"IPRanges"],
|
61
|
+
:pull_out_array =>options[:pull_out_array],
|
62
|
+
:pull_out_single=>options[:pull_out_single],
|
63
|
+
:wrapper =>options[:wrapper])
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
#-----------------------------------------------------------------
|
68
|
+
# REQUESTS
|
69
|
+
#-----------------------------------------------------------------
|
70
|
+
|
71
|
+
|
72
|
+
# options:
|
73
|
+
# :marker => value received from previous response if IsTruncated = true
|
74
|
+
# :max_items => number of items you want returned
|
75
|
+
# :path_previx => for filtering results, default is /
|
76
|
+
def list_server_certificates(options={})
|
77
|
+
@logger.info("Listing server certificates...")
|
78
|
+
|
79
|
+
params = {}
|
80
|
+
params['Marker'] = options[:marker] if options[:marker]
|
81
|
+
params['MaxItems'] = options[:max_items] if options[:max_items]
|
82
|
+
params['PathPrefix'] = options[:path_prefix] if options[:path_prefix]
|
83
|
+
|
84
|
+
resp = do_request("ListServerCertificates", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
|
85
|
+
|
86
|
+
|
87
|
+
rescue Exception
|
88
|
+
on_exception
|
115
89
|
end
|
116
90
|
|
91
|
+
#
|
92
|
+
# name: name of certificate
|
93
|
+
# public_key: public key certificate in PEM-encoded format
|
94
|
+
# private_key: private key in PEM-encoded format
|
95
|
+
# options:
|
96
|
+
# :path => specify a path you want it stored in
|
97
|
+
# :certificate_chain => contents of certificate chain
|
98
|
+
def upload_server_certificate(name, public_key, private_key, options={})
|
99
|
+
params = {}
|
100
|
+
params['ServerCertificateName'] = name
|
101
|
+
params['PrivateKey'] = private_key
|
102
|
+
params['CertificateBody'] = public_key
|
103
|
+
|
104
|
+
params['CertificateChain'] = options[:certificate_chain] if options[:certificate_chain]
|
105
|
+
params['Path'] = options[:path] if options[:path]
|
106
|
+
|
107
|
+
p params
|
108
|
+
|
109
|
+
resp = do_request("UploadServerCertificate", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
|
110
|
+
|
111
|
+
|
112
|
+
rescue Exception
|
113
|
+
on_exception
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
118
|
+
|
117
119
|
|
118
120
|
end
|
data/lib/rds/rds.rb
CHANGED
data/lib/right_aws.rb
CHANGED
@@ -37,15 +37,15 @@ require 'right_http_connection'
|
|
37
37
|
$:.unshift(File.dirname(__FILE__))
|
38
38
|
require 'awsbase/benchmark_fix'
|
39
39
|
require 'awsbase/support'
|
40
|
-
require 'awsbase/
|
41
|
-
require 'ec2/
|
42
|
-
require 'ec2/
|
43
|
-
require 's3/
|
44
|
-
require 's3/
|
45
|
-
require 'sqs/
|
46
|
-
require 'sqs/
|
47
|
-
require 'sdb/
|
48
|
-
require 'acf/
|
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
49
|
require 'elb/elb_interface'
|
50
50
|
|
51
51
|
|
data/lib/s3/bucket.rb
ADDED
@@ -0,0 +1,265 @@
|
|
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
|
+
AwsUtils.mandatory_arguments([:targetbucket, :targetprefix], params)
|
89
|
+
AwsUtils.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
|
+
thislist = {}
|
123
|
+
list = []
|
124
|
+
@s3.interface.incrementally_list_bucket(@name, opt) do |thislist|
|
125
|
+
thislist[:contents].each do |entry|
|
126
|
+
owner = S3::Owner.new(entry[:owner_id], entry[:owner_display_name])
|
127
|
+
key = S3::Key.new(self, entry[:key], nil, {}, {}, entry[:last_modified], entry[:e_tag], entry[:size], entry[:storage_class], owner)
|
128
|
+
key.head if head
|
129
|
+
list << key
|
130
|
+
end
|
131
|
+
end
|
132
|
+
thislist.each_key do |key|
|
133
|
+
service_data[key] = thislist[key] unless (key == :contents || key == :common_prefixes)
|
134
|
+
end
|
135
|
+
[list, service_data]
|
136
|
+
end
|
137
|
+
|
138
|
+
# Retrieve key information from Amazon.
|
139
|
+
# The +key_name+ is a +String+ or Key instance.
|
140
|
+
# Retrieves meta-header information if +head+ is +true+.
|
141
|
+
# Returns new Key instance.
|
142
|
+
#
|
143
|
+
# key = bucket.key('logs/today/1.log', true) #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
144
|
+
# # is the same as:
|
145
|
+
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
|
146
|
+
# key.head
|
147
|
+
#
|
148
|
+
def key(key_name, head=false)
|
149
|
+
raise 'Key name can not be empty.' if key_name.blank?
|
150
|
+
key_instance = nil
|
151
|
+
# if this key exists - find it ....
|
152
|
+
keys({'prefix'=>key_name}, head).each do |key|
|
153
|
+
if key.name == key_name.to_s
|
154
|
+
key_instance = key
|
155
|
+
break
|
156
|
+
end
|
157
|
+
end
|
158
|
+
# .... else this key is unknown
|
159
|
+
unless key_instance
|
160
|
+
key_instance = S3::Key.create(self, key_name.to_s)
|
161
|
+
end
|
162
|
+
key_instance
|
163
|
+
end
|
164
|
+
|
165
|
+
# Store object data.
|
166
|
+
# The +key+ is a +String+ or Key instance.
|
167
|
+
# Returns +true+.
|
168
|
+
#
|
169
|
+
# bucket.put('logs/today/1.log', 'Olala!') #=> true
|
170
|
+
#
|
171
|
+
def put(key, data=nil, meta_headers={}, perms=nil, headers={})
|
172
|
+
key = S3::Key.create(self, key.to_s, data, meta_headers) unless key.is_a?(S3::Key)
|
173
|
+
key.put(data, perms, headers)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Retrieve object data from Amazon.
|
177
|
+
# The +key+ is a +String+ or Key.
|
178
|
+
# Returns Key instance.
|
179
|
+
#
|
180
|
+
# key = bucket.get('logs/today/1.log') #=>
|
181
|
+
# puts key.data #=> 'sasfasfasdf'
|
182
|
+
#
|
183
|
+
def get(key, headers={})
|
184
|
+
key = S3::Key.create(self, key.to_s) unless key.is_a?(S3::Key)
|
185
|
+
key.get(headers)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Rename object. Returns Aws::S3::Key instance.
|
189
|
+
#
|
190
|
+
# new_key = bucket.rename_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
191
|
+
# puts key.name #=> 'logs/today/2.log'
|
192
|
+
# key.exists? #=> true
|
193
|
+
#
|
194
|
+
def rename_key(old_key_or_name, new_name)
|
195
|
+
old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
|
196
|
+
old_key_or_name.rename(new_name)
|
197
|
+
old_key_or_name
|
198
|
+
end
|
199
|
+
|
200
|
+
# Create an object copy. Returns a destination Aws::S3::Key instance.
|
201
|
+
#
|
202
|
+
# new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
203
|
+
# puts key.name #=> 'logs/today/2.log'
|
204
|
+
# key.exists? #=> true
|
205
|
+
#
|
206
|
+
def copy_key(old_key_or_name, new_key_or_name)
|
207
|
+
old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
|
208
|
+
old_key_or_name.copy(new_key_or_name)
|
209
|
+
end
|
210
|
+
|
211
|
+
# Move an object to other location. Returns a destination Aws::S3::Key instance.
|
212
|
+
#
|
213
|
+
# new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
214
|
+
# puts key.name #=> 'logs/today/2.log'
|
215
|
+
# key.exists? #=> true
|
216
|
+
#
|
217
|
+
def move_key(old_key_or_name, new_key_or_name)
|
218
|
+
old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
|
219
|
+
old_key_or_name.move(new_key_or_name)
|
220
|
+
end
|
221
|
+
|
222
|
+
# Remove all keys from a bucket.
|
223
|
+
# Returns +true+.
|
224
|
+
#
|
225
|
+
# bucket.clear #=> true
|
226
|
+
#
|
227
|
+
def clear
|
228
|
+
@s3.interface.clear_bucket(@name)
|
229
|
+
end
|
230
|
+
|
231
|
+
# Delete all keys where the 'folder_key' can be interpreted
|
232
|
+
# as a 'folder' name.
|
233
|
+
# Returns an array of string keys that have been deleted.
|
234
|
+
#
|
235
|
+
# bucket.keys.map{|key| key.name}.join(', ') #=> 'test, test/2/34, test/3, test1, test1/logs'
|
236
|
+
# bucket.delete_folder('test') #=> ['test','test/2/34','test/3']
|
237
|
+
#
|
238
|
+
def delete_folder(folder, separator='/')
|
239
|
+
@s3.interface.delete_folder(@name, folder, separator)
|
240
|
+
end
|
241
|
+
|
242
|
+
# Delete a bucket. Bucket must be empty.
|
243
|
+
# If +force+ is set, clears and deletes the bucket.
|
244
|
+
# Returns +true+.
|
245
|
+
#
|
246
|
+
# bucket.delete(true) #=> true
|
247
|
+
#
|
248
|
+
def delete(force=false)
|
249
|
+
force ? @s3.interface.force_delete_bucket(@name) : @s3.interface.delete_bucket(@name)
|
250
|
+
end
|
251
|
+
|
252
|
+
# Deletes an object from s3 in this bucket.
|
253
|
+
def delete_key(key)
|
254
|
+
@s3.interface.delete(name, key)
|
255
|
+
end
|
256
|
+
|
257
|
+
# Return a list of grantees.
|
258
|
+
#
|
259
|
+
def grantees
|
260
|
+
Grantee::grantees(self)
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|