File: put_object_url.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 1,945 bytes parent folder | download | duplicates (4)
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
40
41
42
module Fog
  module Storage
    class GoogleJSON
      class Real
        # Get an expiring object url from Google Storage for putting an object
        # https://cloud.google.com/storage/docs/access-control#Signed-URLs
        #
        # @param bucket_name [String] Name of bucket containing object
        # @param object_name [String] Name of object to get expiring url for
        # @param expires [Time] Expiry time for this URL
        # @param headers [Hash] Optional hash of headers to include
        # @option options [String] "x-goog-acl" Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read'].
        #     If you want a file to be public you should to add { 'x-goog-acl' => 'public-read' } to headers
        #     and then call for example: curl -H "x-goog-acl:public-read" "signed url"
        # @return [String] Expiring object https URL
        def put_object_url(bucket_name, object_name, expires, headers = {})
          raise ArgumentError.new("bucket_name is required") unless bucket_name
          raise ArgumentError.new("object_name is required") unless object_name
          https_url({
                      :headers  => headers,
                      :host     => @host,
                      :method   => "PUT",
                      :path     => "#{bucket_name}/#{object_name}"
                    }, expires)
        end
      end

      class Mock
        def put_object_url(bucket_name, object_name, expires, headers = {})
          raise ArgumentError.new("bucket_name is required") unless bucket_name
          raise ArgumentError.new("object_name is required") unless object_name
          https_url({
                      :headers  => headers,
                      :host     => @host,
                      :method   => "PUT",
                      :path     => "#{bucket_name}/#{object_name}"
                    }, expires)
        end
      end
    end
  end
end