aliyun-sdk 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f304be3ae5b8631ce2fba50d0d0b8d7e6635eb79
4
- data.tar.gz: 7393a38208b5effa30efed0db2758d499f79afa4
3
+ metadata.gz: 3351c07de0b29f43528b3bcb1a3ce7acae4cd9be
4
+ data.tar.gz: e748094c575c5f22e775723d88794c92f2819d3b
5
5
  SHA512:
6
- metadata.gz: 2affe8557b33db121bfb3ba8cb123c4c16ee8f204fa1fa1f3a6583a8e1592c936c03a3a576e24eb21fb7ba290f56920df2d85a722793501af9359806c3a723ca
7
- data.tar.gz: 475ea25895a767732e9fc912d22db312e4d7ffde00ae16d253cbd3baf8d343a3d68f919562c1a2dadb910e124de02fb95d60658ba32979cd496790417b9fc33f
6
+ metadata.gz: 7ca9fac250cd61d7f9adee1012e033e29a5eeecd5c890f795b0bfb3be4e1094475eb10fcf976e78b3d1662ba8b1046329698375928495c620762bb56228a6714
7
+ data.tar.gz: d5a21aea9411798f93e44f45142abb488c67c4ec06c4b0ff7382cac289862fddac10976f488e9aac59a441b8e2528d9e6844614dd2e95b21d1cb092c09cdffaf
@@ -1,5 +1,9 @@
1
1
  ## Change Log
2
2
 
3
+ ### v0.4.0 / 2016-05-19
4
+
5
+ - Enable copy objects of different buckets(but in the same region)
6
+
3
7
  ### v0.3.7
4
8
 
5
9
  - Remove monkey patch for Hash
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Aliyun OSS SDK for Ruby
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/aliyun-sdk.svg)](https://badge.fury.io/rb/aliyun-sdk)
4
- [![Build Status](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk.svg)](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk)
4
+ [![Build Status](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk?branch=master)
5
5
  [![Coverage Status](https://coveralls.io/repos/aliyun/aliyun-oss-ruby-sdk/badge.svg?branch=master&service=github)](https://coveralls.io/github/aliyun/aliyun-oss-ruby-sdk?branch=master)
6
6
 
7
7
  -----
@@ -157,20 +157,20 @@ aliyun-sdk中包含了STS的SDK,使用时只需要`require 'aliyun/sts'`即可
157
157
  ## 模拟目录结构
158
158
 
159
159
  OSS是Object存储服务,本身不支持目录结构,所有的object都是“平”的。但是
160
- 用户可以通过设置object的key为"/foo/bar/file"这样的形式来模拟目录结构。
160
+ 用户可以通过设置object的key为"foo/bar/file"这样的形式来模拟目录结构。
161
161
  假设现在有以下Objects:
162
162
 
163
- /foo/x
164
- /foo/bar/f1
165
- /foo/bar/dir/file
166
- /foo/hello/file
163
+ foo/x
164
+ foo/bar/f1
165
+ foo/bar/dir/file
166
+ foo/hello/file
167
167
 
168
- 列出"/foo/"目录下的所有文件就是以"/foo/"为prefix进行`list_objects`,但
169
- 是这样也会把"/foo/bar/"下的所有object也列出来。为此需要用到delimiter参
168
+ 列出"foo/"目录下的所有文件就是以"foo/"为prefix进行`list_objects`,但
169
+ 是这样也会把"foo/bar/"下的所有object也列出来。为此需要用到delimiter参
170
170
  数,其含义是从prefix往后遇到第一个delimiter时停止,这中间的key作为
171
171
  Object的common prefix,包含在`list_objects`的结果中。
172
172
 
173
- objs = bucket.list_objects(:prefix => '/foo/', :delimiter => '/')
173
+ objs = bucket.list_objects(:prefix => 'foo/', :delimiter => '/')
174
174
  objs.each do |i|
175
175
  if i.is_a?(Aliyun::OSS::Object) # a object
176
176
  puts "object: #{i.key}"
@@ -179,9 +179,9 @@ Object的common prefix,包含在`list_objects`的结果中。
179
179
  end
180
180
  end
181
181
  # output
182
- object: /foo/x
183
- common prefix: /foo/bar/
184
- common prefix: /foo/hello/
182
+ object: foo/x
183
+ common prefix: foo/bar/
184
+ common prefix: foo/hello/
185
185
 
186
186
  Common prefix让用户不需要遍历所有的object(可能数量巨大)而找出前缀,
187
187
  在模拟目录结构时非常有用。
@@ -413,6 +413,7 @@ bundle exec rake test
413
413
  更多文档请查看:
414
414
 
415
415
  - 阿里云官网文档:http://help.aliyun.com/product/8314910_oss.html
416
+ - OSS官网SDK文档:https://help.aliyun.com/document_detail/oss/sdk/ruby-sdk/install.html
416
417
 
417
418
 
418
419
  [region-list]: https://help.aliyun.com/document_detail/oss/user_guide/endpoint_region.html
@@ -355,6 +355,8 @@ module Aliyun
355
355
  # @param source [String] 源object名字
356
356
  # @param dest [String] 目标object名字
357
357
  # @param opts [Hash] 拷贝object时的选项(可选)
358
+ # @option opts [String] :src_bucket 源object所属的Bucket,默认与
359
+ # 目标文件为同一个Bucket。源Bucket与目标Bucket必须属于同一个Region。
358
360
  # @option opts [String] :acl 目标文件的acl属性,默认为private
359
361
  # @option opts [String] :meta_directive 指定是否拷贝源object的
360
362
  # meta信息,默认为{OSS::MetaDirective::COPY}:即拷贝object的时
@@ -28,7 +28,7 @@ module Aliyun
28
28
  # KEY SECRET,如果不填则会尝试匿名访问
29
29
  # @option opts [Boolean] :cname [可选] 指定endpoint是否是用户绑
30
30
  # 定的域名
31
- # @option opts [Boolean] :sts_token [可选] 指定STS的
31
+ # @option opts [String] :sts_token [可选] 指定STS的
32
32
  # SecurityToken,如果指定,则使用STS授权访问
33
33
  # @option opts [Fixnum] :open_timeout [可选] 指定建立连接的超时
34
34
  # 时间,默认为10秒
@@ -829,11 +829,14 @@ module Aliyun
829
829
  end
830
830
 
831
831
  # Copy an object in the bucket. The source object and the dest
832
- # object must be in the same bucket.
832
+ # object may be from different buckets of the same region.
833
833
  # @param bucket_name [String] the bucket name
834
834
  # @param src_object_name [String] the source object name
835
835
  # @param dst_object_name [String] the dest object name
836
836
  # @param opts [Hash] options
837
+ # @option opts [String] :src_bucket specify the source object's
838
+ # bucket. It MUST be in the same region as the dest bucket. It
839
+ # defaults to dest bucket if not specified.
837
840
  # @option opts [String] :acl specify the dest object's
838
841
  # ACL. See {OSS::ACL}
839
842
  # @option opts [String] :meta_directive specify what to do
@@ -857,9 +860,10 @@ module Aliyun
857
860
  "source object: #{src_object_name}, dest object: "\
858
861
  "#{dst_object_name}, options: #{opts}")
859
862
 
863
+ src_bucket = opts[:src_bucket] || bucket_name
860
864
  headers = {
861
865
  'x-oss-copy-source' =>
862
- @http.get_resource_path(bucket_name, src_object_name),
866
+ @http.get_resource_path(src_bucket, src_object_name),
863
867
  'content-type' => opts[:content_type]
864
868
  }
865
869
  (opts[:metas] || {})
@@ -1096,8 +1100,11 @@ module Aliyun
1096
1100
  # @param part_no [Integer] the part number
1097
1101
  # @param source_object [String] the source object name to copy from
1098
1102
  # @param opts [Hash] options
1103
+ # @option opts [String] :src_bucket specify the source object's
1104
+ # bucket. It MUST be in the same region as the dest bucket. It
1105
+ # defaults to dest bucket if not specified.
1099
1106
  # @option opts [Array<Integer>] :range the bytes range to
1100
- # copy, int the format: [begin(inclusive), end(exclusive]
1107
+ # copy, int the format: [begin(inclusive), end(exclusive)]
1101
1108
  # @option opts [Hash] :condition preconditions to copy the
1102
1109
  # object. See #get_object
1103
1110
  def upload_part_by_copy(
@@ -1113,9 +1120,10 @@ module Aliyun
1113
1120
  fail ClientError, "Range must be an array containing 2 Integers."
1114
1121
  end
1115
1122
 
1123
+ src_bucket = opts[:src_bucket] || bucket_name
1116
1124
  headers = {
1117
1125
  'x-oss-copy-source' =>
1118
- @http.get_resource_path(bucket_name, source_object)
1126
+ @http.get_resource_path(src_bucket, source_object)
1119
1127
  }
1120
1128
  headers['range'] = get_bytes_range(range) if range
1121
1129
  headers.merge!(get_copy_conditions(conditions)) if conditions
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aliyun
4
4
 
5
- VERSION = "0.3.7"
5
+ VERSION = "0.4.0"
6
6
 
7
7
  end # Aliyun
@@ -228,6 +228,25 @@ module Aliyun
228
228
  .with(:body => nil, :query => query, :headers => headers)
229
229
  end
230
230
 
231
+ it "should upload a part by copy object from different bucket" do
232
+ txn_id = 'xxxyyyzzz'
233
+ part_no = 1
234
+ src_bucket = 'source-bucket'
235
+ copy_source = "/#{src_bucket}/src_obj"
236
+
237
+ query = {'partNumber' => part_no, 'uploadId' => txn_id}
238
+ headers = {'x-oss-copy-source' => copy_source}
239
+
240
+ stub_request(:put, request_path)
241
+ .with(:query => query, :headers => headers)
242
+
243
+ @protocol.upload_part_by_copy(
244
+ @bucket, @object, txn_id, part_no, 'src_obj', :src_bucket => src_bucket)
245
+
246
+ expect(WebMock).to have_requested(:put, request_path)
247
+ .with(:body => nil, :query => query, :headers => headers)
248
+ end
249
+
231
250
  it "should return part etag" do
232
251
  txn_id = 'xxxyyyzzz'
233
252
  part_no = 1
@@ -23,8 +23,8 @@ module Aliyun
23
23
  p
24
24
  end
25
25
 
26
- def get_resource_path(object)
27
- "/#{@bucket}/#{object}"
26
+ def get_resource_path(object, bucket = nil)
27
+ "/#{bucket || @bucket}/#{object}"
28
28
  end
29
29
 
30
30
  def mock_copy_object(last_modified, etag)
@@ -314,6 +314,28 @@ module Aliyun
314
314
  expect(result[:etag]).to eq(etag)
315
315
  end
316
316
 
317
+ it "should copy object of different buckets" do
318
+ src_bucket = 'source-bucket'
319
+ src_object = 'ruby'
320
+ dst_object = 'rails'
321
+ url = get_request_path(dst_object)
322
+
323
+ last_modified = Time.parse(Time.now.rfc822)
324
+ etag = '0000'
325
+ stub_request(:put, url).to_return(
326
+ :body => mock_copy_object(last_modified, etag))
327
+
328
+ result = @protocol.copy_object(
329
+ @bucket, src_object, dst_object, :src_bucket => src_bucket)
330
+
331
+ expect(WebMock).to have_requested(:put, url)
332
+ .with(:body => nil, :headers => {
333
+ 'x-oss-copy-source' => get_resource_path(src_object, src_bucket)})
334
+
335
+ expect(result[:last_modified]).to eq(last_modified)
336
+ expect(result[:etag]).to eq(etag)
337
+ end
338
+
317
339
  it "should set acl and conditions when copy object" do
318
340
  src_object = 'ruby'
319
341
  dst_object = 'rails'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliyun-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tianlong Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-20 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri