storekit

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package storekit holds what several object stores share and that names no cloud SDK: the rules of a key, the bounded read of a body, the whole-second time rule of S3, and the rules and the transport of the HTTP and the cloud stores (settings limits, redirect policy, Retry-After, the mapping of a status to a result). The bootstrap file checks its settings against the same rules.

Index

Constants

View Source
const (
	// MaxCloudKeyBytes is the longest key (prefix included) the stores of Google Cloud Storage and Azure Blob
	// Storage read: both services allow 1024.
	MaxCloudKeyBytes = 1024
	// DefaultCloudRequestTimeout bounds one Get of a cloud store, from the request to the last byte.
	DefaultCloudRequestTimeout = 30 * time.Second
	// MaxCloudRequestTimeout is the largest request timeout of a cloud store.
	MaxCloudRequestTimeout = MaxHTTPTimeout
	// MaxCloudRetryAfter bounds the Retry-After the stores pass on to the reader.
	MaxCloudRetryAfter = MaxHTTPRetryAfter
)
View Source
const (
	// DefaultHTTPMaxRedirects is the number of redirects an http store follows when the setting is left out.
	DefaultHTTPMaxRedirects = 3
	// MaxHTTPRedirects is the largest number of redirects that can be set.
	MaxHTTPRedirects = 10
	// MaxHTTPTimeout is the largest value of any of the timeouts of an http store.
	MaxHTTPTimeout = 10 * time.Minute
	// MaxHTTPRetryAfter bounds the Retry-After the store passes on to the reader.
	MaxHTTPRetryAfter = 5 * time.Minute

	// DefaultHTTPConnectTimeout bounds the dial, and the TLS handshake on its own.
	DefaultHTTPConnectTimeout = 10 * time.Second
	// DefaultHTTPHeaderTimeout bounds the wait for the response headers after the request was written.
	DefaultHTTPHeaderTimeout = 20 * time.Second
	// DefaultHTTPRequestTimeout bounds one Get from the dial to the last byte of the body.
	DefaultHTTPRequestTimeout = 30 * time.Second

	// UserAgent is the User-Agent the HTTP side of the stores sends.
	UserAgent = "semaphore-relay"
	// IdleTimeout is how long an idle connection of a store stays open.
	IdleTimeout = 90 * time.Second
	// MaxIdle is the number of idle connections a store keeps.
	MaxIdle = 4
	// MaxHeaderBytes bounds the response headers: the answer of a static host has a few hundred bytes of them.
	MaxHeaderBytes = 64 << 10

	// SchemeHTTP and SchemeHTTPS are the two schemes of a store address.
	SchemeHTTP  = "http"
	SchemeHTTPS = "https"
)

Limits and defaults of the settings of the HTTP stores.

Variables

View Source
var (
	// ErrCloudKeyRefused is the cause of a key that is not a clean relative slash path of at most [MaxCloudKeyBytes].
	ErrCloudKeyRefused = errors.New("objectstore: object key refused")
	// ErrCloudAuth is the cause of a 401 or 403 answer.
	ErrCloudAuth = errors.New("objectstore: object store access refused")
	// ErrCloudStatus is the cause of an answer with a status the store does not map to a result of its own.
	ErrCloudStatus = errors.New("objectstore: unexpected object store status")
	// ErrCloudNoContainer is the cause of an answer that says the bucket or the container does not exist: the
	// configuration is wrong, not the object.
	ErrCloudNoContainer = errors.New("objectstore: the bucket or container does not exist")
	// ErrCloudNoValidator is the cause of an answer without the generation or ETag of the object: the reader could
	// not tell a later change.
	ErrCloudNoValidator = errors.New("objectstore: the answer holds no generation or ETag")
)

Causes carried by the *objectstore.FetchError of a [GCSStore] or an [AzureBlobStore], and by the errors of their constructors. They are for errors.Is; the reader reports only the reason. None of them holds a name, a URL or a secret.

View Source
var (
	// ErrHTTPRedirectRefused is the cause of a redirect that the store does not follow: to another origin, to a lower
	// scheme, to an address with credentials, or past the limit.
	ErrHTTPRedirectRefused = errors.New("objectstore: http redirect refused")
	// ErrHTTPCleartextRefused is the cause of a connection that a cleartext store was about to open to an address that
	// is not a loopback address: the address that the host name resolved to is checked when the connection is made.
	ErrHTTPCleartextRefused = errors.New("objectstore: http cleartext connection refused")
	// ErrHTTPHeader is the cause of a header that cannot be configured. It never names a value.
	ErrHTTPHeader = errors.New("objectstore: invalid http header")
)

Causes of the HTTP side of the stores (the HTTP store and the two cloud stores, which send their requests the same way). They are for errors.Is; the reader reports only the reason.

View Source
var ErrCloudRangeRefused = errors.New("objectstore: a cloud store does not resume a broken read")

ErrCloudRangeRefused is the cause of a request that a cloud client was about to send to resume a read that broke: one with a Range header, or a second one in a call. The stores ask for whole objects, so it would be a request behind the back of the reader and its budget.

Functions

func CheckCloudSetting

func CheckCloudSetting(name, prefix, endpoint string, timeout time.Duration) error

CheckCloudSetting is the validation the two constructors share.

func CheckHTTPHeaderName

func CheckHTTPHeaderName(name string) error

CheckHTTPHeaderName reports why a header name cannot be configured, or nil.

func CheckHTTPHeaderValue

func CheckHTTPHeaderValue(value string) error

CheckHTTPHeaderValue reports why a value cannot be sent, or nil. The error never holds the value.

func CloudName

func CloudName(prefix, key string) string

CloudName is the object name of key below prefix.

func CloudStatus

func CloudStatus(status int) error

CloudStatus is the cause of an answer with a status that the store does not map to a result of its own.

func EndedFailure

func EndedFailure(ctx context.Context) error

EndedFailure maps an error that arrived with a context that has ended: the error of the context is the cause, so that the reader tells a cancellation and a deadline from a failure of the backend.

func HTTPRedirectPolicy

func HTTPRedirectPolicy(limit int) func(*http.Request, []*http.Request) error

HTTPRedirectPolicy is the redirect policy of an [HTTPStore], for http.Client.CheckRedirect. The principle: the headers and the request never reach an origin (scheme, host, port) other than the configured one. A redirect is followed only when its target has the origin of the configured request, with one exception: the upgrade of an http request on port 80 to https on port 443 of the same host. Besides that, at most limit redirects are followed, never one back from https to http (also in a chain), and never one to an address with credentials. A path on the same origin is followed even when it leaves the base path: the server that received the headers decides its own paths. The store does not rely on the standard client for any of this: the client strips only Authorization, cookies and the like on a change of domain, and keeps every other header.

func Interrupted

func Interrupted(err error) error

Interrupted is the result of a Get whose context ended: the same shape as an S3 request that was cancelled.

func LoopbackOnly

func LoopbackOnly(_, address string, _ syscall.RawConn) error

LoopbackOnly is the Control of the dialer of a cleartext store: only a loopback address is connected to.

func NewCloudClient

func NewCloudClient(rt http.RoundTripper) *http.Client

NewCloudClient returns the client of the stores: it follows a redirect to the same host only (the policy of the http store), so a credential that a library adds to every request never leaves the host that was configured.

func NewCloudTransport

func NewCloudTransport(endpoint string) *http.Transport

NewCloudTransport returns the transport both cloud stores send their requests with. A cleartext endpoint is connected to over a loopback address only, checked for the address that is dialled (the rule of the http store), and is never sent through a proxy. An https endpoint honours the proxy variables of the environment, as the cloud libraries do: that is how a host behind a corporate proxy reaches a cloud.

func ParseBaseURL

func ParseBaseURL(raw string, allowCleartext bool) (*url.URL, error)

ParseBaseURL parses the base URL of an HTTP store and applies the rules of ValidHTTPBaseURL; it returns the URL.

func ReadBody

func ReadBody(body io.Reader, contentLength *int64, limit int64) ([]byte, error)

ReadBody reads the body within limit (see bodyread.Read). A transfer error, and a body that ends before its Content-Length, are retryable.

func RetryAfter

func RetryAfter(value string, bound time.Duration) time.Duration

RetryAfter reads a Retry-After value (seconds, or an HTTP date) as a wait, at most bound. A value that is neither is no wait.

func StatusResult

func StatusResult(status int, wait time.Duration, throttled bool) error

StatusResult maps the status of a failed answer to the results of objectstore.ObjectStore. throttled marks a 5xx that the service uses to ask for a slower rate.

func TransportFailure

func TransportFailure(err error) error

TransportFailure maps an error of the client: a refused redirect is final, the rest (network, timeout, TLS, cancellation) is retryable. The address is dropped from the cause: the error then holds no part of the request.

func ValidCloudEndpoint

func ValidCloudEndpoint(raw string) error

ValidCloudEndpoint reports why an endpoint override is not accepted, or nil: https, or http for a loopback host (an emulator); no credentials, query or fragment. The service credentials may travel to it.

func ValidCloudKey

func ValidCloudKey(key string) bool

ValidCloudKey reports whether key is a clean relative slash path (see ValidKey) of at most MaxCloudKeyBytes, with no control character (Google refuses a carriage return and a line feed in a name), no trailing dot (Azure drops it from the address of a blob) and at most 254 segments (Azure).

func ValidCloudName

func ValidCloudName(prefix, key string) bool

ValidCloudName reports whether key is a valid key whose object name below prefix still fits the limit of the services: the limits (bytes and, for Azure, 254 path segments) hold for the whole name.

func ValidCloudPrefix

func ValidCloudPrefix(prefix string) bool

ValidCloudPrefix reports whether prefix is empty or a clean relative slash path; one trailing slash is allowed.

func ValidHTTPBaseURL

func ValidHTTPBaseURL(raw string, allowCleartext bool) error

ValidHTTPBaseURL reports why the base URL is not accepted, or nil. It is the check of the constructor of the HTTP store, for the validation of a configuration file.

func ValidKey

func ValidKey(key string) bool

ValidKey reports whether key is a clean relative slash path.

func WholeObjectsOnly

func WholeObjectsOnly(next http.RoundTripper) http.RoundTripper

WholeObjectsOnly wraps next so that it refuses a request with a Range header, and a second request of a call made with WithOneRequest: a whole-object read that broke before its first byte is reopened by the Google library from offset zero with no Range header, and again after each failure with no delay, so the header alone does not bound it. It also caps the body of an answer that is no success.

func WholeSecond

func WholeSecond(when time.Time) time.Time

WholeSecond is the time as every request of S3 can give it: HeadObject and GetObject carry it in the Last-Modified header, which has no fraction, and an endpoint that lists milliseconds (MinIO) would otherwise give another time for the same object by listing than by HEAD. The date of a flag set must be the same on every replica, whichever request each used.

func WithOneRequest

func WithOneRequest(ctx context.Context) context.Context

WithOneRequest returns a context for one call of a store: the transport lets one request through for it (the redirects the client follows to the same host are part of that request).

func WithoutAddress

func WithoutAddress(err error) error

WithoutAddress drops the address from the error of a body that broke: a library that resumes a read reports the failure of the request it made, with its URL.

Types

type Secret

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

Secret is a credential of a store. Every way to print it, encode it or log it gives a marker; the content comes out of Secret.Reveal only.

func NewSecret

func NewSecret(value string) Secret

NewSecret wraps a credential.

func (Secret) Format

func (Secret) Format(f fmt.State, _ rune)

Format implements fmt.Formatter: no verb prints the content.

func (Secret) IsSet

func (s Secret) IsSet() bool

IsSet reports whether the secret is not empty.

func (Secret) LogValue

func (Secret) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (Secret) MarshalJSON

func (Secret) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Secret) MarshalYAML

func (Secret) MarshalYAML() (any, error)

MarshalYAML implements the Marshaler of gopkg.in/yaml.v3.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal returns the content.

func (Secret) String

func (Secret) String() string

String implements fmt.Stringer.

Directories

Path Synopsis
internal
bodyread
Package bodyread reads the body of an object store's answer into one buffer, within the limit of the call.
Package bodyread reads the body of an object store's answer into one buffer, within the limit of the call.

Jump to

Keyboard shortcuts

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