Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
language: ruby
rvm:
- 1.9.3
- 2.0
- 2.1
- 2.2
script:
bundle exec rake spec
- 1.9.3
- 2.0
- 2.1
- 2.2
env:
global:
- secure: cC3aeKKrNLGuK60zEPKNPmRlE3m/VlzQLAXjD8nYjhbPVL+zjaylY87vq657gSFmDDGY3ISF0aR3rjFpSHeoVr6CiVZDnQIgoaC2FD1oDxkzy6/8tEQBJ0YORLzfCO63NJTKltVMvSsPWck4xE+qIsQLIpDjia9fHc2InLtkn9pTnuhMpHxjBIat6TgFPSiIC9YXXjCveudTy2o+9Is2nCmkdsr7lqEkifLIyXmGzyUp99hmQy0OZ2lF06OMH/RwWSDRBZryqMT+ju1qsv+/LkDRFwaqKfxqDdewhxj6eZdA7Q1YyB7ChT+uFRNaHkrWwPCC+JcZnHq8kt8qykUfN+Saq/txZ65qpQFp0rDUG929iaUUnfreearniqe9+u+7LnrFeseVLa6dJD+fcsTcCQRgfUvuaMARLq3EwqUCvAXPWHFTnY6ynqerTEwlJbxpCXtYktXaO0KugOI+iF4APs/r2iroAM/zkf3AjH78UcSAIBn1AzxQy7+Ah6G+nS69/nvbtPGiiSAmJYgKfBcD1ctDTJXzen78MGz7ImTC64k+2J4kuu8CSi/j8wbdIRHrIIszBUEPKQrGp9RDx08MRffinhnInq1uGEBFvip2Q1qk3tuGXJT+2m/OgbK7KlVmlzRz9M+NGav6ixQpW4qPvu2mf2bdmMeAd/0sg4IIIRc=
- secure: iMjPztZoWaRxrgI/buZZj8SliuOYGEcOyO++xskr0O6x8+3qkT7JRqozwu/PK3Au77Py9+LTpZqNrjy3ZZx/KBzYUX4+g+k5YcjiUAnlX3/CEdj5Apti6Qb0CwtOgHY7V+y205vZeh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Gaf5P0VxUSc7I/bIR6IlXlSu0SpA2KqQvpc4QMNhzaHbhoquNJ9SK4FwCjhdFhGrfRNsePH6tpK9Po2PQoFBqT1WEFZogA5QcdC/3axlfpsXPL8RRHw+YqgplVpR43N2f0ug6rTq2hL8/YM6Dn7Y=
- secure: Bh0qS85guNrnHwGTAqD0TY0xWJ5VSMO9Qh7//oBxT+eqWNmp7jmH7etDGQ6EzlnbXE7MUOBLarlnzH8uONhpz7RsU2R+OaQ4Z1i0npAS7t9sivEK8mHlUpX5iMhbnPvi70LQf8Xh/JEtOis/aYS/J86DM6S4tkFaSgbKAFFpyaxCHconHCLcRTXLRl8PgK+k8VAhlUBIbI2u7v1uYhjefy3eHf/I0ZnUBvM5VOtjflddOH607fbo65SzaQiUrxg7Ed2oy/Vdhgksq4HPSLjS5afsF7EifW2eVq/EjdXeyF8K3XTdMiV9oYj7KkLXVL21jA5LWCiM5rvkG+Zz/ATHZodOgBw/Wdim/Tbni+E3cLkhN3LEVUqx/W4/PKK3bWiIuaf37T7UuZC2+tEpRt1UHCc83w9uX+4XPUjGkH3N5rXrTAhz82z455nSl6lVi8zvIkXECP05/HJFU83ottc7GyWX2a7rpuLVe3iq8D6BCGRpjI3nKsfnCAjbs5UR/ED8/xie1/RylqpBbgQc3yLB/3m9LVV5mZxBYLQGKS4yfYpwJN7sqFZn9dFGqhLTGFfOVyPPmSnjjL7x1R5WgfNHEtwfGFXZN97kt4xd8TkR0UwW4opqePsqX1+JQQODJixxm3CfZVE4P8mQaZWHz7OMGTpnrTSZPqLZPnwte/6pAUk=
script: bundle exec rake smart_test
before_install: gem install bundler
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Aliyun OSS SDK for Ruby

[![Gem Version](https://badge.fury.io/rb/aliyun-sdk.svg)](https://badge.fury.io/rb/aliyun-sdk)
[![Build Status](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk.svg)](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk)
[![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)

Expand Down Expand Up @@ -325,6 +326,7 @@ Multipart的功能,可以在上传/下载时将大文件进行分片传输。A
puts obj.metas

关于meta信息有以下几点需要注意:

1. meta信息的key和value都只能是简单的ASCII非换行字符,并且总的大小不能超过8KB。
2. Copy object时默认将拷贝源object的meta信息,如果用户不希望这么做,需要
显式地将`:meta_directive`设置成{Aliyun::OSS::MetaDirective::REPLACE}
Expand Down Expand Up @@ -395,14 +397,16 @@ SDK的examples/目录下有一些展示SDK功能的示例程序,用户稍加

## 运行测试

SDK采用rspec进行测试,如果要对SDK进行修改,请确保没有break现有测试。测
试运行的方法是,在ruby-sdk/目录下运行:

rspec
```bash
bundle exec rake spec

或者用bundle和rake:
export RUBY_SDK_OSS_ENDPOINT=endpoint
export RUBY_SDK_OSS_ID=AccessKeyId
export RUBY_SDK_OSS_KEY=AccessKeySecret
export RUBY_SDK_OSS_BUCKET=bucket-name

bundle exec rake spec
bundle exec rake test
```

## 更多

Expand Down
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ Rake::TestTask.new do |t|
end

task :default => :spec

task :smart_test do
Rake::Task[:spec].invoke
Rake::Task[:test].invoke if ENV.keys.include?('RUBY_SDK_OSS_KEY')
end
26 changes: 14 additions & 12 deletions lib/aliyun/oss/http.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-

require 'rest-client'
require 'resolv'
require 'fiber'

module Aliyun
Expand Down Expand Up @@ -138,21 +139,22 @@ def initialize(config)
end

def get_request_url(bucket, object)
url = ""
url += "#{@config.endpoint.scheme}://"
url += "#{bucket}." if bucket and not @config.cname
url += @config.endpoint.host
url += "/#{CGI.escape(object)}" if object

url
url = @config.endpoint.dup
isIP = !!(url.host =~ Resolv::IPv4::Regex)
url.host = "#{bucket}." + url.host if bucket && !@config.cname && !isIP
url.path = '/'
url.path << "#{bucket}/" if bucket && isIP
url.path << "#{CGI.escape(object)}" if object

url.to_s
end

def get_resource_path(bucket, object)
if bucket
res = "/#{bucket}/"
res += "#{object}" if object
res
end
res = '/'
res << "#{bucket}/" if bucket
res << "#{object}" if object

res
end

# Handle Net::HTTPRespoonse
Expand Down
2 changes: 1 addition & 1 deletion spec/aliyun/oss/client/bucket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def err(msg, reqid = '0000')

it "should get bucket url" do
expect(@bucket.bucket_url)
.to eq('http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com')
.to eq('http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com/')
end

it "should get access key id" do
Expand Down
49 changes: 49 additions & 0 deletions spec/aliyun/oss/client/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,55 @@ module OSS
expect(config.sts_token).to eq('sts-token')
end

it "should work with CNAME endpoint" do
endpoint = 'rockuw.com'
bucket = 'rubysdk-bucket'
object = 'rubysdk-object'
client = Client.new(
access_key_id: 'xxx',
access_key_secret: 'yyy',
endpoint: endpoint,
cname: true)

# TODO: ignore queries here
# bucket operations
stub_request(:get, endpoint)
.with(:query => {'encoding-type' => 'url'})
client.get_bucket(bucket).list_objects.take(1)
expect(WebMock)
.to have_requested(:get, endpoint)
.with(:query => {'encoding-type' => 'url'})

# object operations
stub_request(:get, "#{endpoint}/#{object}")
client.get_bucket(bucket).get_object(object) {}
expect(WebMock).to have_requested(:get, "#{endpoint}/#{object}")
end

it "should work with IP endpoint" do
endpoint = 'http://127.0.0.1:3000'
bucket = 'rubysdk-bucket'
object = 'rubysdk-object'
client = Client.new(
access_key_id: 'xxx',
access_key_secret: 'yyy',
endpoint: endpoint)

# TODO: ignore queries here
# bucket operations
stub_request(:get, "#{endpoint}/#{bucket}/")
.with(:query => {'encoding-type' => 'url'})
client.get_bucket(bucket).list_objects.take(1)
expect(WebMock)
.to have_requested(:get, "#{endpoint}/#{bucket}/")
.with(:query => {'encoding-type' => 'url'})

# object operations
stub_request(:get, "#{endpoint}/#{bucket}/#{object}")
client.get_bucket(bucket).get_object(object) {}
expect(WebMock).to have_requested(:get, "#{endpoint}/#{bucket}/#{object}")
end

it "should not set Authorization with anonymous client" do
endpoint = 'oss-cn-hangzhou.aliyuncs.com'
bucket = 'rubysdk-bucket'
Expand Down
11 changes: 3 additions & 8 deletions tests/test_content_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require 'zlib'
require_relative 'config'

class TestContentEncoding < Minitest::Test
def setup
Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
conf_file = '~/.oss.yml'
conf = YAML.load(File.read(File.expand_path(conf_file)))
client = Aliyun::OSS::Client.new(
:endpoint => conf['endpoint'],
:cname => conf['cname'],
:access_key_id => conf['access_key_id'],
:access_key_secret => conf['access_key_secret'])
@bucket = client.get_bucket(conf['bucket'])
client = Aliyun::OSS::Client.new(Config.creds)
@bucket = client.get_bucket(Config.bucket)

@prefix = "tests/content_encoding/"
end
Expand Down
11 changes: 3 additions & 8 deletions tests/test_content_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
require 'yaml'
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require_relative 'config'

class TestContentType < Minitest::Test
def setup
Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
conf_file = '~/.oss.yml'
conf = YAML.load(File.read(File.expand_path(conf_file)))
client = Aliyun::OSS::Client.new(
:endpoint => conf['endpoint'],
:cname => conf['cname'],
:access_key_id => conf['access_key_id'],
:access_key_secret => conf['access_key_secret'])
@bucket = client.get_bucket(conf['bucket'])
client = Aliyun::OSS::Client.new(Config.creds)
@bucket = client.get_bucket(Config.bucket)

@types = {
"html" => "text/html",
Expand Down
11 changes: 3 additions & 8 deletions tests/test_custom_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require 'zlib'
require_relative 'config'

class TestCustomHeaders < Minitest::Test
def setup
Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
conf_file = '~/.oss.yml'
conf = YAML.load(File.read(File.expand_path(conf_file)))
client = Aliyun::OSS::Client.new(
:endpoint => conf['endpoint'],
:cname => conf['cname'],
:access_key_id => conf['access_key_id'],
:access_key_secret => conf['access_key_secret'])
@bucket = client.get_bucket(conf['bucket'])
client = Aliyun::OSS::Client.new(Config.creds)
@bucket = client.get_bucket(Config.bucket)

@prefix = "tests/custom_headers/"
end
Expand Down
12 changes: 4 additions & 8 deletions tests/test_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
require 'yaml'
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require_relative 'config'

class TestEncoding < Minitest::Test
def setup
Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
conf_file = '~/.oss.yml'
conf = YAML.load(File.read(File.expand_path(conf_file)))
client = Aliyun::OSS::Client.new(
:endpoint => conf['endpoint'],
:cname => conf['cname'],
:access_key_id => conf['access_key_id'],
:access_key_secret => conf['access_key_secret'])
@bucket = client.get_bucket(conf['bucket'])
client = Aliyun::OSS::Client.new(Config.creds)
@bucket = client.get_bucket(Config.bucket)

@prefix = 'tests/encoding/'
end

Expand Down
12 changes: 4 additions & 8 deletions tests/test_large_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
require 'yaml'
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require_relative 'config'

class TestLargeFile < Minitest::Test
def setup
conf_file = '~/.oss.yml'
conf = YAML.load(File.read(File.expand_path(conf_file)))
client = Aliyun::OSS::Client.new(
:endpoint => conf['endpoint'],
:cname => conf['cname'],
:access_key_id => conf['access_key_id'],
:access_key_secret => conf['access_key_secret'])
@bucket = client.get_bucket(conf['bucket'])
client = Aliyun::OSS::Client.new(Config.creds)
@bucket = client.get_bucket(Config.bucket)

@prefix = 'tests/large_file/'
end

Expand Down
22 changes: 7 additions & 15 deletions tests/test_multipart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
require 'yaml'
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require_relative 'config'

class TestMultipart < Minitest::Test
def setup
conf_file = '~/.oss.yml'
conf = YAML.load(File.read(File.expand_path(conf_file)))
opts = {
endpoint: conf['endpoint'],
cname: conf['cname'],
access_key_id: conf['access_key_id'],
access_key_secret: conf['access_key_secret'],
}
client = Aliyun::OSS::Client.new(opts)
@bucket_name = conf['bucket']
@bucket = client.get_bucket(@bucket_name)
@protocol = Aliyun::OSS::Protocol.new(Aliyun::OSS::Config.new(opts))
Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
client = Aliyun::OSS::Client.new(Config.creds)
@bucket_name = Config.bucket
@bucket = client.get_bucket(Config.bucket)

@protocol = Aliyun::OSS::Protocol.new(Aliyun::OSS::Config.new(Config.creds))
@prefix = 'tests/multipart/'
end

Expand Down Expand Up @@ -99,7 +94,4 @@ def test_id_key_marker
id_marker: bar_ids[4], key_marker: get_key("bar")).to_a
assert_equal foo_ids, after_5.map(&:id)
end

def test_prefix
end
end
11 changes: 3 additions & 8 deletions tests/test_object_acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
require 'yaml'
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require_relative 'config'

class TestObjectACL < Minitest::Test
def setup
Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
conf_file = '~/.oss.yml'
conf = YAML.load(File.read(File.expand_path(conf_file)))
client = Aliyun::OSS::Client.new(
:endpoint => conf['endpoint'],
:cname => conf['cname'],
:access_key_id => conf['access_key_id'],
:access_key_secret => conf['access_key_secret'])
@bucket = client.get_bucket(conf['bucket'])
client = Aliyun::OSS::Client.new(Config.creds)
@bucket = client.get_bucket(Config.bucket)

@prefix = "tests/object_acl/"
end
Expand Down
12 changes: 4 additions & 8 deletions tests/test_object_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
require 'yaml'
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require_relative 'config'

class TestObjectKey < Minitest::Test
def setup
Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
conf_file = '~/.oss.yml'
conf = YAML.load(File.read(File.expand_path(conf_file)))
client = Aliyun::OSS::Client.new(
:endpoint => conf['endpoint'],
:cname => conf['cname'],
:access_key_id => conf['access_key_id'],
:access_key_secret => conf['access_key_secret'])
@bucket = client.get_bucket(conf['bucket'])
client = Aliyun::OSS::Client.new(Config.creds)
@bucket = client.get_bucket(Config.bucket)

@prefix = 'tests/object_key/'
@keys = {
simple: 'simple_key',
Expand Down
12 changes: 4 additions & 8 deletions tests/test_resumable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
require 'yaml'
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'aliyun/oss'
require_relative 'config'

class TestResumable < Minitest::Test
def setup
Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
conf_file = '~/.oss.yml'
conf = YAML.load(File.read(File.expand_path(conf_file)))
client = Aliyun::OSS::Client.new(
:endpoint => conf['endpoint'],
:cname => conf['cname'],
:access_key_id => conf['access_key_id'],
:access_key_secret => conf['access_key_secret'])
@bucket = client.get_bucket(conf['bucket'])
client = Aliyun::OSS::Client.new(Config.creds)
@bucket = client.get_bucket(Config.bucket)

@prefix = 'tests/resumable/'
end

Expand Down