lib/fog/aliyun/storage.rb in fog-aliyun-0.3.10 vs lib/fog/aliyun/storage.rb in fog-aliyun-0.3.11
- old
+ new
@@ -1,15 +1,19 @@
# frozen_string_literal: true
require 'xmlsimple'
+require 'aliyun/oss'
+# Using Aliyun OSS Ruby SDK
+AliyunOssSdk= Aliyun::OSS
+
module Fog
- module Storage
- class Aliyun < Fog::Service
+ module Aliyun
+ class Storage < Fog::Service
DEFAULT_REGION = 'cn-hangzhou'
- DEFAULT_SCHEME = 'http'
+ DEFAULT_SCHEME = 'https'
DEFAULT_SCHEME_PORT = {
'http' => 80,
'https' => 443
}.freeze
@@ -95,10 +99,15 @@
@path = uri.path
@scheme = uri.scheme || DEFAULT_SCHEME
@port = uri.port || DEFAULT_SCHEME_PORT[@scheme]
@persistent = options[:persistent] || false
+ @oss_client = AliyunOssSdk::Client.new(
+ :endpoint => @aliyun_oss_endpoint,
+ :access_key_id => @aliyun_accesskey_id,
+ :access_key_secret => @aliyun_accesskey_secret
+ )
end
def reload
@connection.reset
end
@@ -116,23 +125,26 @@
method = params[:method]
time = Time.new.utc
date = time.strftime('%a, %d %b %Y %H:%M:%S GMT')
endpoint = params[:endpoint]
+ location = params[:location]
if endpoint
uri = URI.parse(endpoint)
host = uri.host
path = uri.path
port = uri.port
scheme = uri.scheme
- else
- host = @host
- path = @path
- port = @port
- scheme = @scheme
+ elsif location
+ host = location + '.aliyuncs.com'
end
+ host ||= @host
+ path ||= @path
+ port ||= @port
+ scheme ||= @scheme
+
bucket = params[:bucket]
tmpHost = if bucket
bucket + '.' + host
else
host
@@ -141,12 +153,14 @@
@connection = Fog::Core::Connection.new("#{scheme}://#{tmpHost}", @persistent, @connection_options)
contentType = params[:contentType]
begin
headers = ''
- params[:headers]&.each do |k, v|
+ if params[:headers]
+ params[:headers].each do |k, v|
headers += "#{k}:#{v}\n" if k != 'Range'
+ end
end
signature = sign(method, date, contentType, params[:resource], headers)
response = @connection.request(params.merge(headers: {
'Content-Type' => contentType,
'Authorization' => 'OSS ' + @aliyun_accesskey_id + ':' + signature,
@@ -155,10 +169,10 @@
path: "#{path}/#{params[:path]}",
query: params[:query]))
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
- Fog::Storage::Aliyun::NotFound.slurp(error)
+ Fog::Aliyun::Storage::NotFound.slurp(error)
else
error
end
end