gcp

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// IteratorDone is returned when the looping of objects/content
	// has reached the end of the iteration.
	IteratorDone = iterator.Done
	// ErrorDirectoryExists is an error returned when the filename provided
	// is a directory.
	ErrorDirectoryExists = errors.New("filename is a directory")
)

Functions

func ValidateSecret

func ValidateSecret(secret *corev1.Secret) error

ValidateSecret validates the credential secret. The provided Secret may be nil.

Types

type GCSClient

type GCSClient struct {
	// client for interacting with the Google Cloud
	// Storage APIs.
	*gcpstorage.Client
}

GCSClient is a minimal Google Cloud Storage client for fetching objects.

func NewClient

func NewClient(ctx context.Context, bucket *sourcev1.Bucket, opts ...Option) (*GCSClient, error)

NewClient creates a new GCP storage client. The Client will automatically look for the Google Application Credential environment variable or look for the Google Application Credential file.

func (*GCSClient) BucketExists

func (c *GCSClient) BucketExists(ctx context.Context, bucketName string) (bool, error)

BucketExists returns if an object storage bucket with the provided name exists, or returns a (client) error.

func (*GCSClient) Close

func (c *GCSClient) Close(ctx context.Context)

Close closes the GCP Client and logs any useful errors.

func (*GCSClient) FGetObject

func (c *GCSClient) FGetObject(ctx context.Context, bucketName, objectName, localPath string) (string, error)

FGetObject gets the object from the provided object storage bucket, and writes it to targetPath. It returns the etag of the successfully fetched file, or any error.

func (*GCSClient) ObjectIsNotFound

func (c *GCSClient) ObjectIsNotFound(err error) bool

ObjectIsNotFound checks if the error provided is storage.ErrObjectNotExist.

func (*GCSClient) VisitObjects

func (c *GCSClient) VisitObjects(ctx context.Context, bucketName string, prefix string, visit func(path, etag string) error) error

VisitObjects iterates over the items in the provided object storage bucket, calling visit for every item. If the underlying client or the visit callback returns an error, it returns early.

type Option

type Option func(*options)

Option is a functional option for configuring the GCS client.

func WithAuth

func WithAuth(authOpts ...auth.Option) Option

WithAuth sets the auth options for workload identity authentication.

func WithProxyURL

func WithProxyURL(proxyURL *url.URL) Option

WithProxyURL sets the proxy URL to use for the GCS client.

func WithSecret

func WithSecret(secret *corev1.Secret) Option

WithSecret sets the secret to use for authenticating with GCP.

Jump to

Keyboard shortcuts

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