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
- func New(env *emu.Env) emu.Service
- type Service
- func (s *Service) AppendObject(ctx context.Context, bucket, name, contentType string, data []byte) error
- func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error
- func (s *Service) ClockAdvanced(ctx context.Context) error
- func (s *Service) EnsureServiceBucket(ctx context.Context, project, name string) error
- func (s *Service) EnvVars(gw string, endpoints map[string]string) map[string]string
- func (s *Service) EvaluateLifecycle(ctx context.Context) error
- func (s *Service) ExportSeed(ctx context.Context) (any, error)
- func (s *Service) ForeignBucket(r *http.Request) bool
- func (s *Service) Name() string
- func (s *Service) ReadObject(ctx context.Context, bucket, name string, gen int64) (io.ReadCloser, int64, error)
- func (s *Service) Ready() error
- func (s *Service) Register(r emu.Router) error
- func (s *Service) Reset(ctx context.Context) error
- func (s *Service) ResourceCounts() map[string]int
- func (s *Service) Restore(ctx context.Context, dir string) error
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) ServeObject(w http.ResponseWriter, r *http.Request, bucket, path string)
- func (s *Service) Signed(r *http.Request) bool
- func (s *Service) Snapshot(ctx context.Context, dir string) error
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop(ctx context.Context) error
Constants ¶
const Name = "gcs"
Name is the service name.
Variables ¶
This section is empty.
Functions ¶
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) ClockAdvanced ¶
ClockAdvanced re-evaluates lifecycle rules after `gcpemu time advance` (FR-GCS-008).
func (*Service) EnsureServiceBucket ¶ added in v0.9.0
EnsureServiceBucket implements emu.ObjectStore.
func (*Service) EvaluateLifecycle ¶
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
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
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) 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) Register ¶
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 ¶
Reset implements emu.Resetter: object data files are deleted; the core clears the metadata store.
func (*Service) ResourceCounts ¶ added in v0.2.0
ResourceCounts implements emu.ResourceCounter.
func (*Service) Restore ¶ added in v0.6.0
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 ¶
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
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
Snapshot implements emu.Snapshotter: object data is linked into dir (blobs are never modified in place) and resumable upload data copied.