gcp

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2018 License: MIT Imports: 16 Imported by: 0

README

Google Cloud Storage Driver

This driver provides support for storing module files in Google Cloud storage.

Configuration

NOTE: The GCP storage driver currently only supports the uploading of modules and so can not be used at this time as a storage back end.

Minimal configuration is needed, just the name of a storage bucket and an authentication method for that project, and then tell Athens you want to use that as your storage medium.

Driver Configuration

You will need to set an environment variable for the bucket name. ATHENS_STORAGE_GCP_BUCKET should be set to the name of the bucket you wish to use. It should be something like fancy-pony-339288.appspot.com.

The only currently supported authentication type is a service account key file in json format. For more information on appengine service accounts see here.

The service account requires a minimum of Storage Object Creator level of permission for the project on GCP. This path to this file must be set in the environment variable ATHENS_STORAGE_GCP_SA.

Athens Configuration

NOTE: Again, this is not yet implemented. In order to tell Olympus to use GCP storage set ATHENS_STORAGE_TYPE to gcp.

Contributing

If you would like to contribute to this driver you will need a service account for the test project in order to run tests.

Please contact robbie for access.

Documentation

Overview

Package gcp provides a storage driver to upload module files to a google cloud platform storage bucket.

Configuration

Environment variables:

ATHENS_STORAGE_GCP_BUCKET	// full name of storage bucket
ATHENS_STORAGE_GCP_SA		// path to json keyfile of a service account

Example:

Bash:
	export ATHENS_STORAGE_GCP_BUCKET="fancy-pony-33928.appspot.com"
Fish:
	set -x ATHENS_STORAGE_GCP_BUCKET fancy-pony-339288.appspot.com

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket interface {
	// Delete removes the file
	Delete(ctx context.Context, path string) error
	// Open returns a reader for a path and any error
	Open(ctx context.Context, path string) (io.ReadCloser, error)
	// Write returns a new writer for a path
	// This writer will overwrite any existing file stored at the same path
	Write(ctx context.Context, path string) io.WriteCloser
	// List returns a slice of paths for a prefix and any error
	List(ctx context.Context, prefix string) ([]string, error)
	// Exists returns true if the file exists
	Exists(ctx context.Context, path string) bool
}

Bucket provides file operations for a Google Cloud Storage resource.

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage implements the (./pkg/storage).Backend interface

func NewWithCredentials

func NewWithCredentials(ctx context.Context, cred option.ClientOption) (*Storage, error)

NewWithCredentials returns a new Storage instance authenticated using the provided ClientOptions. The bucket name to be used will be loaded from the environment variable ATHENS_STORAGE_GCP_BUCKET.

The ClientOptions should provide permissions sufficient to read, write and delete objects in google cloud storage for your project.

func (*Storage) BaseURL

func (s *Storage) BaseURL() *url.URL

BaseURL returns the base URL that stores all modules. It can be used in the "meta" tag redirect response to vgo.

For example:

<meta name="go-import" content="gomods.com/athens mod BaseURL()">

func (*Storage) Close

func (s *Storage) Close() error

Close calls the underlying storage client's close method It is not required to be called on program exit but provided here for completness.

func (*Storage) Delete

func (s *Storage) Delete(ctx context.Context, module, version string) error

Delete implements the (./pkg/storage).Deleter interface and removes a version of a module from storage. Returning ErrNotFound if the version does not exist.

func (*Storage) Exists

func (s *Storage) Exists(ctx context.Context, module, version string) bool

Exists implements the (./pkg/storage).Checker interface returning true if the module at version exists in storage

func (*Storage) Get

func (s *Storage) Get(ctx context.Context, module, version string) (*storage.Version, error)

Get retrieves a module at a specific version from storage as a (./pkg/storage).Version

The caller is responsible for calling close on the Zip ReadCloser

func (*Storage) List

func (s *Storage) List(ctx context.Context, module string) ([]string, error)

List implements the (./pkg/storage).Lister interface It returns a list of versions, if any, for a given module

func (*Storage) Save

func (s *Storage) Save(ctx context.Context, module, version string, mod []byte, zip io.Reader, info []byte) error

Save uploads the module's .mod, .zip and .info files for a given version It expects a context, which can be provided using context.Background from the standard library until context has been threaded down the stack. see issue: https://github.com/gomods/athens/issues/174

Uploaded files are publicly accessable in the storage bucket as per an ACL rule.

Jump to

Keyboard shortcuts

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