s3

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package s3 provides a thin adapter over aws-sdk-go-v2 for S3-compatible object storage. It implements the ObjectUploader interface used by cells/auditcore and other consumers.

This package intentionally does NOT re-export SDK types. For operations beyond Upload and Health (e.g., download, delete, presigned URLs), use the aws-sdk-go-v2 S3 client directly.

ref: github.com/aws/aws-sdk-go-v2/service/s3

Index

Constants

View Source
const (
	ErrAdapterS3Config errcode.Code = "ERR_ADAPTER_S3_CONFIG"
	ErrAdapterS3Upload errcode.Code = "ERR_ADAPTER_S3_UPLOAD"
	ErrAdapterS3Health errcode.Code = "ERR_ADAPTER_S3_HEALTH"
)

S3 adapter error codes.

View Source
const (

	// ProbeReady is the ops-contract name for the S3 readiness probe registered
	// by Checkers(). It is a healthz.ProbeName-typed const (snake_case +
	// "_ready" suffix), funneled by archtest PROBENAME-SEALED-FUNNEL-01 so
	// production code and tests reference the same identifier without drift.
	ProbeReady healthz.ProbeName = "s3_ready"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a thin S3 adapter backed by aws-sdk-go-v2. It implements lifecycle.ManagedResource: Checkers() reads the last known health state without network I/O; Worker() drives a background ticker that re-probes HeadBucket on each tick and updates state.

ref: runtime/websocket/hub.go — state-machine + worker adapter pattern. ref: kubernetes/kubernetes pkg/util/healthz — named health checkers.

func New

func New(ctx context.Context, clk clock.Clock, cfg Config) (*Client, error)

New creates a Client with ctx, clk and cfg. It synchronously runs one HeadBucket probe; failure returns a wrapped ErrAdapterS3Health error (fail-fast, symmetric to oidc adapter).

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close implements lifecycle.ManagedResource. It signals the worker to stop and waits for the goroutine to drain, bounded by ctx. Idempotent — safe to call from both Worker.Stop and ManagedResource.Close teardown paths.

Fast path: if the worker goroutine was never started (e.g. bootstrap aborted before Worker.Start was called), workerDone will never be closed. In that case we skip the select so we do not burn the shutdown budget on a non-existent drain.

ref: runtime/websocket/hub.go Close — idempotent + ctx-bounded pattern.

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

Health checks bucket accessibility via a direct HeadBucket network call. This is useful for one-shot diagnostics. The background worker and Checkers use the internal state, not this method.

Requires a full SDK client (c.s3 non-nil). When constructed via newClientWithHead with a mock (tests), c.s3 is nil and Health returns ErrAdapterS3Health rather than panicking on nil dereference.

func (*Client) Probes

func (c *Client) Probes() []healthz.Probe

Probes implements lifecycle.ManagedResource. It returns a single typed probe with name ProbeReady ("s3_ready") that reads the latest health state without any network call.

probe name follows the observability rule: snake_case + "_ready" suffix. ProbeReady is the single source of truth; both this method and tests reference it so the name cannot drift.

ref: runtime/websocket/hub.go Probes — state-read probe pattern.

func (*Client) SDK

func (c *Client) SDK() *awss3.Client

SDK returns the underlying aws-sdk-go-v2 S3 client for operations not covered by this thin adapter (download, delete, presigned URLs, etc.).

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, key string, data []byte, contentType string) error

Upload stores an object via PutObject. Used by cells implementing object archival.

Requires a full SDK client (c.s3 non-nil). When constructed via newClientWithHead with a mock (tests), c.s3 is nil and Upload returns ErrAdapterS3Upload rather than panicking on nil dereference.

func (*Client) Worker

func (c *Client) Worker() worker.Worker

Worker returns a worker.Worker that drives the background health probe loop.

ref: runtime/websocket/hub.go Worker — non-nil documents "auto-managed background worker".

type Config

type Config struct {
	Endpoint        string
	Region          string
	Bucket          string
	AccessKeyID     string
	SecretAccessKey string
	UsePathStyle    bool
	HTTPTimeout     time.Duration // default 30s
	HealthInterval  time.Duration // default 30s; background probe cadence
}

Config holds the S3 connection configuration.

func ConfigFromEnv

func ConfigFromEnv() Config

ConfigFromEnv creates a Config from environment variables.

Callers must pass a clock.Clock as the second argument to New(). Composition root: pass clock.Real(); tests: pass clockmock.New(...).

func (Config) Validate

func (c Config) Validate() error

Validate checks that required fields are populated and that the endpoint uses a TLS scheme for remote hosts (loopback exempt for dev/CI).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL