aliyun-sdk 0.3.5 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 002610ac26720b767cd7218d665da92926081f17
4
- data.tar.gz: 62a0a01d10c1fe2f944c7247f6b52a5cf35a6e60
3
+ metadata.gz: adaf526c24ef420d2ee095742e60eb898656a67f
4
+ data.tar.gz: 9a3827d7efe46ebce561983a42cad93d56036dc4
5
5
  SHA512:
6
- metadata.gz: 783dd45bcc4db86557e81a383f0de230e5c937d060c6cb8ff00cab296a67f963b718c2e13d32e1fdbdf9926f8f165a851f826eb68b53fb62252ed76ccc12c4c2
7
- data.tar.gz: 2742836c20960f9dd4df8f546a144ddebae62677f2d650108c3677dc9038bb4d71020356c99a5e3368bc323f5a11e63a45aef37670bce3cd1d82eed2bd500407
6
+ metadata.gz: ac6518e978b92b880614513e46ee00e34f5224c497cb9522e4419e49f01d71ea077b61d9cfda680f18fde9dd8c52871e59d8b06c5b4bb2c5d61b93c408eecdd9
7
+ data.tar.gz: 8cfc5141a37ab81d18b9e26dba0046c2cf7eda11501b5b25313e85d17847b0f5f4fc288d06ddec21d6d7722f212a7e88d150916cc0a1b45104db84decfcce516
@@ -1,5 +1,12 @@
1
1
  ## Change Log
2
2
 
3
+ ### v0.3.6
4
+
5
+ - Fix Zlib::Inflate in ruby-1.9.x
6
+ - Add function test(tests/) in travis CI
7
+ - Add Gem version badge
8
+ - Support IP endpoint
9
+
3
10
  ### v0.3.5
4
11
 
5
12
  - Fix the issue that StreamWriter will read more bytes than wanted
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Aliyun OSS SDK for Ruby
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/aliyun-sdk.svg)](https://badge.fury.io/rb/aliyun-sdk)
3
4
  [![Build Status](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk.svg)](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk)
4
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)
5
6
 
@@ -325,6 +326,7 @@ Multipart的功能,可以在上传/下载时将大文件进行分片传输。A
325
326
  puts obj.metas
326
327
 
327
328
  关于meta信息有以下几点需要注意:
329
+
328
330
  1. meta信息的key和value都只能是简单的ASCII非换行字符,并且总的大小不能超过8KB。
329
331
  2. Copy object时默认将拷贝源object的meta信息,如果用户不希望这么做,需要
330
332
  显式地将`:meta_directive`设置成{Aliyun::OSS::MetaDirective::REPLACE}
@@ -395,14 +397,16 @@ SDK的examples/目录下有一些展示SDK功能的示例程序,用户稍加
395
397
 
396
398
  ## 运行测试
397
399
 
398
- SDK采用rspec进行测试,如果要对SDK进行修改,请确保没有break现有测试。测
399
- 试运行的方法是,在ruby-sdk/目录下运行:
400
-
401
- rspec
400
+ ```bash
401
+ bundle exec rake spec
402
402
 
403
- 或者用bundle和rake:
403
+ export RUBY_SDK_OSS_ENDPOINT=endpoint
404
+ export RUBY_SDK_OSS_ID=AccessKeyId
405
+ export RUBY_SDK_OSS_KEY=AccessKeySecret
406
+ export RUBY_SDK_OSS_BUCKET=bucket-name
404
407
 
405
- bundle exec rake spec
408
+ bundle exec rake test
409
+ ```
406
410
 
407
411
  ## 更多
408
412
 
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  require 'rest-client'
4
+ require 'resolv'
4
5
  require 'fiber'
5
6
 
6
7
  module Aliyun
@@ -138,21 +139,22 @@ module Aliyun
138
139
  end
139
140
 
140
141
  def get_request_url(bucket, object)
141
- url = ""
142
- url += "#{@config.endpoint.scheme}://"
143
- url += "#{bucket}." if bucket and not @config.cname
144
- url += @config.endpoint.host
145
- url += "/#{CGI.escape(object)}" if object
146
-
147
- url
142
+ url = @config.endpoint.dup
143
+ isIP = !!(url.host =~ Resolv::IPv4::Regex)
144
+ url.host = "#{bucket}." + url.host if bucket && !@config.cname && !isIP
145
+ url.path = '/'
146
+ url.path << "#{bucket}/" if bucket && isIP
147
+ url.path << "#{CGI.escape(object)}" if object
148
+
149
+ url.to_s
148
150
  end
149
151
 
150
152
  def get_resource_path(bucket, object)
151
- if bucket
152
- res = "/#{bucket}/"
153
- res += "#{object}" if object
154
- res
155
- end
153
+ res = '/'
154
+ res << "#{bucket}/" if bucket
155
+ res << "#{object}" if object
156
+
157
+ res
156
158
  end
157
159
 
158
160
  # Handle Net::HTTPRespoonse
@@ -170,14 +172,24 @@ module Aliyun
170
172
  elsif encoding == 'deflate'
171
173
  begin
172
174
  stream = Zlib::Inflate.new
173
- r.read_body { |chunk| stream << chunk }
174
- stream.finish { |chunk| yield chunk }
175
+ # 1.9.x doesn't support streaming inflate
176
+ if RUBY_VERSION < '2.0.0'
177
+ yield stream.inflate(r.read_body)
178
+ else
179
+ r.read_body { |chunk| stream << chunk }
180
+ stream.finish { |chunk| yield chunk }
181
+ end
175
182
  rescue Zlib::DataError
176
183
  # No luck with Zlib decompression. Let's try with raw deflate,
177
184
  # like some broken web servers do.
178
185
  stream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
179
- r.read_body { |chunk| stream << chunk }
180
- stream.finish { |chunk| yield chunk }
186
+ # 1.9.x doesn't support streaming inflate
187
+ if RUBY_VERSION < '2.0.0'
188
+ yield stream.inflate(r.read_body)
189
+ else
190
+ r.read_body { |chunk| stream << chunk }
191
+ stream.finish { |chunk| yield chunk }
192
+ end
181
193
  end
182
194
  else
183
195
  r.read_body { |chunk| yield chunk }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aliyun
4
4
 
5
- VERSION = "0.3.5"
5
+ VERSION = "0.3.6"
6
6
 
7
7
  end # Aliyun
@@ -158,7 +158,7 @@ module Aliyun
158
158
 
159
159
  it "should get bucket url" do
160
160
  expect(@bucket.bucket_url)
161
- .to eq('http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com')
161
+ .to eq('http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com/')
162
162
  end
163
163
 
164
164
  it "should get access key id" do
@@ -24,6 +24,55 @@ module Aliyun
24
24
  expect(config.sts_token).to eq('sts-token')
25
25
  end
26
26
 
27
+ it "should work with CNAME endpoint" do
28
+ endpoint = 'rockuw.com'
29
+ bucket = 'rubysdk-bucket'
30
+ object = 'rubysdk-object'
31
+ client = Client.new(
32
+ access_key_id: 'xxx',
33
+ access_key_secret: 'yyy',
34
+ endpoint: endpoint,
35
+ cname: true)
36
+
37
+ # TODO: ignore queries here
38
+ # bucket operations
39
+ stub_request(:get, endpoint)
40
+ .with(:query => {'encoding-type' => 'url'})
41
+ client.get_bucket(bucket).list_objects.take(1)
42
+ expect(WebMock)
43
+ .to have_requested(:get, endpoint)
44
+ .with(:query => {'encoding-type' => 'url'})
45
+
46
+ # object operations
47
+ stub_request(:get, "#{endpoint}/#{object}")
48
+ client.get_bucket(bucket).get_object(object) {}
49
+ expect(WebMock).to have_requested(:get, "#{endpoint}/#{object}")
50
+ end
51
+
52
+ it "should work with IP endpoint" do
53
+ endpoint = 'http://127.0.0.1:3000'
54
+ bucket = 'rubysdk-bucket'
55
+ object = 'rubysdk-object'
56
+ client = Client.new(
57
+ access_key_id: 'xxx',
58
+ access_key_secret: 'yyy',
59
+ endpoint: endpoint)
60
+
61
+ # TODO: ignore queries here
62
+ # bucket operations
63
+ stub_request(:get, "#{endpoint}/#{bucket}/")
64
+ .with(:query => {'encoding-type' => 'url'})
65
+ client.get_bucket(bucket).list_objects.take(1)
66
+ expect(WebMock)
67
+ .to have_requested(:get, "#{endpoint}/#{bucket}/")
68
+ .with(:query => {'encoding-type' => 'url'})
69
+
70
+ # object operations
71
+ stub_request(:get, "#{endpoint}/#{bucket}/#{object}")
72
+ client.get_bucket(bucket).get_object(object) {}
73
+ expect(WebMock).to have_requested(:get, "#{endpoint}/#{bucket}/#{object}")
74
+ end
75
+
27
76
  it "should not set Authorization with anonymous client" do
28
77
  endpoint = 'oss-cn-hangzhou.aliyuncs.com'
29
78
  bucket = 'rubysdk-bucket'
@@ -0,0 +1,15 @@
1
+ class TestConf
2
+ class << self
3
+ def creds
4
+ {
5
+ access_key_id: ENV['RUBY_SDK_OSS_ID'],
6
+ access_key_secret: ENV['RUBY_SDK_OSS_KEY'],
7
+ endpoint: ENV['RUBY_SDK_OSS_ENDPOINT']
8
+ }
9
+ end
10
+
11
+ def bucket
12
+ ENV['RUBY_SDK_OSS_BUCKET']
13
+ end
14
+ end
15
+ end
@@ -3,18 +3,13 @@ require 'yaml'
3
3
  $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
4
  require 'aliyun/oss'
5
5
  require 'zlib'
6
+ require_relative 'config'
6
7
 
7
8
  class TestContentEncoding < Minitest::Test
8
9
  def setup
9
10
  Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
10
- conf_file = '~/.oss.yml'
11
- conf = YAML.load(File.read(File.expand_path(conf_file)))
12
- client = Aliyun::OSS::Client.new(
13
- :endpoint => conf['endpoint'],
14
- :cname => conf['cname'],
15
- :access_key_id => conf['access_key_id'],
16
- :access_key_secret => conf['access_key_secret'])
17
- @bucket = client.get_bucket(conf['bucket'])
11
+ client = Aliyun::OSS::Client.new(TestConf.creds)
12
+ @bucket = client.get_bucket(TestConf.bucket)
18
13
 
19
14
  @prefix = "tests/content_encoding/"
20
15
  end
@@ -33,7 +28,7 @@ class TestContentEncoding < Minitest::Test
33
28
  key, file: '/tmp/x', content_type: 'text/plain')
34
29
 
35
30
  @bucket.get_object(
36
- key, file: '/tmp/y', headers: {'accept-encoding': 'gzip'})
31
+ key, file: '/tmp/y', headers: {'accept-encoding' => 'gzip'})
37
32
 
38
33
  assert File.exist?('/tmp/y')
39
34
  diff = `diff /tmp/x /tmp/y`
@@ -50,7 +45,7 @@ class TestContentEncoding < Minitest::Test
50
45
  key, file: '/tmp/x', content_type: 'text/plain')
51
46
 
52
47
  @bucket.get_object(
53
- key, file: '/tmp/y', headers: {'accept-encoding': 'deflate'})
48
+ key, file: '/tmp/y', headers: {'accept-encoding' => 'deflate'})
54
49
 
55
50
  assert File.exist?('/tmp/y')
56
51
  diff = `diff /tmp/x /tmp/y`
@@ -2,18 +2,13 @@ require 'minitest/autorun'
2
2
  require 'yaml'
3
3
  $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
4
  require 'aliyun/oss'
5
+ require_relative 'config'
5
6
 
6
7
  class TestContentType < Minitest::Test
7
8
  def setup
8
9
  Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
9
- conf_file = '~/.oss.yml'
10
- conf = YAML.load(File.read(File.expand_path(conf_file)))
11
- client = Aliyun::OSS::Client.new(
12
- :endpoint => conf['endpoint'],
13
- :cname => conf['cname'],
14
- :access_key_id => conf['access_key_id'],
15
- :access_key_secret => conf['access_key_secret'])
16
- @bucket = client.get_bucket(conf['bucket'])
10
+ client = Aliyun::OSS::Client.new(TestConf.creds)
11
+ @bucket = client.get_bucket(TestConf.bucket)
17
12
 
18
13
  @types = {
19
14
  "html" => "text/html",
@@ -3,18 +3,13 @@ require 'yaml'
3
3
  $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
4
  require 'aliyun/oss'
5
5
  require 'zlib'
6
+ require_relative 'config'
6
7
 
7
8
  class TestCustomHeaders < Minitest::Test
8
9
  def setup
9
10
  Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
10
- conf_file = '~/.oss.yml'
11
- conf = YAML.load(File.read(File.expand_path(conf_file)))
12
- client = Aliyun::OSS::Client.new(
13
- :endpoint => conf['endpoint'],
14
- :cname => conf['cname'],
15
- :access_key_id => conf['access_key_id'],
16
- :access_key_secret => conf['access_key_secret'])
17
- @bucket = client.get_bucket(conf['bucket'])
11
+ client = Aliyun::OSS::Client.new(TestConf.creds)
12
+ @bucket = client.get_bucket(TestConf.bucket)
18
13
 
19
14
  @prefix = "tests/custom_headers/"
20
15
  end
@@ -3,18 +3,14 @@ require 'minitest/autorun'
3
3
  require 'yaml'
4
4
  $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
5
5
  require 'aliyun/oss'
6
+ require_relative 'config'
6
7
 
7
8
  class TestEncoding < Minitest::Test
8
9
  def setup
9
10
  Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
10
- conf_file = '~/.oss.yml'
11
- conf = YAML.load(File.read(File.expand_path(conf_file)))
12
- client = Aliyun::OSS::Client.new(
13
- :endpoint => conf['endpoint'],
14
- :cname => conf['cname'],
15
- :access_key_id => conf['access_key_id'],
16
- :access_key_secret => conf['access_key_secret'])
17
- @bucket = client.get_bucket(conf['bucket'])
11
+ client = Aliyun::OSS::Client.new(TestConf.creds)
12
+ @bucket = client.get_bucket(TestConf.bucket)
13
+
18
14
  @prefix = 'tests/encoding/'
19
15
  end
20
16
 
@@ -4,17 +4,13 @@ require 'benchmark'
4
4
  require 'yaml'
5
5
  $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
6
6
  require 'aliyun/oss'
7
+ require_relative 'config'
7
8
 
8
9
  class TestLargeFile < Minitest::Test
9
10
  def setup
10
- conf_file = '~/.oss.yml'
11
- conf = YAML.load(File.read(File.expand_path(conf_file)))
12
- client = Aliyun::OSS::Client.new(
13
- :endpoint => conf['endpoint'],
14
- :cname => conf['cname'],
15
- :access_key_id => conf['access_key_id'],
16
- :access_key_secret => conf['access_key_secret'])
17
- @bucket = client.get_bucket(conf['bucket'])
11
+ client = Aliyun::OSS::Client.new(TestConf.creds)
12
+ @bucket = client.get_bucket(TestConf.bucket)
13
+
18
14
  @prefix = 'tests/large_file/'
19
15
  end
20
16
 
@@ -3,21 +3,16 @@ require 'minitest/autorun'
3
3
  require 'yaml'
4
4
  $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
5
5
  require 'aliyun/oss'
6
+ require_relative 'config'
6
7
 
7
8
  class TestMultipart < Minitest::Test
8
9
  def setup
9
- conf_file = '~/.oss.yml'
10
- conf = YAML.load(File.read(File.expand_path(conf_file)))
11
- opts = {
12
- endpoint: conf['endpoint'],
13
- cname: conf['cname'],
14
- access_key_id: conf['access_key_id'],
15
- access_key_secret: conf['access_key_secret'],
16
- }
17
- client = Aliyun::OSS::Client.new(opts)
18
- @bucket_name = conf['bucket']
19
- @bucket = client.get_bucket(@bucket_name)
20
- @protocol = Aliyun::OSS::Protocol.new(Aliyun::OSS::Config.new(opts))
10
+ Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
11
+ client = Aliyun::OSS::Client.new(TestConf.creds)
12
+ @bucket_name = TestConf.bucket
13
+ @bucket = client.get_bucket(TestConf.bucket)
14
+
15
+ @protocol = Aliyun::OSS::Protocol.new(Aliyun::OSS::Config.new(TestConf.creds))
21
16
  @prefix = 'tests/multipart/'
22
17
  end
23
18
 
@@ -99,7 +94,4 @@ class TestMultipart < Minitest::Test
99
94
  id_marker: bar_ids[4], key_marker: get_key("bar")).to_a
100
95
  assert_equal foo_ids, after_5.map(&:id)
101
96
  end
102
-
103
- def test_prefix
104
- end
105
97
  end
@@ -2,18 +2,13 @@ require 'minitest/autorun'
2
2
  require 'yaml'
3
3
  $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
4
  require 'aliyun/oss'
5
+ require_relative 'config'
5
6
 
6
7
  class TestObjectACL < Minitest::Test
7
8
  def setup
8
9
  Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
9
- conf_file = '~/.oss.yml'
10
- conf = YAML.load(File.read(File.expand_path(conf_file)))
11
- client = Aliyun::OSS::Client.new(
12
- :endpoint => conf['endpoint'],
13
- :cname => conf['cname'],
14
- :access_key_id => conf['access_key_id'],
15
- :access_key_secret => conf['access_key_secret'])
16
- @bucket = client.get_bucket(conf['bucket'])
10
+ client = Aliyun::OSS::Client.new(TestConf.creds)
11
+ @bucket = client.get_bucket(TestConf.bucket)
17
12
 
18
13
  @prefix = "tests/object_acl/"
19
14
  end
@@ -3,18 +3,14 @@ require 'minitest/autorun'
3
3
  require 'yaml'
4
4
  $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
5
5
  require 'aliyun/oss'
6
+ require_relative 'config'
6
7
 
7
8
  class TestObjectKey < Minitest::Test
8
9
  def setup
9
10
  Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
10
- conf_file = '~/.oss.yml'
11
- conf = YAML.load(File.read(File.expand_path(conf_file)))
12
- client = Aliyun::OSS::Client.new(
13
- :endpoint => conf['endpoint'],
14
- :cname => conf['cname'],
15
- :access_key_id => conf['access_key_id'],
16
- :access_key_secret => conf['access_key_secret'])
17
- @bucket = client.get_bucket(conf['bucket'])
11
+ client = Aliyun::OSS::Client.new(TestConf.creds)
12
+ @bucket = client.get_bucket(TestConf.bucket)
13
+
18
14
  @prefix = 'tests/object_key/'
19
15
  @keys = {
20
16
  simple: 'simple_key',
@@ -2,18 +2,14 @@ require 'minitest/autorun'
2
2
  require 'yaml'
3
3
  $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
4
  require 'aliyun/oss'
5
+ require_relative 'config'
5
6
 
6
7
  class TestResumable < Minitest::Test
7
8
  def setup
8
9
  Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
9
- conf_file = '~/.oss.yml'
10
- conf = YAML.load(File.read(File.expand_path(conf_file)))
11
- client = Aliyun::OSS::Client.new(
12
- :endpoint => conf['endpoint'],
13
- :cname => conf['cname'],
14
- :access_key_id => conf['access_key_id'],
15
- :access_key_secret => conf['access_key_secret'])
16
- @bucket = client.get_bucket(conf['bucket'])
10
+ client = Aliyun::OSS::Client.new(TestConf.creds)
11
+ @bucket = client.get_bucket(TestConf.bucket)
12
+
17
13
  @prefix = 'tests/resumable/'
18
14
  end
19
15
 
@@ -32,6 +28,9 @@ class TestResumable < Minitest::Test
32
28
  (10 * 1024).times { f.write(random_string(1024)) }
33
29
  end
34
30
 
31
+ # clear checkpoints
32
+ `rm -rf /tmp/x.cpt && rm -rf /tmp/y.cpt`
33
+
35
34
  @bucket.resumable_upload(key, '/tmp/x', :part_size => 100 * 1024)
36
35
  @bucket.resumable_download(key, '/tmp/y', :part_size => 100 * 1024)
37
36
 
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.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tianlong Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-25 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -179,6 +179,7 @@ files:
179
179
  - spec/aliyun/oss/util_spec.rb
180
180
  - spec/aliyun/sts/client_spec.rb
181
181
  - spec/aliyun/sts/util_spec.rb
182
+ - tests/config.rb
182
183
  - tests/test_content_encoding.rb
183
184
  - tests/test_content_type.rb
184
185
  - tests/test_custom_headers.rb
@@ -225,6 +226,7 @@ test_files:
225
226
  - spec/aliyun/oss/util_spec.rb
226
227
  - spec/aliyun/sts/client_spec.rb
227
228
  - spec/aliyun/sts/util_spec.rb
229
+ - tests/config.rb
228
230
  - tests/test_content_encoding.rb
229
231
  - tests/test_content_type.rb
230
232
  - tests/test_custom_headers.rb