Documentation ¶
Overview ¶
Package gcsstore provides a Google cloud storage based backend.
GCSStore is a storage backend that uses the GCSAPI interface in order to store uploads on GCS. Uploads will be represented by two files in GCS; the data file will be stored as an extensionless object uid and the JSON info file will stored as uid.info. In order to store uploads on GCS, make sure to specifiy the appropriate Google service account file path in the GCS_SERVICE_ACCOUNT_FILE environment variable. Also make sure that this service account file has the "https://www.googleapis.com/auth/devstorage.read_write" scope enabled so you can read and write data to the storage buckets associated with the service account file.
Index ¶
- Constants
- type GCSAPI
- type GCSComposeParams
- type GCSFilterParams
- type GCSObjectParams
- type GCSReader
- type GCSService
- func (service *GCSService) ComposeFrom(ctx context.Context, objSrcs []*storage.ObjectHandle, ...) (uint32, error)
- func (service *GCSService) ComposeObjects(ctx context.Context, params GCSComposeParams) error
- func (service *GCSService) DeleteObject(ctx context.Context, params GCSObjectParams) error
- func (service *GCSService) DeleteObjectsWithFilter(ctx context.Context, params GCSFilterParams) error
- func (service *GCSService) FilterObjects(ctx context.Context, params GCSFilterParams) ([]string, error)
- func (service *GCSService) GetObjectAttrs(ctx context.Context, params GCSObjectParams) (*storage.ObjectAttrs, error)
- func (service *GCSService) GetObjectSize(ctx context.Context, params GCSObjectParams) (int64, error)
- func (service *GCSService) ReadObject(ctx context.Context, params GCSObjectParams) (GCSReader, error)
- func (service *GCSService) SetObjectMetadata(ctx context.Context, params GCSObjectParams, metadata map[string]string) error
- func (service *GCSService) WriteObject(ctx context.Context, params GCSObjectParams, r io.Reader) (int64, error)
- type GCSStore
- func (store GCSStore) FinishUpload(id string) error
- func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error)
- func (store GCSStore) GetReader(id string) (io.Reader, error)
- func (store GCSStore) NewUpload(info tusd.FileInfo) (id string, err error)
- func (store GCSStore) Terminate(id string) error
- func (store GCSStore) UseIn(composer *tusd.StoreComposer)
- func (store GCSStore) WriteChunk(id string, offset int64, src io.Reader) (int64, error)
Constants ¶
const COMPOSE_RETRIES = 3
const CONCURRENT_SIZE_REQUESTS = 32
const MAX_OBJECT_COMPOSITION = 32
MAX_OBJECT_COMPOSITION specifies the maximum number of objects that can combined in a compose operation. GCloud storage's limit is 32.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GCSAPI ¶
type GCSAPI interface { ReadObject(ctx context.Context, params GCSObjectParams) (GCSReader, error) GetObjectSize(ctx context.Context, params GCSObjectParams) (int64, error) SetObjectMetadata(ctx context.Context, params GCSObjectParams, metadata map[string]string) error DeleteObject(ctx context.Context, params GCSObjectParams) error DeleteObjectsWithFilter(ctx context.Context, params GCSFilterParams) error WriteObject(ctx context.Context, params GCSObjectParams, r io.Reader) (int64, error) ComposeObjects(ctx context.Context, params GCSComposeParams) error FilterObjects(ctx context.Context, params GCSFilterParams) ([]string, error) }
GCSAPI is an interface composed of all the necessary GCS operations that are required to enable the tus protocol to work with Google's cloud storage.
type GCSComposeParams ¶
type GCSFilterParams ¶
type GCSObjectParams ¶
type GCSReader ¶
type GCSReader interface { Close() error ContentType() string Read(p []byte) (int, error) Remain() int64 Size() int64 }
GCSReader implements cloud.google.com/go/storage.Reader. It is used to read Google Cloud storage objects.
type GCSService ¶
GCSService holds the cloud.google.com/go/storage client as well as its associated context. Closures are used as minimal wrappers aroudn the Google Cloud Storage API, since the Storage API cannot be mocked. The usage of these closures allow them to be redefined in the testing package, allowing test to be run against this file.
func NewGCSService ¶
func NewGCSService(filename string) (*GCSService, error)
NewGCSService returns a GCSSerivce object given a GCloud service account file path.
func (*GCSService) ComposeFrom ¶
func (service *GCSService) ComposeFrom(ctx context.Context, objSrcs []*storage.ObjectHandle, dstParams GCSObjectParams, contentType string) (uint32, error)
ComposeFrom composes multiple object types together,
func (*GCSService) ComposeObjects ¶
func (service *GCSService) ComposeObjects(ctx context.Context, params GCSComposeParams) error
ComposeObjects composes multiple GCS objects in to a single object. Since GCS limits composition to a max of 32 objects, additional logic has been added to chunk objects in to groups of 32 and then recursively compose those objects together.
func (*GCSService) DeleteObject ¶
func (service *GCSService) DeleteObject(ctx context.Context, params GCSObjectParams) error
DeleteObject deletes the object defined by GCSObjectParams
func (*GCSService) DeleteObjectsWithFilter ¶
func (service *GCSService) DeleteObjectsWithFilter(ctx context.Context, params GCSFilterParams) error
DeleteObjectWithPrefix will delete objects who match the provided filter parameters.
func (*GCSService) FilterObjects ¶
func (service *GCSService) FilterObjects(ctx context.Context, params GCSFilterParams) ([]string, error)
FilterObjects retuns a list of GCS object IDs that match the passed GCSFilterParams. It expects GCS objects to be of the format uid_[chunk_idx] where chunk_idx is zero based. The format uid_tmp_[recursion_lvl]_[chunk_idx] can also be used to specify objects that have been composed in a recursive fashion. These different formats are usedd to ensure that objects are composed in the correct order.
func (*GCSService) GetObjectAttrs ¶
func (service *GCSService) GetObjectAttrs(ctx context.Context, params GCSObjectParams) (*storage.ObjectAttrs, error)
GetObjectAttrs returns the associated attributes of a GCS object. See: https://godoc.org/cloud.google.com/go/storage#ObjectAttrs
func (*GCSService) GetObjectSize ¶
func (service *GCSService) GetObjectSize(ctx context.Context, params GCSObjectParams) (int64, error)
GetObjectSize returns the byte length of the specified GCS object.
func (*GCSService) ReadObject ¶
func (service *GCSService) ReadObject(ctx context.Context, params GCSObjectParams) (GCSReader, error)
ReadObject reads a GCSObjectParams, returning a GCSReader object if successful, and an error otherwise
func (*GCSService) SetObjectMetadata ¶
func (service *GCSService) SetObjectMetadata(ctx context.Context, params GCSObjectParams, metadata map[string]string) error
SetObjectMetadata reads a GCSObjectParams and a map of metedata, returning a nil on sucess and an error otherwise
func (*GCSService) WriteObject ¶
func (service *GCSService) WriteObject(ctx context.Context, params GCSObjectParams, r io.Reader) (int64, error)
Write object writes the file set out by the GCSObjectParams
type GCSStore ¶
type GCSStore struct { // Specifies the GCS bucket that uploads will be stored in Bucket string // Service specifies an interface used to communicate with the Google // cloud storage backend. Implementation can be seen in gcsservice file. Service GCSAPI }
See the tusd.DataStore interface for documentation about the different methods.
func New ¶
New constructs a new GCS storage backend using the supplied GCS bucket name and service object.
func (GCSStore) FinishUpload ¶
func (GCSStore) UseIn ¶
func (store GCSStore) UseIn(composer *tusd.StoreComposer)