lib/fog/aliyun/storage.rb in fog-aliyun-0.3.16 vs lib/fog/aliyun/storage.rb in fog-aliyun-0.3.17

- old
+ new

@@ -17,11 +17,13 @@ 'https' => 443 }.freeze recognizes :aliyun_oss_endpoint, :aliyun_oss_location, - :aliyun_region_id + :aliyun_region_id, + :aliyun_oss_sdk_log_path + requires :aliyun_accesskey_id, :aliyun_accesskey_secret, :aliyun_oss_bucket model_path 'fog/aliyun/models/storage' @@ -70,19 +72,24 @@ attr_reader :aliyun_accesskey_id attr_reader :aliyun_accesskey_secret attr_reader :aliyun_oss_endpoint attr_reader :aliyun_region_id attr_reader :aliyun_oss_bucket + attr_reader :aliyun_oss_sdk_log_path def initialize(options = {}) # initialize the parameters @aliyun_region_id = options[:aliyun_region_id] || options[:aliyun_oss_location] || DEFAULT_REGION @aliyun_oss_endpoint = options[:aliyun_oss_endpoint] || region_to_endpoint(@aliyun_region_id) @aliyun_accesskey_id = options[:aliyun_accesskey_id] @aliyun_accesskey_secret = options[:aliyun_accesskey_secret] @aliyun_oss_bucket = options[:aliyun_oss_bucket] - + @aliyun_oss_sdk_log_path=options[:aliyun_oss_sdk_log_path] + if @aliyun_oss_sdk_log_path && !::File.exist?(@aliyun_oss_sdk_log_path) + `touch #{@aliyun_oss_sdk_log_path}` + end + ENV["ALIYUN_OSS_SDK_LOG_PATH"] = @aliyun_oss_sdk_log_path # check for the parameters missing_credentials = [] missing_credentials << :aliyun_oss_bucket unless @aliyun_oss_bucket missing_credentials << :aliyun_accesskey_id unless @aliyun_accesskey_id missing_credentials << :aliyun_accesskey_secret unless @aliyun_accesskey_secret @@ -104,9 +111,17 @@ @oss_client = AliyunOssSdk::Client.new( :endpoint => @aliyun_oss_endpoint, :access_key_id => @aliyun_accesskey_id, :access_key_secret => @aliyun_accesskey_secret ) + + # initiate a aliyun oss ruby sdk config and using sdk http to invoke the OSS openapi + @oss_config = AliyunOssSdk::Config.new( + :endpoint => @aliyun_oss_endpoint, + :access_key_id => @aliyun_accesskey_id, + :access_key_secret => @aliyun_accesskey_secret + ) + @oss_http = AliyunOssSdk::HTTP.new(@oss_config) end def reload @connection.reset end