gurl

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 14 Imported by: 0

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

View Source
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

func (p Params) HeaderString() string

HeaderString sorts the headers in order, returning an ordered, usable string for use with signing.

func (Params) ObjectPath

func (p Params) ObjectPath() string

ObjectPath returns the canonical path.

func (Params) String

func (p Params) String() string

String satisfies the fmt.Stringer interface.

Returns the ordered and formatted string suitable needed by Signer.

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

func FromFile(path string) (*Signer, error)

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

func FromJSON(buf []byte) (*Signer, error)

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 New

func New() (*Signer, error)

New creates a new url signer.

func (*Signer) DeletePath

func (u *Signer) DeletePath(bucket, path string) (string, error)

DeletePath generates a signed path for deleting an object.

func (*Signer) DownloadPath

func (u *Signer) DownloadPath(bucket, path string) (string, error)

DownloadPath generates a signed path for downloading an object.

func (*Signer) Make

func (u *Signer) Make(p *Params, d time.Duration) (string, error)

Make creates and signs a URL using the specified params and duration.

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

func (u *Signer) Params(p *Params) (string, error)

Params generates and signs the provided URL parameters.

Note: Please see the Sign method.

func (*Signer) Sign

func (u *Signer) Sign(method, hash, contentType, bucket, path string, headers map[string]string) (string, error)

Sign creates the signature for the provided method, hash, contentType, bucket, and path accordingly.

func (*Signer) UploadPath

func (u *Signer) UploadPath(bucket, path string) (string, error)

UploadPath generates a signed path for uploading an object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL