Documentation
¶
Overview ¶
Package url provides a quick API to sign Google Storage URLs using Google Service Account Credentials.
For an example, please see cmd/gurl in this repository.
Index ¶
- Constants
- type Params
- type Signer
- func (u *Signer) DeletePath(bucket, path string) (string, error)
- func (u *Signer) DownloadPath(bucket, path string) (string, error)
- func (u *Signer) Make(p *Params, d time.Duration) (string, error)
- func (u *Signer) MakeParams(method, bucket, path string, d time.Duration, headers map[string]string) (string, error)
- func (u *Signer) Params(p *Params) (string, error)
- func (u *Signer) Sign(method, hash, contentType, bucket, path string, headers map[string]string) (string, error)
- func (u *Signer) UploadPath(bucket, path string) (string, error)
Constants ¶
const ( // DefaultBaseURL is the base Google Storage URL. DefaultBaseURL = "https://storage.googleapis.com" // DefaultExpiration is the default expiration for signed URLs. DefaultExpiration = 1 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Params ¶
type Params struct { // BaseURL is the URL to use for building the URL. If not supplied, then // DefaultBaseURL will be used instead. BaseURL string // Method is the HTTP method (GET, PUT, ...). Method string // Hash is the md5 hash of the file content for an upload. Hash string // ContentType is the content type of the uploaded file. ContentType string // Expiration is the expiration time of a generated signature. Expiration time.Time // Headers are the extra headers. Headers map[string]string // Bucket is the storage bucket. Bucket string // Object is the object path. Object string }
Params are the signing params for generating a signed URL.
func (Params) HeaderString ¶
HeaderString sorts the headers in order, returning an ordered, usable string for use with signing.
func (Params) ObjectPath ¶
ObjectPath returns the canonical path.
type Signer ¶
type Signer struct { PrivateKey *rsa.PrivateKey ClientEmail string }
Signer is a url signer that generates signed URLs for use with Google Cloud Storage.
func FromFile ¶
FromFile creates a new Google URL Signer from Google Service Account.
Google Service Account credentials can be downloaded from the Google Cloud console: https://console.cloud.google.com/iam-admin/serviceaccounts/
func FromJSON ¶
FromJSON is an option that loads Google Service Account credentials from a JSON encoded buf to create a url signer.
Google Service Account credentials can be downloaded from the Google Cloud console: https://console.cloud.google.com/iam-admin/serviceaccounts/
func (*Signer) DeletePath ¶
DeletePath generates a signed path for deleting an object.
func (*Signer) DownloadPath ¶
DownloadPath generates a signed path for downloading an object.
func (*Signer) MakeParams ¶
func (u *Signer) MakeParams(method, bucket, path string, d time.Duration, headers map[string]string) (string, error)
MakeParams creates and signs a URL for the specified method, bucket, path, duration, and any additional headers.
func (*Signer) Params ¶
Params generates and signs the provided URL parameters.
Note: Please see the Sign method.