Documentation
¶
Overview ¶
Package blob is the transport-only object I/O layer shared by artifact repositories and the legacy CI artifact adapters.
A Store reads and writes opaque byte streams addressed by slash-separated keys. It knows nothing about artifact records, CI metadata, signatures, or key layouts: callers own those and pass fully formed keys. The package defines streaming put/get, head, conditional write and delete (if-absent and if-match), prefix listing with pagination, object tags, user metadata, capability reporting, and a small set of classified errors.
Conditional operations carry an ETag. ETags are opaque concurrency tokens and are never payload checksums. A store that cannot enforce a requested condition fails that operation with errors.ErrBlobConditionalUnsupported instead of silently overwriting. A mutation whose result was not observed (for example a connection reset after the request was sent) fails with an error for which IsAmbiguous is true and whose Temporary method reports true; callers reconcile by reading the object back.
Implementations live in subpackages: blob/local (filesystem) and blob/s3 (AWS SDK v2). The blobtest subpackage holds the shared conformance suite every implementation must pass.
This package must not import pkg/ci or any CI types. Dependencies point from CI adapters to blob.
Package blob is a generated GoMock package.
Index ¶
- Constants
- func CloneMap(m map[string]string) map[string]string
- func IsAmbiguous(err error) bool
- func IsConditionalUnsupported(err error) bool
- func IsNotFound(err error) bool
- func IsPreconditionFailed(err error) bool
- func MergeTags(defaults, overrides map[string]string) map[string]string
- func ValidateKey(key string) error
- func ValidateOpaqueKey(key string) error
- func ValidateTags(tags map[string]string) error
- type Capabilities
- type Condition
- type ConditionKind
- type DeleteOptions
- type Error
- type GetOptions
- type Kind
- type ListOptions
- type ListPage
- type MockStore
- func (m *MockStore) Capabilities() Capabilities
- func (m *MockStore) Delete(ctx context.Context, key string, opts DeleteOptions) error
- func (m *MockStore) EXPECT() *MockStoreMockRecorder
- func (m *MockStore) Get(ctx context.Context, key string, opts GetOptions) (*Object, error)
- func (m *MockStore) List(ctx context.Context, opts ListOptions) (*ListPage, error)
- func (m *MockStore) Name() string
- func (m *MockStore) Put(ctx context.Context, key string, body io.Reader, opts PutOptions) (*ObjectInfo, error)
- func (m *MockStore) Stat(ctx context.Context, key string, opts StatOptions) (*ObjectInfo, error)
- type MockStoreMockRecorder
- func (mr *MockStoreMockRecorder) Capabilities() *gomock.Call
- func (mr *MockStoreMockRecorder) Delete(ctx, key, opts any) *gomock.Call
- func (mr *MockStoreMockRecorder) Get(ctx, key, opts any) *gomock.Call
- func (mr *MockStoreMockRecorder) List(ctx, opts any) *gomock.Call
- func (mr *MockStoreMockRecorder) Name() *gomock.Call
- func (mr *MockStoreMockRecorder) Put(ctx, key, body, opts any) *gomock.Call
- func (mr *MockStoreMockRecorder) Stat(ctx, key, opts any) *gomock.Call
- type Object
- type ObjectInfo
- type PutOptions
- type StatOptions
- type Store
Constants ¶
const ( OpPut = "put" OpGet = "get" OpStat = "stat" OpDelete = "delete" OpList = "list" OpValidate = "validate" OpNew = "new" )
Operation names carried by Error.Op and used by every backend.
const ( MaxTags = 10 MaxTagKeyChars = 128 MaxTagValueChars = 256 )
S3 object tag limits, enforced for every store so tags are portable.
const MaxKeyBytes = 1024
MaxKeyBytes is the longest key any store accepts. It matches the S3 object key limit.
const UnknownSize int64 = -1
UnknownSize is the Size value of a PutOptions whose body length is not known in advance.
Variables ¶
This section is empty.
Functions ¶
func IsAmbiguous ¶
IsAmbiguous reports whether err means a mutation's outcome was not observed.
func IsConditionalUnsupported ¶
IsConditionalUnsupported reports whether err means the endpoint cannot enforce a condition.
func IsNotFound ¶
IsNotFound reports whether err means the object does not exist.
func IsPreconditionFailed ¶
IsPreconditionFailed reports whether err means a conditional write or delete lost its race.
func MergeTags ¶
MergeTags returns defaults overlaid with overrides. It returns nil when both are empty and never aliases either input.
func ValidateKey ¶
ValidateKey checks that key is a portable relative key: non-empty, valid UTF-8 without NUL or backslash, no leading or trailing slash, and no empty, "." or ".." segments. Filesystem stores require it; S3 stores apply it by default so a key is valid on every backend.
func ValidateOpaqueKey ¶
ValidateOpaqueKey applies only the limits every object store shares: non-empty, at most MaxKeyBytes bytes, valid UTF-8, and no NUL. It is used for legacy key patterns that are opaque strings rather than portable paths.
func ValidateTags ¶
ValidateTags checks the S3 object tag limits: at most MaxTags tags, non-empty keys of at most MaxTagKeyChars UTF-16 code units, and values of at most MaxTagValueChars UTF-16 code units.
Types ¶
type Capabilities ¶
type Capabilities struct {
// ConditionalPut reports that if-absent and if-match writes are enforced.
ConditionalPut bool
// ConditionalDelete reports that if-match deletes are enforced.
ConditionalDelete bool
// Multipart reports that bodies larger than one buffer stream without being held in memory.
Multipart bool
// Tags reports that object tags are stored and returned.
Tags bool
// Metadata reports that user metadata and content type are stored and returned.
Metadata bool
// Range reports that partial reads are supported.
Range bool
// Listing reports that prefix listing with pagination is supported.
Listing bool
// ListDelimiter reports that listing rolls keys up into common prefixes.
ListDelimiter bool
}
Capabilities describes what a store can enforce. It is computed without network access.
func (Capabilities) CheckDelete ¶
func (c Capabilities) CheckDelete(store, key string, opts DeleteOptions) error
CheckDelete returns a clear ErrBlobConditionalUnsupported error when the store cannot enforce an if-match delete.
func (Capabilities) CheckPut ¶
func (c Capabilities) CheckPut(store, key string, cond Condition) error
CheckPut returns a clear ErrBlobConditionalUnsupported error when the store cannot enforce cond.
func (Capabilities) SupportsPut ¶
func (c Capabilities) SupportsPut(cond Condition) bool
SupportsPut reports whether the store can enforce the put condition.
type Condition ¶
type Condition struct {
// Kind selects the guard.
Kind ConditionKind
// ETag is the expected current ETag for [ConditionIfMatch]. It is an opaque token.
ETag string
}
Condition guards a write. The zero value is unconditional.
func IfAbsent ¶
func IfAbsent() Condition
IfAbsent returns a condition that succeeds only when the key does not exist.
func (Condition) IsConditional ¶
IsConditional reports whether the condition constrains the write.
type ConditionKind ¶
type ConditionKind int
ConditionKind selects how a write is guarded.
const ( // ConditionNone writes unconditionally. ConditionNone ConditionKind = iota // ConditionIfAbsent writes only when the key does not exist (S3 If-None-Match: *). ConditionIfAbsent // ConditionIfMatch writes only when the current ETag equals Condition.ETag (S3 If-Match). ConditionIfMatch )
Condition kinds.
type DeleteOptions ¶
type DeleteOptions struct {
// IfMatch deletes only when the current ETag equals this opaque token.
IfMatch string
}
DeleteOptions describe one delete.
type Error ¶
type Error struct {
// Kind is the failure class.
Kind Kind
// Op is the transport operation, for example "put" or "stat".
Op string
// Key is the object key, when the operation addressed one.
Key string
// Err is the underlying cause.
Err error
}
Error is a classified blob failure. It matches both the kind sentinel and the cause under errors.Is, so context cancellation and SDK errors stay visible.
func NewError ¶
NewError returns a classified error. A nil err is allowed because every kind has a sentinel.
type GetOptions ¶
type GetOptions struct {
// Offset is the first byte to read.
Offset int64
// Length is the number of bytes to read from Offset. Zero or negative reads to the end.
Length int64
// SkipETag tells the store the caller does not need the ETag, so a store that derives it from
// the content may leave it empty instead of reading the whole object first.
SkipETag bool
}
GetOptions describe one read.
func (GetOptions) IsRange ¶
func (o GetOptions) IsRange() bool
IsRange reports whether the read is a partial read.
type Kind ¶
type Kind int
Kind classifies a blob error independently of the backend that produced it.
const ( // KindOther is any failure without a more specific class. It matches ErrBlobOperationFailed // and keeps the cause visible. KindOther Kind = iota // KindNotFound means the addressed object does not exist. KindNotFound // KindPrecondition means a conditional write or delete lost its race. KindPrecondition // KindUnsupported means the endpoint cannot enforce a required condition. KindUnsupported // KindAmbiguous means a mutation was sent but its result was not observed. KindAmbiguous // KindInvalid means the request itself was malformed. KindInvalid // KindIdentity means a configured identity could not be resolved to credentials. KindIdentity )
Error kinds.
type ListOptions ¶
type ListOptions struct {
// Prefix restricts the listing to keys beginning with it.
Prefix string
// Delimiter groups keys sharing a prefix up to the delimiter into CommonPrefixes.
Delimiter string
// Cursor continues a previous listing.
Cursor string
// Limit caps the entries (objects plus common prefixes) in one page; zero uses the store default.
Limit int
}
ListOptions describe one listing page.
type ListPage ¶
type ListPage struct {
// Objects are the keys found, lexicographically ordered.
Objects []ObjectInfo
// CommonPrefixes are rolled-up prefixes when a delimiter was requested.
CommonPrefixes []string
// NextCursor continues the listing; empty means complete.
NextCursor string
}
ListPage is one page of a listing.
type MockStore ¶
type MockStore struct {
// contains filtered or unexported fields
}
MockStore is a mock of Store interface.
func NewMockStore ¶
func NewMockStore(ctrl *gomock.Controller) *MockStore
NewMockStore creates a new mock instance.
func (*MockStore) Capabilities ¶
func (m *MockStore) Capabilities() Capabilities
Capabilities mocks base method.
func (*MockStore) EXPECT ¶
func (m *MockStore) EXPECT() *MockStoreMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockStore) Put ¶
func (m *MockStore) Put(ctx context.Context, key string, body io.Reader, opts PutOptions) (*ObjectInfo, error)
Put mocks base method.
func (*MockStore) Stat ¶
func (m *MockStore) Stat(ctx context.Context, key string, opts StatOptions) (*ObjectInfo, error)
Stat mocks base method.
type MockStoreMockRecorder ¶
type MockStoreMockRecorder struct {
// contains filtered or unexported fields
}
MockStoreMockRecorder is the mock recorder for MockStore.
func (*MockStoreMockRecorder) Capabilities ¶
func (mr *MockStoreMockRecorder) Capabilities() *gomock.Call
Capabilities indicates an expected call of Capabilities.
func (*MockStoreMockRecorder) Delete ¶
func (mr *MockStoreMockRecorder) Delete(ctx, key, opts any) *gomock.Call
Delete indicates an expected call of Delete.
func (*MockStoreMockRecorder) Get ¶
func (mr *MockStoreMockRecorder) Get(ctx, key, opts any) *gomock.Call
Get indicates an expected call of Get.
func (*MockStoreMockRecorder) List ¶
func (mr *MockStoreMockRecorder) List(ctx, opts any) *gomock.Call
List indicates an expected call of List.
func (*MockStoreMockRecorder) Name ¶
func (mr *MockStoreMockRecorder) Name() *gomock.Call
Name indicates an expected call of Name.
type Object ¶
type Object struct {
ObjectInfo
// Body streams the (possibly ranged) content.
Body io.ReadCloser
}
Object is an open object. Callers must close Body.
type ObjectInfo ¶
type ObjectInfo struct {
// Key is the object key.
Key string
// Size is the full object size in bytes, even for a ranged read.
Size int64
// ETag is an opaque concurrency token, never a payload checksum.
ETag string
// ContentType is the stored content type, when known.
ContentType string
// LastModified is the last modification time.
LastModified time.Time
// Metadata is user metadata, when loaded.
Metadata map[string]string
// Tags are object tags, loaded only when requested.
Tags map[string]string
}
ObjectInfo describes a stored object.
func ListAll ¶
func ListAll(ctx context.Context, store Store, opts ListOptions) ([]ObjectInfo, []string, error)
ListAll follows the pagination cursor until the listing is complete and returns every object and common prefix. Callers that can stop early should page manually.
type PutOptions ¶
type PutOptions struct {
// Size is the body length in bytes, or [UnknownSize]. A known size is verified: a body that
// is shorter or longer fails the call and leaves no object behind.
Size int64
// ContentType is stored with the object when non-empty.
ContentType string
// Metadata is stored as user metadata.
Metadata map[string]string
// Tags are explicit object tags. Stores that merge default tags apply them first; these win.
Tags map[string]string
// Condition guards the write. The zero value is unconditional.
Condition Condition
}
PutOptions describe one write.
type StatOptions ¶
type StatOptions struct {
// IncludeTags also loads the object tags, which may cost an extra request.
IncludeTags bool
// SkipETag tells the store the caller does not need the ETag, so a store that derives it from
// the content may leave it empty instead of reading the whole object first.
SkipETag bool
}
StatOptions describe one head request.
type Store ¶
type Store interface {
// Name returns the implementation name, for example "local" or "s3".
Name() string
// Capabilities describes what the store can enforce without network access.
Capabilities() Capabilities
// Put streams body to key. An unmet or unenforceable [PutOptions.Condition] fails the call
// without changing the object. Returned info describes the stored object, including its ETag.
Put(ctx context.Context, key string, body io.Reader, opts PutOptions) (*ObjectInfo, error)
// Get opens key for streaming. Callers must close the returned body. A missing object fails
// with ErrBlobNotFound.
Get(ctx context.Context, key string, opts GetOptions) (*Object, error)
// Stat returns object attributes. Some backends read the body to compute an ETag. A missing object fails with
// ErrBlobNotFound.
Stat(ctx context.Context, key string, opts StatOptions) (*ObjectInfo, error)
// Delete removes key. Deleting a missing object without a condition succeeds. With
// [DeleteOptions.IfMatch] set, a missing object fails with ErrBlobNotFound and a different ETag
// fails with ErrBlobPreconditionFailed.
Delete(ctx context.Context, key string, opts DeleteOptions) error
// List returns one lexicographically ordered page of objects under a prefix. Pass the returned
// NextCursor back to continue; an empty NextCursor means the listing is complete.
List(ctx context.Context, opts ListOptions) (*ListPage, error)
}
Store is transport-only object I/O. Keys are slash-separated and already fully formed by the caller; a Store never interprets them beyond validation. Every method honors context cancellation. Implementations are safe for concurrent use.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package blobtest is the shared conformance suite for blob.Store implementations.
|
Package blobtest is the shared conformance suite for blob.Store implementations. |
|
Package local is the filesystem implementation of blob.Store.
|
Package local is the filesystem implementation of blob.Store. |
|
Package s3 is the AWS SDK v2 implementation of blob.Store, plus the shared S3 client construction used by the legacy CI artifact adapter.
|
Package s3 is the AWS SDK v2 implementation of blob.Store, plus the shared S3 client construction used by the legacy CI artifact adapter. |
|
s3test
Package s3test is an in-process, S3-compatible HTTP server for tests.
|
Package s3test is an in-process, S3-compatible HTTP server for tests. |