File: get_object_http_url.rb

package info (click to toggle)
ruby-fog-aliyun 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 720 kB
  • sloc: ruby: 5,804; makefile: 6; sh: 3
file content (39 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
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
# frozen_string_literal: true

require 'addressable'

module Fog
  module Aliyun
    class Storage
      class Real
        # 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
        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
      end
    end
  end
end