Documentation
¶
Index ¶
- Constants
- Variables
- func LocationType(loc string) string
- type APIError
- type Bucket
- type ComposeSource
- type ConfigProvider
- type CopyRequest
- type Handler
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type IAMBinding
- type IAMPolicy
- type InMemoryBackend
- func (b *InMemoryBackend) AppendUpload(id string, offset int64, chunk []byte, total int64) (UploadProgress, error)
- func (b *InMemoryBackend) CancelUpload(id string) error
- func (b *InMemoryBackend) ComposeObject(bucket, dst string, sources []ComposeSource, meta Patch, pre Preconds) (*Object, error)
- func (b *InMemoryBackend) CopyObject(req CopyRequest) (*Object, error)
- func (b *InMemoryBackend) CreateBucket(project string, p Patch) (*Bucket, error)
- func (b *InMemoryBackend) DeleteBucket(name string, pre Preconds) error
- func (b *InMemoryBackend) DeleteObject(bucket, name string, gen int64, pre Preconds) error
- func (b *InMemoryBackend) GetBucket(name string, pre Preconds) (*Bucket, error)
- func (b *InMemoryBackend) GetIAMPolicy(name string) (IAMPolicy, error)
- func (b *InMemoryBackend) GetObject(bucket, name string, gen int64, pre Preconds) (*Object, error)
- func (b *InMemoryBackend) ListBuckets(project, prefix, token string, limit int) page.Page[*Bucket]
- func (b *InMemoryBackend) ListObjects(bucket string, opts ListOptions) (ListResult, error)
- func (b *InMemoryBackend) PutObject(bucket, name string, data []byte, p Patch, pre Preconds) (*Object, error)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetIAMPolicy(name string, pol IAMPolicy) (IAMPolicy, error)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) StartUpload(bucket, name string, meta Patch, pre Preconds) (string, error)
- func (b *InMemoryBackend) UpdateBucket(name string, p Patch, replace bool, pre Preconds) (*Bucket, error)
- func (b *InMemoryBackend) UpdateObject(bucket, name string, gen int64, p Patch, replace bool, pre Preconds) (*Object, error)
- type ListOptions
- type ListResult
- type Object
- type Patch
- type Preconds
- type Provider
- type Settings
- type UploadProgress
Constants ¶
const DefaultPort = 4443
DefaultPort is the dedicated listener's default TCP port.
Variables ¶
var ErrNilAppContext = errors.New("gcpstorage: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
var ErrSnapshotBucketNull = errors.New("gcpstorage: restore snapshot: bucket is null")
ErrSnapshotBucketNull is returned by Restore when a snapshot holds a null bucket.
Functions ¶
func LocationType ¶
LocationType returns the GCS locationType of a bucket location.
Types ¶
type Bucket ¶
type Bucket struct {
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Objects map[string][]*Object `json:"objects"`
Labels map[string]string `json:"labels,omitempty"`
Config map[string]json.RawMessage `json:"config,omitempty"`
Name string `json:"name"`
Project string `json:"project"`
Location string `json:"location"`
StorageClass string `json:"storageClass"`
IAM IAMPolicy `json:"iam"`
Metageneration int64 `json:"metageneration"`
Versioning bool `json:"versioning,omitempty"`
DefaultEventBasedHold bool `json:"defaultEventBasedHold,omitempty"`
}
Bucket is a bucket with all of its object versions.
type ComposeSource ¶
ComposeSource is one source object of a compose request.
type ConfigProvider ¶
type ConfigProvider interface {
GetGCPStorageSettings() Settings
}
ConfigProvider extracts GCS configuration from the AppContext Config.
type CopyRequest ¶
type CopyRequest struct {
DstPre Preconds
SrcPre Preconds
Meta Patch
SrcBucket string
SrcName string
DstBucket string
DstName string
SrcGeneration int64
}
CopyRequest describes a copy or rewrite.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Port int
// contains filtered or unexported fields
}
Handler serves the Cloud Storage JSON and XML APIs.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler; callers override Port from Settings.
func (*Handler) ExtractOperation ¶
ExtractOperation returns the operation name for metrics.
func (*Handler) ExtractResource ¶
ExtractResource returns bucket[/object] for metrics.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the supported operations.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the Echo handler for all GCS requests.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: GCS runs on its own listener.
func (*Handler) Shutdown ¶
Shutdown stops the dedicated listener, forcing a close if graceful shutdown fails.
type IAMBinding ¶
type IAMBinding struct {
Condition json.RawMessage `json:"condition,omitempty"`
Role string `json:"role"`
Members []string `json:"members"`
}
IAMBinding is one role binding of a bucket IAM policy.
type IAMPolicy ¶
type IAMPolicy struct {
Etag string `json:"etag"`
Bindings []IAMBinding `json:"bindings"`
Version int `json:"version"`
}
IAMPolicy is a bucket IAM policy.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds all buckets, objects and resumable upload sessions under one lock.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend.
func (*InMemoryBackend) AppendUpload ¶
func (b *InMemoryBackend) AppendUpload(id string, offset int64, chunk []byte, total int64) (UploadProgress, error)
AppendUpload appends chunk at offset. total is the declared object size or -1 when unknown; once the received bytes reach it the object is committed.
func (*InMemoryBackend) CancelUpload ¶
func (b *InMemoryBackend) CancelUpload(id string) error
CancelUpload discards a resumable session.
func (*InMemoryBackend) ComposeObject ¶
func (b *InMemoryBackend) ComposeObject( bucket, dst string, sources []ComposeSource, meta Patch, pre Preconds, ) (*Object, error)
ComposeObject concatenates sources (same bucket) into dst.
func (*InMemoryBackend) CopyObject ¶
func (b *InMemoryBackend) CopyObject(req CopyRequest) (*Object, error)
CopyObject copies an object. A nil Meta inherits the source metadata; otherwise Meta supplies the destination metadata.
func (*InMemoryBackend) CreateBucket ¶
func (b *InMemoryBackend) CreateBucket(project string, p Patch) (*Bucket, error)
CreateBucket creates a bucket in project from the request body p.
func (*InMemoryBackend) DeleteBucket ¶
func (b *InMemoryBackend) DeleteBucket(name string, pre Preconds) error
DeleteBucket deletes an empty bucket.
func (*InMemoryBackend) DeleteObject ¶
func (b *InMemoryBackend) DeleteObject(bucket, name string, gen int64, pre Preconds) error
DeleteObject deletes the live version (archiving it in a versioned bucket) or, with gen set, permanently removes that generation.
func (*InMemoryBackend) GetBucket ¶
func (b *InMemoryBackend) GetBucket(name string, pre Preconds) (*Bucket, error)
GetBucket returns the bucket metadata.
func (*InMemoryBackend) GetIAMPolicy ¶
func (b *InMemoryBackend) GetIAMPolicy(name string) (IAMPolicy, error)
GetIAMPolicy returns the bucket IAM policy.
func (*InMemoryBackend) GetObject ¶
GetObject returns generation gen of an object, or the live one when gen is 0.
func (*InMemoryBackend) ListBuckets ¶
ListBuckets lists the project's buckets whose names start with prefix.
func (*InMemoryBackend) ListObjects ¶
func (b *InMemoryBackend) ListObjects(bucket string, opts ListOptions) (ListResult, error)
ListObjects lists objects in name order, collapsing delimited prefixes.
func (*InMemoryBackend) PutObject ¶
func (b *InMemoryBackend) PutObject(bucket, name string, data []byte, p Patch, pre Preconds) (*Object, error)
PutObject creates or overwrites an object.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads backend state from a snapshot.
func (*InMemoryBackend) SetIAMPolicy ¶
func (b *InMemoryBackend) SetIAMPolicy(name string, pol IAMPolicy) (IAMPolicy, error)
SetIAMPolicy replaces the bucket IAM policy; a non-empty etag must match.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises the backend state. In-flight resumable sessions are not persisted.
func (*InMemoryBackend) StartUpload ¶
func (b *InMemoryBackend) StartUpload(bucket, name string, meta Patch, pre Preconds) (string, error)
StartUpload opens a resumable upload session and returns its id.
func (*InMemoryBackend) UpdateBucket ¶
func (b *InMemoryBackend) UpdateBucket(name string, p Patch, replace bool, pre Preconds) (*Bucket, error)
UpdateBucket applies a PATCH (replace=false) or PUT (replace=true) body.
func (*InMemoryBackend) UpdateObject ¶
func (b *InMemoryBackend) UpdateObject( bucket, name string, gen int64, p Patch, replace bool, pre Preconds, ) (*Object, error)
UpdateObject applies a PATCH (replace=false) or PUT (replace=true) body.
type ListOptions ¶
type ListOptions struct {
Prefix string
Delimiter string
StartOffset string
EndOffset string
PageToken string
MaxResults int
Versions bool
IncludeTrailingDelimiter bool
}
ListOptions are the object list parameters.
type ListResult ¶
ListResult is one page of objects and collapsed prefixes.
type Object ¶
type Object struct {
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Deleted time.Time `json:"deleted"`
CustomTime time.Time `json:"customTime"`
Metadata map[string]string `json:"metadata,omitempty"`
Bucket string `json:"bucket"`
Name string `json:"name"`
ContentType string `json:"contentType"`
ContentEncoding string `json:"contentEncoding,omitempty"`
ContentDisposition string `json:"contentDisposition,omitempty"`
ContentLanguage string `json:"contentLanguage,omitempty"`
CacheControl string `json:"cacheControl,omitempty"`
StorageClass string `json:"storageClass"`
MD5 string `json:"md5,omitempty"`
CRC32C string `json:"crc32c"`
Data []byte `json:"data"`
Generation int64 `json:"generation"`
Metageneration int64 `json:"metageneration"`
ComponentCount int64 `json:"componentCount,omitempty"`
TemporaryHold bool `json:"temporaryHold,omitempty"`
EventBasedHold bool `json:"eventBasedHold,omitempty"`
}
Object is one stored object version. A version whose Deleted time is set is noncurrent; the live version, if any, is always last in its slice.
type Patch ¶
type Patch map[string]json.RawMessage
Patch is a decoded JSON request body, keyed by field name. A null value clears the field, as in a JSON merge patch.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Google Cloud Storage. Like the Azure services it runs on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
type Settings ¶
type Settings struct {
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 168-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPStorage.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.
type UploadProgress ¶
UploadProgress reports a session's state after an append.