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
- Variables
- func CheckCloudSetting(name, prefix, endpoint string, timeout time.Duration) error
- func CheckHTTPHeaderName(name string) error
- func CheckHTTPHeaderValue(value string) error
- func CloudName(prefix, key string) string
- func CloudStatus(status int) error
- func EndedFailure(ctx context.Context) error
- func HTTPRedirectPolicy(limit int) func(*http.Request, []*http.Request) error
- func Interrupted(err error) error
- func LoopbackOnly(_, address string, _ syscall.RawConn) error
- func NewCloudClient(rt http.RoundTripper) *http.Client
- func NewCloudTransport(endpoint string) *http.Transport
- func ParseBaseURL(raw string, allowCleartext bool) (*url.URL, error)
- func ReadBody(body io.Reader, contentLength *int64, limit int64) ([]byte, error)
- func RetryAfter(value string, bound time.Duration) time.Duration
- func StatusResult(status int, wait time.Duration, throttled bool) error
- func TransportFailure(err error) error
- func ValidCloudEndpoint(raw string) error
- func ValidCloudKey(key string) bool
- func ValidCloudName(prefix, key string) bool
- func ValidCloudPrefix(prefix string) bool
- func ValidHTTPBaseURL(raw string, allowCleartext bool) error
- func ValidKey(key string) bool
- func WholeObjectsOnly(next http.RoundTripper) http.RoundTripper
- func WholeSecond(when time.Time) time.Time
- func WithOneRequest(ctx context.Context) context.Context
- func WithoutAddress(err error) error
- type Secret
Constants ¶
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 )
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 ¶
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.
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.
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 ¶
CheckCloudSetting is the validation the two constructors share.
func CheckHTTPHeaderName ¶
CheckHTTPHeaderName reports why a header name cannot be configured, or nil.
func CheckHTTPHeaderValue ¶
CheckHTTPHeaderValue reports why a value cannot be sent, or nil. The error never holds the value.
func CloudStatus ¶
CloudStatus is the cause of an answer with a status that the store does not map to a result of its own.
func EndedFailure ¶
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 ¶
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 ¶
Interrupted is the result of a Get whose context ended: the same shape as an S3 request that was cancelled.
func LoopbackOnly ¶
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 ¶
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 ¶
ParseBaseURL parses the base URL of an HTTP store and applies the rules of ValidHTTPBaseURL; it returns the URL.
func ReadBody ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ValidCloudPrefix reports whether prefix is empty or a clean relative slash path; one trailing slash is allowed.
func ValidHTTPBaseURL ¶
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 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 ¶
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 ¶
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 ¶
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 (Secret) Format ¶
Format implements fmt.Formatter: no verb prints the content.
func (Secret) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Secret) MarshalYAML ¶
MarshalYAML implements the Marshaler of gopkg.in/yaml.v3.