adminhandler

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package adminhandler implements the go-faster/fs admin API: instance info and runtime access-key management, backed by an auth.Manager.

Index

Constants

This section is empty.

Variables

View Source
var ErrBucketNotFound = errors.New("bucket not found")

ErrBucketNotFound is returned by a BucketSchemeStore when the named bucket does not exist; the handler maps it to 404.

View Source
var ErrPublicReadRejected = errors.New("public-read bucket list rejected")

ErrPublicReadRejected is returned by a PublicReadStore when a bucket name is invalid; the handler maps it to 400.

View Source
var ErrRebalanceConflict = errors.New("invalid rebalance transition")

ErrRebalanceConflict marks an invalid rebalance transition (starting a running rebalance, pausing an idle one); it maps to 409.

View Source
var ErrSchemeRejected = errors.New("scheme rejected")

ErrSchemeRejected is returned by a BucketSchemeStore when a scheme is invalid or the topology cannot host it; the handler maps it to 400.

Functions

func UIMiddleware

func UIMiddleware() func(http.Handler) http.Handler

UIMiddleware serves the embedded admin SPA for non-API requests, delegating everything under /api/ to the next handler (the ogen server). Unknown paths fall back to index.html so client-side routing works. When the SPA was not built, a placeholder page is served instead.

Types

type AdminAPI

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

AdminAPI implements adminapi.Handler.

func NewAdminAPI

func NewAdminAPI(opts Options) *AdminAPI

NewAdminAPI builds an AdminAPI.

func (*AdminAPI) ControlRebalance

ControlRebalance starts, pauses or resumes the rebalance runner.

func (*AdminAPI) CreateAccessKey

CreateAccessKey creates a runtime credential.

func (*AdminAPI) DeleteAccessKey

func (a *AdminAPI) DeleteAccessKey(_ context.Context, params adminapi.DeleteAccessKeyParams) error

DeleteAccessKey removes a runtime credential.

func (*AdminAPI) GetBucketScheme added in v0.7.0

func (a *AdminAPI) GetBucketScheme(ctx context.Context, params adminapi.GetBucketSchemeParams) (*adminapi.BucketScheme, error)

GetBucketScheme reports a bucket's effective scheme, its override and the cluster default.

func (*AdminAPI) GetClusterStatus added in v0.6.0

func (a *AdminAPI) GetClusterStatus(ctx context.Context) (*adminapi.ClusterStatus, error)

GetClusterStatus reports the cluster-wide view.

func (*AdminAPI) GetInfo

func (a *AdminAPI) GetInfo(_ context.Context) (*adminapi.InstanceInfo, error)

GetInfo returns build info, uptime and the loaded config revision.

func (*AdminAPI) GetPublicReadBuckets added in v0.8.0

func (a *AdminAPI) GetPublicReadBuckets(ctx context.Context) (*adminapi.PublicReadBuckets, error)

GetPublicReadBuckets returns the cluster-wide public-read bucket list.

func (*AdminAPI) GetRebalanceStatus

func (a *AdminAPI) GetRebalanceStatus(ctx context.Context) (*adminapi.RebalanceStatus, error)

GetRebalanceStatus reports the node's rebalance runner state.

func (*AdminAPI) ListAccessKeys

func (a *AdminAPI) ListAccessKeys(_ context.Context) (*adminapi.AccessKeyList, error)

ListAccessKeys returns all credentials, secrets omitted.

func (*AdminAPI) NewError

func (a *AdminAPI) NewError(_ context.Context, err error) *adminapi.ErrorStatusCode

NewError maps an unhandled error to a 500 structured response.

func (*AdminAPI) ReloadConfig added in v0.6.0

func (a *AdminAPI) ReloadConfig(ctx context.Context) (*adminapi.ReloadResult, error)

ReloadConfig re-applies the hot-reloadable configuration and reports what changed.

func (*AdminAPI) SetBucketScheme added in v0.7.0

SetBucketScheme sets or clears a bucket's scheme override and returns the effective scheme after applying.

func (*AdminAPI) SetPublicReadBuckets added in v0.8.0

SetPublicReadBuckets replaces the cluster-wide public-read bucket list and returns the stored result.

type BucketSchemeStore added in v0.7.0

type BucketSchemeStore interface {
	// SchemeOverride returns the bucket's explicit scheme override, empty when
	// the bucket follows the cluster default. It returns ErrBucketNotFound when
	// the bucket does not exist.
	SchemeOverride(ctx context.Context, bucket string) (string, error)
	// SetScheme sets the bucket's override, or clears it when scheme is empty.
	// It returns ErrBucketNotFound when the bucket does not exist and
	// ErrSchemeRejected when the scheme is invalid or the topology cannot host
	// it.
	SetScheme(ctx context.Context, bucket, scheme string) error
}

BucketSchemeStore reads and writes a bucket's replication-scheme override in the cluster control plane. It is nil outside cluster mode, where the scheme endpoints return 501.

type BuildInfo

type BuildInfo struct {
	Version string
	Commit  string
}

BuildInfo is static build metadata reported by GetInfo.

type ClusterDisk added in v0.6.0

type ClusterDisk struct {
	ID         string
	Weight     float64
	TotalBytes uint64
	FreeBytes  uint64
}

ClusterDisk is one disk's placement weight and reported capacity.

type ClusterNode added in v0.6.0

type ClusterNode struct {
	ID    string
	Addr  string
	Rack  string
	Disks []ClusterDisk
}

ClusterNode is a cluster member and its disks.

type ClusterStatus added in v0.6.0

type ClusterStatus struct {
	SchemaVersion       int
	BinarySchemaVersion int
	Nodes               []ClusterNode
	// RebalanceRunning reports whether a runner holds the cluster-wide
	// election; the cursor is the in-progress/last resume point.
	RebalanceRunning              bool
	RebalanceCursorBucket, Cursor string
}

ClusterStatus is the cluster-wide view assembled from the control plane.

type ClusterStatusSource added in v0.6.0

type ClusterStatusSource interface {
	ClusterStatus(ctx context.Context) (ClusterStatus, error)
}

ClusterStatusSource assembles the cluster-wide status from etcd (topology, schema version, rebalance election/cursor). Implemented by the cluster runtime and the headless admin; nil outside cluster mode.

type CredentialManager added in v0.8.0

type CredentialManager interface {
	// List returns every credential, secrets omitted, sorted by access key.
	List() []auth.KeyInfo
	// Create adds a credential, generating the access key and/or secret when
	// CreateInput leaves them empty, and returns the secret exactly once.
	Create(in auth.CreateInput) (*auth.Created, error)
	// Delete removes a credential by access key.
	Delete(accessKey string) error
}

CredentialManager is the runtime access-key store the admin API manages. Both the local file-backed store (*auth.Manager) and the etcd-backed cluster store satisfy it, so the same endpoints serve single-node and cluster-wide credentials. Its methods do not take a context: the file store is in-memory, and the cluster store reads from a watch-maintained snapshot for List while bounding its own etcd writes for Create/Delete.

type Options

type Options struct {
	// Manager is the access-key store to manage. Optional: nil disables the
	// access-key endpoints (they return 501) — e.g. a headless cluster admin
	// with file-backed credentials, which live on the data nodes.
	Manager CredentialManager
	// Build is reported by GetInfo.
	Build BuildInfo
	// AuthEnabled reports whether the S3 server enforces SigV4.
	AuthEnabled bool
	// StartTime is the process start, for uptime. Defaults to now.
	StartTime time.Time
	// Rebalance drives the cluster rebalance runner; nil outside cluster mode
	// (the endpoints then report "disabled" / refuse control).
	Rebalance RebalanceControl
	// ClusterStatus assembles the cluster-wide status; nil outside cluster mode
	// (the endpoint then reports "disabled").
	ClusterStatus ClusterStatusSource
	// Reloader applies hot-reloadable configuration on demand (POST
	// /api/v1/reload); nil on a listener with nothing to reload (the headless
	// cluster admin), where the endpoint returns 501.
	Reloader Reloader
	// ConfigRevision returns the config revision currently in effect, reported
	// by GetInfo; nil reports none.
	ConfigRevision func() string
	// BucketSchemes reads and writes per-bucket replication-scheme overrides
	// via the control plane; nil outside cluster mode (the scheme endpoints
	// then return 501).
	BucketSchemes BucketSchemeStore
	// PublicRead reads and writes the cluster-wide public-read bucket list; nil
	// unless the server uses cluster-wide credentials (the public-read endpoints
	// then return 501).
	PublicRead PublicReadStore
	// ClusterDefaultScheme is the scheme applied to buckets without an override,
	// echoed by the scheme endpoints. Empty when unknown.
	ClusterDefaultScheme string
	// contains filtered or unexported fields
}

Options configures an AdminAPI.

type PublicReadStore added in v0.8.0

type PublicReadStore interface {
	// PublicReadBuckets returns the current public-read bucket list.
	PublicReadBuckets(ctx context.Context) ([]string, error)
	// SetPublicReadBuckets replaces the list. It returns ErrPublicReadRejected
	// when a bucket name is invalid.
	SetPublicReadBuckets(ctx context.Context, buckets []string) error
}

PublicReadStore reads and writes the cluster-wide list of anonymously-readable buckets in the control plane. It is nil unless the server uses cluster-wide credentials (auth.source: etcd), where the public-read endpoints return 501.

type RebalanceControl

type RebalanceControl interface {
	// Start launches the rebalance (campaigning for the cluster-wide slot).
	// Returns ErrRebalanceConflict when one is already waiting or running.
	Start(ctx context.Context) error
	// Pause stops this node's runner, keeping the resume cursor. Returns
	// ErrRebalanceConflict when nothing is waiting or running.
	Pause(ctx context.Context) error
	// Resume relaunches a paused rebalance from the persisted cursor. Returns
	// ErrRebalanceConflict unless the runner is paused.
	Resume(ctx context.Context) error
	// Status snapshots the runner.
	Status(ctx context.Context) RebalanceStatus
}

RebalanceControl drives the node's cluster rebalance runner. Implemented by the cluster runtime; absent (nil) outside cluster mode.

type RebalanceState

type RebalanceState string

RebalanceState is the node-local runner state.

const (
	RebalanceIdle    RebalanceState = "idle"
	RebalanceWaiting RebalanceState = "waiting"
	RebalanceRunning RebalanceState = "running"
	RebalancePaused  RebalanceState = "paused"
	RebalanceDone    RebalanceState = "done"
	RebalanceFailed  RebalanceState = "failed"
)

Runner states; see the admin API schema for semantics.

type RebalanceStatus

type RebalanceStatus struct {
	State RebalanceState
	// Objects, Relocated and Failed are the current or last run's progress.
	Objects, Relocated, Failed int
	// CursorBucket/CursorKey is the persisted resume cursor (empty when none).
	CursorBucket, CursorKey string
	// StartedAt/FinishedAt frame the current or last run; zero when unset.
	StartedAt, FinishedAt time.Time
	// Err is why the last run failed.
	Err string
	// RepairQueueDepth is the node's pending async remainder backlog.
	RepairQueueDepth int
}

RebalanceStatus is a snapshot of the node's rebalance runner.

type ReloadResult added in v0.6.0

type ReloadResult struct {
	// Reloaded names the hot-reloadable parts the reload applied, any of
	// "credentials", "tls".
	Reloaded []string
	// ConfigRevision is the config file's revision marker after the reload;
	// empty when the config sets none.
	ConfigRevision string
}

ReloadResult reports what a reload applied and the config revision left in effect.

type Reloader added in v0.6.0

type Reloader interface {
	// Reload re-reads the config file and applies the hot-reloadable parts,
	// returning what it changed and the config revision now in effect.
	Reload(ctx context.Context) (ReloadResult, error)
}

Reloader re-applies hot-reloadable configuration on demand — the same work SIGHUP does. Implemented by the S3 data node; absent (nil) on a listener with nothing to reload (the headless cluster admin serves no S3 data), where the endpoint returns 501.

Jump to

Keyboard shortcuts

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