Class: Fog::Aliyun::Storage::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aliyun/storage.rb,
lib/fog/aliyun/requests/storage/get_bucket.rb,
lib/fog/aliyun/requests/storage/get_object.rb,
lib/fog/aliyun/requests/storage/put_bucket.rb,
lib/fog/aliyun/requests/storage/put_object.rb,
lib/fog/aliyun/requests/storage/copy_object.rb,
lib/fog/aliyun/requests/storage/get_service.rb,
lib/fog/aliyun/requests/storage/head_object.rb,
lib/fog/aliyun/requests/storage/upload_part.rb,
lib/fog/aliyun/requests/storage/list_buckets.rb,
lib/fog/aliyun/requests/storage/list_objects.rb,
lib/fog/aliyun/requests/storage/delete_bucket.rb,
lib/fog/aliyun/requests/storage/delete_object.rb,
lib/fog/aliyun/requests/storage/get_object_acl.rb,
lib/fog/aliyun/requests/storage/get_bucket_location.rb,
lib/fog/aliyun/requests/storage/get_object_http_url.rb,
lib/fog/aliyun/requests/storage/get_object_https_url.rb,
lib/fog/aliyun/requests/storage/abort_multipart_upload.rb,
lib/fog/aliyun/requests/storage/delete_multiple_objects.rb,
lib/fog/aliyun/requests/storage/complete_multipart_upload.rb,
lib/fog/aliyun/requests/storage/initiate_multipart_upload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.

Raises:

  • (ArgumentError)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/fog/aliyun/storage.rb', line 84

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
  raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?

  @connection_options = options[:connection_options] || {}

  endpoint = @aliyun_oss_endpoint

  @aliyun_oss_endpoint = "#{DEFAULT_SCHEME}://#{endpoint}" unless endpoint.start_with?(DEFAULT_SCHEME)

  uri = URI.parse(@aliyun_oss_endpoint)
  @host = uri.host
  @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
  )

  # 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)
  @oss_protocol = AliyunOssSdk::Protocol.new(@oss_config)
end

Instance Attribute Details

#aliyun_accesskey_idObject (readonly)

Initialize connection to OSS

Notes

options parameter must include values for :aliyun_accesskey_id, :aliyun_secret_access_key and :aliyun_oss_bucket in order to create a connection. :aliyun_oss_location will be replaced by :aliyun_region_id, and it has a default value cn-hangzhou if :aliyun_oss_endpoint is not specified, it will be generated by method region_to_endpoint

Examples

sdb = Fog::Storage.new(:provider=>'aliyun',
 :aliyun_accesskey_id => your_:aliyun_accesskey_id,
 :aliyun_secret_access_key => your_aliyun_secret_access_key
)

Parameters

  • options<~Hash> - config arguments for connection. Defaults to {}.

Returns

  • OSS object with connection to aliyun.



77
78
79
# File 'lib/fog/aliyun/storage.rb', line 77

def aliyun_accesskey_id
  @aliyun_accesskey_id
end

#aliyun_accesskey_secretObject (readonly)

Returns the value of attribute aliyun_accesskey_secret.



78
79
80
# File 'lib/fog/aliyun/storage.rb', line 78

def aliyun_accesskey_secret
  @aliyun_accesskey_secret
end

#aliyun_oss_bucketObject (readonly)

Returns the value of attribute aliyun_oss_bucket.



81
82
83
# File 'lib/fog/aliyun/storage.rb', line 81

def aliyun_oss_bucket
  @aliyun_oss_bucket
end

#aliyun_oss_endpointObject (readonly)

Returns the value of attribute aliyun_oss_endpoint.



79
80
81
# File 'lib/fog/aliyun/storage.rb', line 79

def aliyun_oss_endpoint
  @aliyun_oss_endpoint
end

#aliyun_oss_sdk_log_pathObject (readonly)

Returns the value of attribute aliyun_oss_sdk_log_path.



82
83
84
# File 'lib/fog/aliyun/storage.rb', line 82

def aliyun_oss_sdk_log_path
  @aliyun_oss_sdk_log_path
end

#aliyun_region_idObject (readonly)

Returns the value of attribute aliyun_region_id.



80
81
82
# File 'lib/fog/aliyun/storage.rb', line 80

def aliyun_region_id
  @aliyun_region_id
end

Instance Method Details

#abort_multipart_upload(bucket_name, object_name, upload_id) ⇒ Object

Abort a multipart upload

Parameters:

  • bucket_name (String)

    Name of bucket to abort multipart upload on

  • object_name (String)

    Name of object to abort multipart upload on

  • upload_id (String)

    Id of upload to add part to

See Also:



15
16
17
# File 'lib/fog/aliyun/requests/storage/abort_multipart_upload.rb', line 15

def abort_multipart_upload(bucket_name, object_name, upload_id)
  @oss_protocol.abort_multipart_upload(bucket_name, object_name, upload_id)
end

#bucket_exists?(bucket_name) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/fog/aliyun/requests/storage/get_bucket.rb', line 7

def bucket_exists?(bucket_name)
  @oss_client.bucket_exists?(bucket_name)
end

#complete_multipart_upload(bucket_name, object_name, upload_id, parts) ⇒ Object

Complete a multipart upload

Parameters:

  • bucket_name (String)

    Name of bucket to complete multipart upload for

  • object_name (String)

    Name of object to complete multipart upload for

  • upload_id (String)

    Id of upload to add part to

  • parts (Array)

    Array of etag and number as Strings for parts

See Also:



15
16
17
# File 'lib/fog/aliyun/requests/storage/complete_multipart_upload.rb', line 15

def complete_multipart_upload(bucket_name, object_name, upload_id, parts)
  @oss_protocol.complete_multipart_upload(bucket_name, object_name, upload_id, parts)
end

#copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {}) ⇒ Object

Copy object

Parameters

  • source_bucket_name<~String> - Name of source bucket

  • source_object_name<~String> - Name of source object

  • target_bucket_name<~String> - Name of bucket to create copy in

  • target_object_name<~String> - Name for new copy of object

  • options<~Hash> - Additional headers options={}



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/aliyun/requests/storage/copy_object.rb', line 15

def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
  headers = { 'x-oss-copy-source' => "/#{source_bucket_name}#{object_to_path(source_object_name)}" }.merge!(options)
  resources = {
      :bucket => target_bucket_name,
      :object => target_object_name
  }
  http_options = {
      :headers => headers
  }
  @oss_http.put(resources, http_options)
end

#delete_bucket(bucket_name) ⇒ Object

Delete an existing bucket

Parameters

  • bucket_name<~String> - Name of bucket to delete



12
13
14
# File 'lib/fog/aliyun/requests/storage/delete_bucket.rb', line 12

def delete_bucket(bucket_name)
  @oss_protocol.delete_bucket(bucket_name)
end

#delete_multiple_objects(bucket_name, object_names, options = {}) ⇒ Object

Delete multiple objects from OSS

Parameters:

  • bucket_name (String)

    Name of bucket containing object to delete

  • object_names (Array)

    Array of object names to delete

See Also:



13
14
15
16
# File 'lib/fog/aliyun/requests/storage/delete_multiple_objects.rb', line 13

def delete_multiple_objects(bucket_name, object_names, options = {})
  bucket = @oss_client.get_bucket(bucket_name)
  bucket.batch_delete_objects(object_names, options)
end

#delete_object(bucket_name, object_name, options = {}) ⇒ Object

Delete an existing object

Parameters

  • bucket_name<~String> - Name of bucket to delete

  • object_name<~String> - Name of object to delete



13
14
15
16
17
18
19
20
21
# File 'lib/fog/aliyun/requests/storage/delete_object.rb', line 13

def delete_object(bucket_name, object_name, options = {})
  # TODO Support versionId
  # if version_id = options.delete('versionId')
  #   query = {'versionId' => version_id}
  # else
  #   query = {}
  # end
  @oss_http.delete({:bucket => bucket_name, :object => object_name}, {:headers => options})
end

#escape(string) ⇒ Object



149
150
151
152
153
# File 'lib/fog/aliyun/storage.rb', line 149

def escape(string)
  string.gsub(/([^a-zA-Z0-9_.\-~\/]+)/) {
    "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
  }
end

#get_bucket(bucket_name, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/aliyun/requests/storage/get_bucket.rb', line 11

def get_bucket(bucket_name, options = {})
  unless bucket_name
    raise ArgumentError.new('bucket_name is required')
  end

  # Set the GetBucket max limitation to 1000
  maxKeys = options[:max_keys] || 1000
  maxKeys = maxKeys.to_i
  maxKeys = [maxKeys, 1000].min

  options[:limit] = maxKeys
  options.delete(:max_keys)

  @oss_protocol.list_objects(bucket_name, options)
end

#get_bucket_acl(bucket_name) ⇒ Object



27
28
29
# File 'lib/fog/aliyun/requests/storage/get_bucket.rb', line 27

def get_bucket_acl(bucket_name)
  @oss_protocol.get_bucket_acl(bucket_name)
end

#get_bucket_CORSRules(bucket_name) ⇒ Object



31
32
33
# File 'lib/fog/aliyun/requests/storage/get_bucket.rb', line 31

def get_bucket_CORSRules(bucket_name)
  @oss_protocol.get_bucket_cors(bucket_name)
end

#get_bucket_lifecycle(bucket_name) ⇒ Object



35
36
37
# File 'lib/fog/aliyun/requests/storage/get_bucket.rb', line 35

def get_bucket_lifecycle(bucket_name)
  @oss_protocol.get_bucket_lifecycle(bucket_name)
end

#get_bucket_location(bucket_name) ⇒ Object

Get location constraint for an OSS bucket

note: The OSS Ruby sdk does not support get_bucket_location and there needs to parse response

Parameters:

  • bucket_name (String)

    name of bucket to get location constraint for

See Also:



15
16
17
18
19
# File 'lib/fog/aliyun/requests/storage/get_bucket_location.rb', line 15

def get_bucket_location(bucket_name)
  data = @oss_http.get({:bucket => bucket_name, :sub_res => { 'location' => nil} }, {})
  doc = parse_xml(data.body)
  doc.at_css("LocationConstraint").text
end

#get_bucket_logging(bucket_name) ⇒ Object



39
40
41
# File 'lib/fog/aliyun/requests/storage/get_bucket.rb', line 39

def get_bucket_logging(bucket_name)
  @oss_protocol.get_bucket_logging(bucket_name)
end

#get_bucket_referer(bucket_name) ⇒ Object



43
44
45
# File 'lib/fog/aliyun/requests/storage/get_bucket.rb', line 43

def get_bucket_referer(bucket_name)
  @oss_protocol.get_bucket_referer(bucket_name)
end

#get_bucket_website(bucket_name) ⇒ Object



47
48
49
# File 'lib/fog/aliyun/requests/storage/get_bucket.rb', line 47

def get_bucket_website(bucket_name)
  @oss_protocol.get_bucket_website(bucket_name)
end

#get_object(bucket_name, object_name, options = {}, &block) ⇒ Object

Get details for object

Parameters

  • object_name<~String> - Name of object to look for



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fog/aliyun/requests/storage/get_object.rb', line 12

def get_object(bucket_name, object_name, options = {}, &block)
  options = options.reject { |_key, value| value.nil? }
  unless bucket_name
    raise ArgumentError.new('bucket_name is required')
  end
  unless object_name
    raise ArgumentError.new('object_name is required')
  end
  # Using OSS ruby SDK to fix performance issue
  http_options = { :headers => {} }
  http_options[:query] = options.delete('query') || {}

  http_options[:headers].merge!(options)
  if options['If-Modified-Since']
    http_options[:headers]['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header
  end
  if options['If-Unmodified-Since']
    http_options[:headers]['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header
  end

  if block_given?
    http_options[:response_block] = Proc.new {}
  end

  resources = {
      :bucket => bucket_name,
      :object => object_name
  }

  @oss_http.get(resources, http_options, &block)

end

#get_object_acl(bucket_name, object_name, options = {}) ⇒ Object

Get access control list for an S3 object

Parameters:

  • bucket_name (String)

    name of bucket containing object

  • object_name (String)

    name of object to get access control list for

  • options (Hash) (defaults to: {})

Options Hash (options):

  • versionId (String)

    specify a particular version to retrieve



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/aliyun/requests/storage/get_object_acl.rb', line 13

def get_object_acl(bucket_name, object_name, options = {})
  unless bucket_name
    raise ArgumentError.new('bucket_name is required')
  end
  unless object_name
    raise ArgumentError.new('object_name is required')
  end

  # At present, sdk does not support versionId
  # if version_id = options.delete('versionId')
  #   query['versionId'] = version_id
  # end
  @oss_protocol.get_object_acl(bucket_name, object_name)
end

#get_object_http_url_public(bucket_name, object_name, expires) ⇒ Object

Get an expiring object http url

Parameters

  • bucket_name<~String> - Name of bucket

  • object_name<~String> - Name of object to get expiring url for

  • expires<~Integer> - An expiry time for this url

Returns

  • response<~Excon::Response>:

    • body<~String> - url for object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/aliyun/requests/storage/get_object_http_url.rb', line 19

def get_object_http_url_public(bucket_name, object_name, expires)
  bucket = @oss_client.get_bucket(bucket_name)
  acl = bucket.acl()

  if acl == 'private'
    expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s
    resource = bucket_name + '/' + object_name
    signature = sign('GET', expires_time, nil, resource)
    'http://' + bucket_name + '.' + @host + '/' + object_name +
      '?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
      '&Signature=' + Addressable::URI.encode_component(signature, Addressable::URI::CharacterClasses::UNRESERVED + '|')
  elsif acl == 'public-read' || acl == 'public-read-write'
    'http://' + bucket_name + '.' + @host + '/' + object_name
  else
    'acl is wrong with value:' + acl
  end
end

#get_object_https_url_public(bucket_name, object_name, expires) ⇒ Object

Get an expiring object https url from Cloud Files

Parameters

  • bucket_name<~String> - Name of bucket

  • object_name<~String> - Name of object to get expiring url for

  • expires<~Integer> - An expiry time for this url

Returns

  • response<~Excon::Response>:

    • body<~String> - url for object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/aliyun/requests/storage/get_object_https_url.rb', line 19

def get_object_https_url_public(bucket_name, object_name, expires)
  bucket = @oss_client.get_bucket(bucket_name)
  acl = bucket.acl()

  if acl == 'private'
    expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s
    resource = bucket_name + '/' + object_name
    signature = sign('GET', expires_time, nil, resource)
    'https://' + bucket_name + '.' + @host + '/' + object_name +
      '?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
      '&Signature=' + Addressable::URI.encode_component(signature, Addressable::URI::CharacterClasses::UNRESERVED + '|')
  elsif acl == 'public-read' || acl == 'public-read-write'
    'https://' + bucket_name + '.' + @host + '/' + object_name
  else
    'acl is wrong with value:' + acl
  end
end

#get_serviceObject

List information about OSS buckets for authorized user



7
8
9
# File 'lib/fog/aliyun/requests/storage/get_service.rb', line 7

def get_service
  @oss_protocol.list_buckets
end

#head_object(bucket_name, object_name, options = {}) ⇒ Object

Get headers for object

Parameters

  • object_name<~String> - Name of object to look for



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/aliyun/requests/storage/head_object.rb', line 12

def head_object(bucket_name, object_name, options={})
  unless bucket_name
    raise ArgumentError.new('bucket_name is required')
  end
  unless object_name
    raise ArgumentError.new('object_name is required')
  end

  # Currently, the ruby sdk does not support versionId
  # if version_id = options.delete('versionId')
  #   query = {'versionId' => version_id}
  # end
  headers = {}
  headers['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header if options['If-Modified-Since']
  headers['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header if options['If-Modified-Since']
  headers.merge!(options)
  resources = {
      :bucket => bucket_name,
      :object => object_name
  }
  http_options = {
      :headers => headers
  }
  @oss_http.head(resources, http_options)
end

#initiate_multipart_upload(bucket_name, object_name, options = {}) ⇒ Object

Initiate a multipart upload

Parameters:

  • bucket_name (String)

    Name of bucket to create

  • object_name (String)

    Name of object to create

  • options (Hash) (defaults to: {})

See Also:



13
14
15
# File 'lib/fog/aliyun/requests/storage/initiate_multipart_upload.rb', line 13

def initiate_multipart_upload(bucket_name, object_name, options = {})
  @oss_protocol.initiate_multipart_upload(bucket_name, object_name, options)
end

#list_buckets(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/aliyun/requests/storage/list_buckets.rb', line 7

def list_buckets(options = {})
  maxKeys = options[:max_keys] || 1000
  maxKeys = maxKeys.to_i
  maxKeys = [maxKeys, 1000].min

  options[:limit] = maxKeys
  options.delete(:max_keys)
  @oss_protocol.list_buckets(options)
end

#list_multipart_uploads(bucket_name, _options = {}) ⇒ Object



17
18
19
# File 'lib/fog/aliyun/requests/storage/list_objects.rb', line 17

def list_multipart_uploads(bucket_name, _options = {})
  @oss_protocol.list_multipart_uploads(bucket_name, _options)
end

#list_objects(bucket_name, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/aliyun/requests/storage/list_objects.rb', line 7

def list_objects(bucket_name, options = {})
  maxKeys = options[:max_keys] || 1000
  maxKeys = maxKeys.to_i
  maxKeys = [maxKeys, 1000].min

  options[:limit] = maxKeys
  options.delete(:max_keys)
  @oss_protocol.list_objects(bucket_name, options)
end

#list_parts(bucket_name, object_name, upload_id, _options = {}) ⇒ Object



21
22
23
# File 'lib/fog/aliyun/requests/storage/list_objects.rb', line 21

def list_parts(bucket_name, object_name, upload_id, _options = {})
  @oss_protocol.list_parts(bucket_name, object_name, upload_id, _options)
end

#object_to_path(object_name = nil) ⇒ Object



145
146
147
# File 'lib/fog/aliyun/storage.rb', line 145

def object_to_path(object_name=nil)
  '/' + escape(object_name.to_s).gsub('%2F','/')
end

#put_bucket(bucket_name, options = {}) ⇒ Object



7
8
9
# File 'lib/fog/aliyun/requests/storage/put_bucket.rb', line 7

def put_bucket(bucket_name, options = {})
  @oss_protocol.create_bucket(bucket_name, options)
end

#put_object(bucket_name, object_name, data, options = {}) ⇒ Object

Put details for object

Parameters

  • bucket_name<~String> - Name of bucket to look for

  • object_name<~String> - Object of object to look for

  • data<~File>

  • options<~Hash>



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/aliyun/requests/storage/put_object.rb', line 15

def put_object(bucket_name, object_name, data, options = {})
  if data.is_a? ::File
    @oss_protocol.put_object(bucket_name, object_name, options)do |sw|
      while line = data.read(16*1024)
        sw.write(line)
      end
    end
  else
    content=StringIO.new(data.dup)
    @oss_protocol.put_object(bucket_name, object_name, options)do |sw|
      while line=content.read(16*1024)
        sw.write(line)
      end
    end
    content.close
  end
end

#region_to_endpoint(region = nil) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/fog/aliyun/storage.rb', line 136

def region_to_endpoint(region = nil)
  case region.to_s
  when ''
    "oss-#{DEFAULT_REGION}.aliyuncs.com"
  else
    "oss-#{region}.aliyuncs.com"
  end
end

#reloadObject



132
133
134
# File 'lib/fog/aliyun/storage.rb', line 132

def reload
  @connection.reset
end

#request(params) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/fog/aliyun/storage.rb', line 155

def request(params)
  method = params[:method]
  time = Time.new.utc
  date = time.strftime('%a, %d %b %Y %H:%M:%S GMT')

  bucket = params[:bucket]
  tmpHost = if bucket
              bucket + '.' + @host
            else
              @host
            end

  @connection = Fog::Core::Connection.new("#{@scheme}://#{tmpHost}", @persistent, @connection_options)
  contentType = params[:contentType]

  begin
    headers = ''
    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,
      'Date' => date
    }.merge!(params[:headers] || {}),
                                                path: "#{@path}/#{params[:path]}",
                                                query: params[:query]))
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
          when Excon::Errors::NotFound
            Fog::Aliyun::Storage::NotFound.slurp(error)
          else
            error
          end
  end

  response
end

#sign(method, date, contentType, resource = nil, headers = nil) ⇒ Object

copmute signature



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/fog/aliyun/storage.rb', line 198

def sign(method, date, contentType, resource = nil, headers = nil)
  contentmd5 = ''

  canonicalizedResource = if resource
                            '/' + resource
                          else
                            '/'
                          end

  canonicalizedOSSHeaders = headers || ''

  contentTypeStr = contentType || ''

  stringToSign = method + "\n" + contentmd5 + "\n" + contentTypeStr + "\n" + date + "\n" + canonicalizedOSSHeaders + canonicalizedResource

  digVer = OpenSSL::Digest.new('sha1')
  digest = OpenSSL::HMAC.digest(digVer, @aliyun_accesskey_secret, stringToSign)
  signature = Base64.encode64(digest)
  signature[-1] = ''

  signature
end

#upload_part(bucket_name, object_name, upload_id, part_number, data) ⇒ Object

Upload a part for a multipart upload

Parameters:

  • bucket_name (String)

    Name of bucket to add part to

  • object_name (String)

    Name of object to add part to

  • upload_id (String)

    Id of upload to add part to

  • part_number (String)

    Index of part in upload

  • data (File||String)

    Content for part

See Also:



16
17
18
19
20
# File 'lib/fog/aliyun/requests/storage/upload_part.rb', line 16

def upload_part(bucket_name, object_name, upload_id, part_number, data)
  @oss_protocol.upload_part(bucket_name, object_name, upload_id, part_number) do |sw|
      sw.write(data)
  end
end