Documentation
¶
Overview ¶
Package s3store implements objectstore.Store over the S3 API for AWS S3, Cloudflare R2, GCS (S3-compatible endpoint with HMAC keys), and MinIO.
Index ¶
- Variables
- type NewStoreArgs
- type Provider
- type Store
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) DeleteMany(ctx context.Context, keys []string) ([]string, error)
- func (s *Store) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (s *Store) GetWithETag(ctx context.Context, key string) (io.ReadCloser, string, error)
- func (s *Store) List(ctx context.Context, prefix string, startAfter string) iter.Seq2[objectstore.Object, error]
- func (s *Store) Put(ctx context.Context, key string, body io.ReadSeeker, size int64) error
- func (s *Store) PutIfAbsent(ctx context.Context, key string, body io.ReadSeeker, size int64) (string, error)
- func (s *Store) PutIfMatch(ctx context.Context, key string, body io.ReadSeeker, size int64, etag string) (string, error)
- func (s *Store) Versioning(ctx context.Context) (objectstore.Versioning, error)
Constants ¶
This section is empty.
Variables ¶
var ErrLinkLocalEndpoint = errors.New(
"bucket endpoints may not reach link-local addresses",
)
ErrLinkLocalEndpoint reports a bucket endpoint that resolved to a link-local address, where cloud metadata services answer. It is refused whatever NewStoreArgs says.
var ErrPrivateEndpoint = errors.New(
"bucket endpoints may not reach private or loopback addresses " +
"unless PrivateAddressesAllowed is set",
)
ErrPrivateEndpoint reports a bucket endpoint that resolved to a private, loopback, or unspecified address of a store whose NewStoreArgs.PrivateAddressesAllowed is false.
Functions ¶
This section is empty.
Types ¶
type NewStoreArgs ¶
type NewStoreArgs struct {
// Provider selects endpoint and checksum defaults. Required.
Provider Provider
// Endpoint is the service URL. R2 and ProviderS3 require it; GCS
// defaults to storage.googleapis.com, and AWS to its regional endpoint.
Endpoint string
// Region is the bucket's region. AWS requires it; R2 uses "auto", GCS
// defaults to "auto", and ProviderS3 to us-east-1.
Region string
// Bucket is the bucket's name. Required.
Bucket string
// Prefix scopes every key to a directory of the bucket, without leading
// or trailing slashes; "" uses the whole bucket.
Prefix string
// AccessKeyID is the credential's ID (an HMAC key ID on GCS).
AccessKeyID string
// SecretAccessKey is the credential's secret. It signs every request
// and is never sent.
SecretAccessKey string
// PathStyle puts the bucket in the URL path instead of the host name,
// as MinIO and most self-hosted servers need.
PathStyle bool
// PrivateAddressesAllowed lets the store connect to private, loopback,
// and unspecified addresses, for a bucket on a LAN or on this host.
// Without it such an endpoint fails with ErrPrivateEndpoint, so an
// endpoint a user typed cannot reach services inside the network.
// Link-local and cloud metadata addresses are refused either way.
PrivateAddressesAllowed bool
}
NewStoreArgs configures NewStore.
type Provider ¶
type Provider string
Provider selects endpoint and checksum defaults.
const ( // ProviderAWS is Amazon S3. ProviderAWS Provider = "aws" // ProviderR2 is Cloudflare R2. ProviderR2 Provider = "r2" // ProviderGCS is Google Cloud Storage's S3-compatible XML API, with HMAC // keys. ProviderGCS Provider = "gcs" // ProviderS3 is any other S3-compatible service, such as MinIO. ProviderS3 Provider = "s3" )
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a bucket reached through the S3 API.
func NewStore ¶
func NewStore(args *NewStoreArgs) (*Store, error)
NewStore builds a client for the bucket.
func (*Store) Delete ¶
Delete removes an object. A missing key succeeds: S3 and R2 answer 204, and GCS answers 404 NoSuchKey, which is taken as success here.
func (*Store) DeleteMany ¶
DeleteMany removes keys with DeleteObjects, up to 1,000 per request. GCS's XML API has no multi-object delete, so GCS buckets delete one key at a time.
func (*Store) GetWithETag ¶
GetWithETag opens an object and returns its ETag, or on GCS its generation, which is what PutIfMatch takes there.
func (*Store) List ¶
func (s *Store) List( ctx context.Context, prefix string, startAfter string, ) iter.Seq2[objectstore.Object, error]
List pages through ListObjectsV2.
func (*Store) PutIfAbsent ¶
func (s *Store) PutIfAbsent( ctx context.Context, key string, body io.ReadSeeker, size int64, ) (string, error)
PutIfAbsent uploads with If-None-Match: *, so the bucket refuses the write when the key exists.
func (*Store) PutIfMatch ¶
func (s *Store) PutIfMatch( ctx context.Context, key string, body io.ReadSeeker, size int64, etag string, ) (string, error)
PutIfMatch uploads with If-Match: etag, so the bucket refuses the write when the object changed or is gone.
func (*Store) Versioning ¶
func (s *Store) Versioning(ctx context.Context) (objectstore.Versioning, error)
Versioning reads the bucket's versioning state. R2 has no versioning API, and a provider that refuses the call reports unknown rather than failing.