Sha256: 8f17031b96ded325787086563eff8fa2b3884c08adab71854885eae5ceafd35b

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module Fog
  module Aliyun
    class Storage
      class Real
        # Get an expiring object https url from Cloud Files
        #
        # ==== Parameters
        # * container<~String> - Name of container containing object
        # * object<~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
        def get_object_https_url_public(object, expires, options = {})
          options = options.reject { |_key, value| value.nil? }
          bucket_name = options[:bucket]
          bucket_name ||= @aliyun_oss_bucket
          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
            signature = sign('GET', expires_time, nil, resource)
            'https://' + bucket_name + '.' + @host + '/' + object +
              '?OSSAccessKeyId=' + @aliyun_accesskey_id + '&Expires=' + expires_time +
              '&Signature=' + URI.encode(signature, '/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
          elsif acl == 'public-read' || acl == 'public-read-write'
            'https://' + bucket_name + '.' + @host + '/' + object
          else
            'acl is wrong with value:' + acl
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fog-aliyun-0.3.18 lib/fog/aliyun/requests/storage/get_object_https_url.rb
fog-aliyun-0.3.17 lib/fog/aliyun/requests/storage/get_object_https_url.rb
fog-aliyun-0.3.16 lib/fog/aliyun/requests/storage/get_object_https_url.rb