gcs

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package gcs defines the Google Cloud Storage provider contract.

Slice 0 intentionally pins the stable configuration surface and SDK intake without enabling command dispatch or implementing provider operations.

Index

Constants

View Source
const (
	// DefaultMaxKeys is the default page size for List operations.
	DefaultMaxKeys = 1000

	// MaxAllowedKeys is the maximum page size accepted by the JSON API list
	// maxResults parameter.
	MaxAllowedKeys = 1000

	// DefaultWriterChunkSizeBytes is the GCS SDK's default storage.Writer
	// ChunkSize. Each active writer allocates this much buffer memory unless a
	// provider config overrides WriterChunkSizeBytes.
	DefaultWriterChunkSizeBytes = 16 * 1024 * 1024

	// MinWriterChunkSizeBytes is the GCS SDK's minimum resumable-upload chunk
	// quantum. The SDK rounds positive chunk sizes up to this multiple.
	MinWriterChunkSizeBytes = googleapi.MinUploadChunkSize
)

Variables

This section is empty.

Functions

func DefaultScopes

func DefaultScopes() []string

DefaultScopes returns the provider's default OAuth scope set for ADC/token construction points that require explicit scopes.

Types

type Config

type Config struct {
	// Bucket is the GCS bucket name (required).
	Bucket string

	// Project is the optional GCP project for client construction. Empty lets
	// the SDK infer project context when supported.
	Project string

	// Anonymous issues unauthenticated read requests for public buckets. It is
	// mutually exclusive with TokenSource and never falls back to ADC.
	Anonymous bool

	// TokenSource overrides credential resolution with caller-managed OAuth2
	// tokens. It takes precedence over ADC and intentionally carries an already
	// resolved credential handle rather than a credentials filepath.
	TokenSource oauth2.TokenSource

	// MaxKeys is the default page size for List operations.
	// Zero uses the provider default (1000). Values over 1000 are clamped.
	MaxKeys int

	// MaxIdleConnsPerHost optionally sizes the per-host idle HTTP connection
	// pool for high-concurrency transfer paths. Zero leaves SDK defaults.
	MaxIdleConnsPerHost int

	// MaxConnsPerHost optionally caps total HTTP connections per host. Zero
	// leaves SDK defaults.
	MaxConnsPerHost int

	// WriterChunkSizeBytes optionally overrides storage.Writer.ChunkSize for
	// high-concurrency write paths. Zero keeps the SDK default; positive values
	// are rounded by the SDK to a 256 KiB multiple; negative values are invalid.
	WriterChunkSizeBytes int
}

Config configures a Google Cloud Storage provider.

Authentication priority:

  1. Anonymous unauthenticated reads when Anonymous is true; this is mutually exclusive with TokenSource and must fail closed for mutating operations.
  2. Caller-injected TokenSource, if provided.
  3. Google Application Default Credentials from the operator environment.

Credential source file paths are intentionally absent. GCP ADC external account files may contain credential_source.executable hooks, so manifest, CLI, and other untrusted config surfaces must never choose a credentials filepath for this package.

func (Config) AuthClientOptions

func (c Config) AuthClientOptions() []option.ClientOption

AuthClientOptions returns the SDK auth options implied by the config. It is intentionally limited to typed handles and anonymous mode; ADC remains the SDK default when no auth option is returned.

func (Config) GoString

func (c Config) GoString() string

GoString returns a redacted representation for %#v formatting.

func (Config) String

func (c Config) String() string

String returns a redacted representation of the config suitable for logs.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that required configuration is present.

type ConfigError

type ConfigError struct {
	Field   string
	Message string
}

ConfigError represents a configuration validation error.

func (*ConfigError) Error

func (e *ConfigError) Error() string

Error implements the error interface.

type Provider

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

Provider implements read operations for Google Cloud Storage.

func New

func New(ctx context.Context, cfg Config) (*Provider, error)

New creates a new GCS provider with the given configuration.

func (*Provider) Close

func (p *Provider) Close() error

Close releases resources held by the SDK client.

func (*Provider) ConditionalWriteCapabilities

func (p *Provider) ConditionalWriteCapabilities() provider.ConditionalWriteCapabilities

ConditionalWriteCapabilities declares the conditional-write predicates this GCS adapter honors: IfAbsent only, mapped to a DoesNotExist generation precondition. GCS has no ETag If-Match compare-and-swap here, so IfMatchETag is not offered and PutObjectConditional returns ErrUnsupportedPrecondition for it; conditional multipart completion is likewise unsupported.

func (*Provider) DeleteObject

func (p *Provider) DeleteObject(ctx context.Context, key string) error

DeleteObject deletes an object.

func (*Provider) GetObject

func (p *Provider) GetObject(ctx context.Context, key string) (io.ReadCloser, int64, error)

GetObject downloads an object as a stream.

func (*Provider) GetObjectRevision

func (p *Provider) GetObjectRevision(ctx context.Context, key string, revision provider.SourceRevision) (io.ReadCloser, provider.ObjectMeta, error)

GetObjectRevision downloads exactly the admitted generation or ETag.

func (*Provider) GetObjectVersioned

func (p *Provider) GetObjectVersioned(ctx context.Context, key string) (io.ReadCloser, provider.ObjectMeta, error)

GetObjectVersioned downloads an object and returns the generation observed from the same read handle.

func (*Provider) GetRange

func (p *Provider) GetRange(ctx context.Context, key string, start, endInclusive int64) (io.ReadCloser, int64, error)

GetRange downloads a byte range as a stream.

func (*Provider) Head

func (p *Provider) Head(ctx context.Context, key string) (*provider.ObjectMeta, error)

Head returns metadata for a single object.

func (*Provider) List

List returns a page of objects with the given prefix.

func (*Provider) ListCommonPrefixes

ListCommonPrefixes returns immediate child prefixes for prefix discovery.

func (*Provider) ListWithDelimiter

ListWithDelimiter returns direct objects and immediate child prefixes.

func (*Provider) PutObject

func (p *Provider) PutObject(ctx context.Context, key string, body io.Reader, contentLength int64) error

PutObject uploads an object.

func (*Provider) PutObjectConditional

func (p *Provider) PutObjectConditional(ctx context.Context, key string, body io.Reader, contentLength int64, precond provider.PutPrecondition) (provider.PutResult, error)

func (*Provider) PutObjectConditionalWithOptions

func (p *Provider) PutObjectConditionalWithOptions(ctx context.Context, key string, body io.Reader, _ int64, precond provider.PutPrecondition, opts provider.PutOptions) (provider.PutResult, error)

func (*Provider) PutObjectResult

func (p *Provider) PutObjectResult(ctx context.Context, key string, body io.Reader, contentLength int64) (provider.PutResult, error)

func (*Provider) PutObjectResultWithOptions

func (p *Provider) PutObjectResultWithOptions(ctx context.Context, key string, body io.Reader, _ int64, opts provider.PutOptions) (provider.PutResult, error)

func (*Provider) PutObjectWithOptions

func (p *Provider) PutObjectWithOptions(ctx context.Context, key string, body io.Reader, contentLength int64, opts provider.PutOptions) error

Jump to

Keyboard shortcuts

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