aws-ext 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -4
- data/VERSION +1 -1
- data/aws-ext.gemspec +1 -1
- data/lib/aws-ext.rb +1 -1
- data/spec/aws-ext_spec.rb +46 -44
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -8,13 +8,17 @@ Extensions for the aws-s3 gem
|
|
8
8
|
|
9
9
|
== S3Object
|
10
10
|
|
11
|
-
=== .copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy)
|
11
|
+
=== .copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy = :public_read)
|
12
12
|
|
13
|
-
Copies arbitrary S3Object across buckets using the Amazon S3 copy option. ACLs
|
13
|
+
Copies arbitrary S3Object across buckets using the Amazon S3 copy option. ACLs
|
14
|
+
default to :public_read. Passing :copy as the ACL will copy the ACL from the
|
15
|
+
source.
|
14
16
|
|
15
17
|
=== #copy_to_bucket(dest_bucket, dest_key = nil, acl_policy = :copy)
|
16
18
|
|
17
|
-
Copies this S3Object across buckets using the Amazon S3 copy option.
|
19
|
+
Copies this S3Object across buckets using the Amazon S3 copy option.
|
20
|
+
Destination key defaults to Source key. Passing :copy as the ACL will copy the
|
21
|
+
ACL form the source.
|
18
22
|
|
19
23
|
== Bucket
|
20
24
|
|
@@ -41,7 +45,8 @@ Paginates over all objects in the bucket. :max_keys defaults to 100.
|
|
41
45
|
* Add tests for it. This is important so I don't break it in a
|
42
46
|
future version unintentionally.
|
43
47
|
* Commit, do not mess with rakefile, version, or history.
|
44
|
-
(if you want to have your own version, that is fine but bump version in a
|
48
|
+
(if you want to have your own version, that is fine but bump version in a
|
49
|
+
commit by itself I can ignore when I pull)
|
45
50
|
* Send me a pull request. Bonus points for topic branches.
|
46
51
|
|
47
52
|
== Copyright
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/aws-ext.gemspec
CHANGED
data/lib/aws-ext.rb
CHANGED
@@ -3,7 +3,7 @@ require 'aws/s3'
|
|
3
3
|
module AWS
|
4
4
|
module S3
|
5
5
|
class S3Object
|
6
|
-
def self.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy)
|
6
|
+
def self.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy = :public_read)
|
7
7
|
headers = {'x-amz-copy-source' => path!(src_bucket, src_key)}
|
8
8
|
if acl_policy == :copy
|
9
9
|
returning put(path!(dest_bucket, dest_key), headers) do
|
data/spec/aws-ext_spec.rb
CHANGED
@@ -47,54 +47,56 @@ describe 'aws_ext' do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
context "AWS::S3::S3Object" do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
dest_bucket_name = 'dest_bucket'
|
55
|
-
dest_bucket = AWS::S3::Bucket.new(:name => dest_bucket_name)
|
56
|
-
AWS::S3::S3Object.should_receive(:copy_across_buckets).with(src_bucket_name, key, dest_bucket_name, key, :copy)
|
57
|
-
AWS::S3::S3Object.new(:bucket => src_bucket, 'key' => key).copy_to_bucket(dest_bucket)
|
58
|
-
end
|
50
|
+
let(:src_key) { 'src_key' }
|
51
|
+
let(:dest_key) { 'dest_key' }
|
52
|
+
let(:src_bucket) { 'src_bucket' }
|
53
|
+
let(:dest_bucket) { 'dest_bucket' }
|
59
54
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
AWS::S3::S3Object.new(:bucket => src_bucket, 'key' => src_key).copy_to_bucket(dest_bucket, dest_key, acl)
|
70
|
-
end
|
55
|
+
describe "#copy_to_bucket" do
|
56
|
+
let(:s3bucket_src) { AWS::S3::Bucket.new(:name => src_bucket) }
|
57
|
+
let(:s3bucket_dest) { AWS::S3::Bucket.new(:name => dest_bucket) }
|
58
|
+
let(:s3object) { AWS::S3::S3Object.new(:bucket => s3bucket_src, 'key' => src_key) }
|
59
|
+
|
60
|
+
it "#copy_to_bucket delegates to S3Object.copy_across_buckets with defaults" do
|
61
|
+
AWS::S3::S3Object.should_receive(:copy_across_buckets).with(src_bucket, src_key, dest_bucket, src_key, :copy)
|
62
|
+
s3object.copy_to_bucket(s3bucket_dest)
|
63
|
+
end
|
71
64
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
dest_bucket = 'dest_bucket'
|
78
|
-
headers = {}
|
79
|
-
headers['x-amz-copy-source'] = AWS::S3::S3Object.path!(src_bucket, src_key)
|
80
|
-
headers['x-amz-acl'] = acl
|
81
|
-
AWS::S3::S3Object.should_receive(:put).with(AWS::S3::S3Object.path!(dest_bucket, dest_key), headers)
|
82
|
-
AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, :public_read)
|
65
|
+
it "#copy_to_bucket delegates to S3Object.copy_across_buckets without defaults" do
|
66
|
+
acl = :public_read
|
67
|
+
AWS::S3::S3Object.should_receive(:copy_across_buckets).with(src_bucket, src_key, dest_bucket, dest_key, acl)
|
68
|
+
s3object.copy_to_bucket(s3bucket_dest, dest_key, acl)
|
69
|
+
end
|
83
70
|
end
|
84
71
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
72
|
+
describe ".copy_across_buckets" do
|
73
|
+
let(:dest_path) { AWS::S3::S3Object.path!(dest_bucket, dest_key) }
|
74
|
+
let(:copy_header) { {'x-amz-copy-source' => AWS::S3::S3Object.path!(src_bucket, src_key)} }
|
75
|
+
|
76
|
+
it "delegates to put with the destination path" do
|
77
|
+
AWS::S3::S3Object.should_receive(:put).with(dest_path, anything)
|
78
|
+
AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "delegates to put with copy source set" do
|
82
|
+
AWS::S3::S3Object.should_receive(:put).with(anything, hash_including(copy_header))
|
83
|
+
AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "delegates to put with the requested canned acl policy" do
|
87
|
+
acl = :private
|
88
|
+
acl_header = {'x-amz-acl' => acl }
|
89
|
+
AWS::S3::S3Object.should_receive(:put).with(anything, hash_including(acl_header))
|
90
|
+
AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "when acl is :copy, copies the existing acl policy" do
|
94
|
+
returned_acl = 'returned_acl'
|
95
|
+
AWS::S3::S3Object.should_receive(:acl).with(src_key, src_bucket).and_return(returned_acl)
|
96
|
+
AWS::S3::S3Object.should_receive(:acl).with(dest_key, dest_bucket, returned_acl)
|
97
|
+
AWS::S3::S3Object.stub(:put)
|
98
|
+
AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, :copy)
|
99
|
+
end
|
98
100
|
end
|
99
101
|
|
100
102
|
end
|