gcs

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 48 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gcs emulates Cloud Storage (SRS 5.4): the JSON API v1 (buckets, objects, uploads, notifications, IAM, HMAC keys, legacy ACLs, managed folders), the XML API subset used by the official clients for reads and by S3-style tools, V4 signed URLs and POST policies, Pub/Sub notifications and lifecycle rules. Object data is stored in files under the service data directory.

Index

Constants

View Source
const Name = "gcs"

Name is the service name.

Variables

This section is empty.

Functions

func New

func New(env *emu.Env) emu.Service

New returns the service.

Types

type Service

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

Service is the Cloud Storage service module.

func (*Service) AppendObject added in v0.9.0

func (s *Service) AppendObject(ctx context.Context, bucket, name, contentType string, data []byte) error

AppendObject implements emu.ObjectStore. Blobs are never modified in place, so each call copies the object's data into a new blob with data after it, and commits it as a new generation on the condition that the one it copied is still live.

func (*Service) ApplySeed

func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error

ApplySeed implements emu.Seeder.

func (*Service) ClockAdvanced

func (s *Service) ClockAdvanced(ctx context.Context) error

ClockAdvanced re-evaluates lifecycle rules after `gcpemu time advance` (FR-GCS-008).

func (*Service) EnsureServiceBucket added in v0.9.0

func (s *Service) EnsureServiceBucket(ctx context.Context, project, name string) error

EnsureServiceBucket implements emu.ObjectStore.

func (*Service) EnvVars

func (s *Service) EnvVars(gw string, endpoints map[string]string) map[string]string

EnvVars implements emu.EnvVarer (FR-CORE-004).

func (*Service) EvaluateLifecycle

func (s *Service) EvaluateLifecycle(ctx context.Context) error

EvaluateLifecycle applies every bucket's lifecycle rules once, using the emulator clock. The core can call it after `gcpemu time advance`; it also runs periodically in the background.

func (*Service) ExportSeed added in v0.6.0

func (s *Service) ExportSeed(ctx context.Context) (any, error)

ExportSeed implements emu.SeedExporter: every bucket with the live generation of its objects (inline content) and its notification configs.

func (*Service) ForeignBucket added in v0.9.0

func (s *Service) ForeignBucket(r *http.Request) bool

ForeignBucket reports whether r reads from a bucket the Instance doesn't have, through the JSON API, its download path or the XML API. The Google front end's LAN listener reads those through from real GCS for callers without credentials, such as the Go module proxy's downloads (ADR 0021).

func (*Service) Name

func (s *Service) Name() string

Name implements emu.Service.

func (*Service) ReadObject added in v0.9.0

func (s *Service) ReadObject(ctx context.Context, bucket, name string, gen int64) (io.ReadCloser, int64, error)

ReadObject implements emu.ObjectStore.

func (*Service) Ready

func (s *Service) Ready() error

Ready implements emu.Service.

func (*Service) Register

func (s *Service) Register(r emu.Router) error

Register mounts the JSON API paths at the gateway root (the official clients use "/storage/v1/", "/upload/storage/v1/" and "/download/storage/v1/"), plus "/storage/" for prefix routing and storage.googleapis.com for host mode.

func (*Service) Reset

func (s *Service) Reset(ctx context.Context) error

Reset implements emu.Resetter: object data files are deleted; the core clears the metadata store.

func (*Service) ResourceCounts added in v0.2.0

func (s *Service) ResourceCounts() map[string]int

ResourceCounts implements emu.ResourceCounter.

func (*Service) Restore added in v0.6.0

func (s *Service) Restore(ctx context.Context, dir string) error

Restore implements emu.Snapshotter, after Reset emptied the blob store.

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches JSON API, upload, download, batch and XML API requests.

func (*Service) ServeObject

func (s *Service) ServeObject(w http.ResponseWriter, r *http.Request, bucket, path string)

ServeObject serves an object of bucket to a load balancer backend bucket request (FR-INT-003): the request path maps to the object name; the bucket's website configuration applies (mainPageSuffix for "/" and directory paths, notFoundPage with status 404); Range, HEAD and conditional requests (If-None-Match, If-Modified-Since) are honoured. Errors use the XML API format, as storage.googleapis.com returns them to a load balancer.

func (*Service) Signed added in v0.9.0

func (s *Service) Signed(r *http.Request) bool

Signed reports whether r is an XML API request carrying a V4 signature, in its query or its Authorization header, which serveXML verifies (and refuses when malformed).

func (*Service) Snapshot added in v0.6.0

func (s *Service) Snapshot(ctx context.Context, dir string) error

Snapshot implements emu.Snapshotter: object data is linked into dir (blobs are never modified in place) and resumable upload data copied.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start opens the per-service port (default 4443, for STORAGE_EMULATOR_HOST) and starts the lifecycle evaluator.

func (*Service) Stop

func (s *Service) Stop(ctx context.Context) error

Stop shuts the listener and background work down.

Jump to

Keyboard shortcuts

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