gstorage

package module
v0.0.0-...-101cc1f Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2017 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

About gstorage

Package gstorage is a helper for signing Google Storage URLs for download/upload/delete.

Usage

Install in the normal way:

go get -u github.com/knq/gstorage

Please see the gsign util for an example for signing URLs.

Documentation

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 Option

type Option func(*URLSigner) error

Option represents a URLSigner option.

func GoogleServiceAccountCredentialsFile

func GoogleServiceAccountCredentialsFile(path string) Option

GoogleServiceAccountCredentialsFile is an option that loads Google Service Account credentials for from the specified file.

Google Service Account credentials can be downloaded from the Google Cloud console: https://console.cloud.google.com/iam-admin/serviceaccounts/

func GoogleServiceAccountCredentialsJSON

func GoogleServiceAccountCredentialsJSON(buf []byte) Option

GoogleServiceAccountCredentialsJSON is an option that loads Google Service Account credentials from a JSON encoded buf.

Google Service Account credentials can be downloaded from the Google Cloud console: https://console.cloud.google.com/iam-admin/serviceaccounts/

type SignParams

type SignParams 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
}

SignParams are the signing params for generating a signed URL.

func (SignParams) HeaderString

func (p SignParams) HeaderString() string

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

func (SignParams) ObjectPath

func (p SignParams) ObjectPath() string

ObjectPath returns the canonical path.

func (SignParams) String

func (p SignParams) String() string

String satisfies stringer returning the formatted string suitable for use with the URLSigner.

type URLSigner

type URLSigner struct {
	PrivateKey  *rsa.PrivateKey
	ClientEmail string
}

URLSigner provides a type that can generate signed URLs for use with Google Cloud Storage.

func NewURLSigner

func NewURLSigner(opts ...Option) (*URLSigner, error)

NewURLSigner creates a new URLSigner

func (*URLSigner) DeletePath

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

DeletePath generates a signed path for deleting an object.

func (*URLSigner) DownloadPath

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

DownloadPath generates a signed path for downloading an object.

func (*URLSigner) Make

func (u *URLSigner) Make(p *SignParams, d time.Duration) (string, error)

Make makes a URL for the specified signing params.

func (*URLSigner) MakeURL

func (u *URLSigner) MakeURL(method, bucket, path string, d time.Duration, headers map[string]string) (string, error)

MakeURL creates a signed URL for the method.

func (*URLSigner) Sign

func (u *URLSigner) 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 (*URLSigner) SignParams

func (u *URLSigner) SignParams(p *SignParams) (string, error)

SignParams signs using the URLSigner.

func (*URLSigner) UploadPath

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

UploadPath generates a signed path for uploading an object.

Directories

Path Synopsis
cmd
gsign command

Jump to

Keyboard shortcuts

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