go.bigb.es/cacher/internal/s3

go.bigb.es/cacher @ v0.2.0 — f26ddc0e 11 days ago

import "go.bigb.es/cacher/internal/s3"

Overview

Package s3 wraps the AWS SDK v2 S3 client with the Garage-compatible settings that the existing .builds/lib/ci-lib.sh shell helpers configure via ~/.aws/config:

[default]
region = $AWS_DEFAULT_REGION
s3 =
    addressing_style = path
    signature_version = s3v4
(plus AWS_REQUEST/RESPONSE_CHECKSUM_* = when_required for Garage)

Types

T type Client

src
type Client struct {
	// contains filtered or unexported fields
}

Client is a small surface over the S3 SDK tuned for the cacher use case.

f func New

src
func New(opts Options) (*Client, error)

New constructs a Client. The HTTP client uses Go's default transport; callers can decorate later if needed (timeouts, proxies).

m func (*Client) Bucket

src
func (c *Client) Bucket() string

Bucket returns the configured bucket name (for diagnostics).

m func (*Client) Delete

src
func (c *Client) Delete(ctx context.Context, key string) error

Delete removes the object. Deleting a missing object returns nil (matches `aws s3 rm` semantics).

m func (*Client) Exists

src
func (c *Client) Exists(ctx context.Context, key string) (bool, error)

Exists returns true if the object is present.

m func (*Client) FullKey

src
func (c *Client) FullKey(key string) string

FullKey returns prefix/key, with single-slash semantics.

m func (*Client) Get

src
func (c *Client) Get(ctx context.Context, key string) (io.ReadCloser, error)

Get streams the object body. Caller must Close the returned reader.

m func (*Client) List

src
func (c *Client) List(ctx context.Context, sub string, recursive bool) (ListResult, error)

List walks objects under sub. When recursive is false, results are delimited by "/" so output matches `aws s3 ls` — common prefixes surface as "directories".

m func (*Client) PingBucket

src
func (c *Client) PingBucket(ctx context.Context) error

PingBucket is the smoke test used by `cacher doctor`. Garage rejects HeadBucket with 403 even for valid credentials, so we use a 1-key ListObjectsV2 instead — matches `aws s3 ls s3://$bucket/` from the shell helper this replaces.

m func (*Client) Put

src
func (c *Client) Put(ctx context.Context, key string, body io.Reader) error

Put uploads body to key, streaming. Multipart is automatic for bodies over the manager's PartSize threshold (5MiB by default).

m func (*Client) SetPrefix

src
func (c *Client) SetPrefix(prefix string)

SetPrefix mutates the configured key prefix in place. Used by `cacher list --root` to escape the project namespace.

T type ListResult

src
type ListResult struct {
	Keys     []string // object keys relative to the client prefix
	Prefixes []string // common prefixes (each ending in "/") relative to the client prefix
}

ListResult separates "files at this level" from "common prefixes (directories)". When recursive=true, Prefixes is always empty and Keys contains every object under sub.

T type Options

src
type Options struct {
	Endpoint  string
	Region    string
	Bucket    string
	Prefix    string
	KeyID     string
	Secret    string
	UserAgent string // appended to the default UA for traceability
}

Options configures a new Client.

Source files