gcs

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildLogPath

func BuildLogPath(gcsURL string) (string, error)

BuildLogPath returns the build log path from the test result gcsURL

func GetConsoleURL

func GetConsoleURL(gcsURL string) (string, error)

GetConsoleURL returns the gcs link renderable directly from a browser

Types

type Client

type Client interface {
	// NewStorageBucket creates a new bucket in GCS with uniform access policy
	NewStorageBucket(ctx context.Context, bkt, project string) error
	// DeleteStorageBucket removes all children objects, force if not empty
	DeleteStorageBucket(ctx context.Context, bkt string, force bool) error
	// Exists check if an object exists under a bucket, assuming bucket exists
	Exists(ctx context.Context, bkt, objPath string) bool
	// ListChildrenFiles recursively lists all children files
	ListChildrenFiles(ctx context.Context, bkt, dirPath string) ([]string, error)
	// ListDirectChildren lists direct children paths (incl. files and dir)
	ListDirectChildren(ctx context.Context, bkt, dirPath string) ([]string, error)
	// AttrObject returns the object attributes
	AttrObject(ctx context.Context, bkt, objPath string) (*storage.ObjectAttrs, error)
	// CopyObject copies objects from one location to another, assuming both src and dst
	// buckets both exist
	CopyObject(ctx context.Context, srcBkt, srcObjPath, dstBkt, dstObjPath string) error
	// ReadObject reads a GCS object and returns then contents in []byte
	ReadObject(ctx context.Context, bkt, objPath string) ([]byte, error)
	// WriteObject writes []byte content to a GCS object
	WriteObject(ctx context.Context, bkt, objPath string, content []byte) (int, error)
	// DeleteObject deletes an object
	DeleteObject(ctx context.Context, bkt, objPath string) error
	// Download downloads GCS object to a local file, assuming bucket exists
	Download(ctx context.Context, bktName, objPath, filePath string) error
	// Upload uploads a local file to a GCS object, assuming bucket exists
	Upload(ctx context.Context, bktName, objPath, filePath string) error
}

type GCSClient

type GCSClient struct {
	*storage.Client
}

nolint // there's also Client so they collide.

func NewClient

func NewClient(ctx context.Context, serviceAccount string) (*GCSClient, error)

NewClient creates new GCS client with given service account

func (*GCSClient) AttrObject

func (g *GCSClient) AttrObject(ctx context.Context, bucketName, objPath string) (*storage.ObjectAttrs, error)

AttrObject returns the object attributes

func (*GCSClient) CopyObject

func (g *GCSClient) CopyObject(ctx context.Context, srcBucketName, srcPath, dstBucketName, dstPath string) error

CopyObject copies objects from one location to another. Assumes both source and destination buckets exist.

func (*GCSClient) DeleteObject

func (g *GCSClient) DeleteObject(ctx context.Context, bucketName, objPath string) error

DeleteObject deletes an object

func (*GCSClient) DeleteStorageBucket

func (g *GCSClient) DeleteStorageBucket(ctx context.Context, bucketName string, force bool) error

DeleteStorageBucket removes all children objects and then deletes the bucket

func (*GCSClient) Download

func (g *GCSClient) Download(ctx context.Context, bucketName, objPath, dstPath string) error

Download gcs object to a file

func (*GCSClient) Exists

func (g *GCSClient) Exists(ctx context.Context, bucketName, objPath string) bool

Exists check if an object exists under a bucket, assuming bucket exists

func (*GCSClient) ListChildrenFiles

func (g *GCSClient) ListChildrenFiles(ctx context.Context, bucketName, dirPath string) ([]string, error)

ListChildrenFiles recursively lists all children files.

func (*GCSClient) ListDirectChildren

func (g *GCSClient) ListDirectChildren(ctx context.Context, bucketName, dirPath string) ([]string, error)

ListDirectChildren lists direct children paths (including files and directories).

func (*GCSClient) NewReader

func (g *GCSClient) NewReader(ctx context.Context, bucketName, objPath string) (*storage.Reader, error)

NewReader creates a new Reader of a gcs file. Important: caller must call Close on the returned Reader when done reading

func (*GCSClient) NewStorageBucket

func (g *GCSClient) NewStorageBucket(ctx context.Context, bucketName, project string) error

NewStorageBucket creates a new bucket in GCS with uniform access policy

func (*GCSClient) ReadObject

func (g *GCSClient) ReadObject(ctx context.Context, bucketName, objPath string) ([]byte, error)

ReadObject reads the content of a gcs object

func (*GCSClient) ReadURL

func (g *GCSClient) ReadURL(ctx context.Context, gcsURL string) ([]byte, error)

ReadURL reads from a gsUrl and return a log structure

func (*GCSClient) Upload

func (g *GCSClient) Upload(ctx context.Context, bucketName, objPath, srcPath string) error

Upload file to gcs object

func (*GCSClient) WriteObject

func (g *GCSClient) WriteObject(ctx context.Context, bucketName, objPath string,
	content []byte) (n int, err error)

WriteObject writes the content to a gcs object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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