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 CheckNextToken(requested, next string) error
- func CloudListPrefix(connPrefix, prefix string) string
- 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 PageSize32(limit int) int32
- func ParseBaseURL(raw string, allowCleartext bool) (*url.URL, error)
- func ReadBody(body io.Reader, contentLength *int64, limit int64) ([]byte, error)
- func RelativeName(connPrefix, name string) (string, bool)
- func RetryAfter(value string, bound time.Duration) time.Duration
- func RetryAfterAt(value string, bound time.Duration, now time.Time) 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 ValidDynamoTable(name string) bool
- func ValidHTTPBaseURL(raw string, allowCleartext bool) error
- func ValidKey(key string) bool
- func ValidKubeName(name string) bool
- func ValidKubeNamespace(name string) bool
- func ValidListPrefix(connPrefix, prefix string) bool
- func ValidMongoCollection(database, name string) bool
- func ValidMongoDatabase(name string) bool
- func ValidPostgresIdentifier(name string) bool
- func ValidProjectSlug(slug string) bool
- func ValidRepositorySlug(slug 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 PostgresKey
- 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 ( // MinDynamoTable is the shortest table name DynamoDB accepts, in bytes. MinDynamoTable = 3 // MaxDynamoTable is the longest table name DynamoDB accepts, in bytes. MaxDynamoTable = 255 )
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.
const ( // MaxKubeLabel is the longest namespace name (a DNS-1123 label). MaxKubeLabel = 63 // MaxKubeName is the longest ConfigMap name (a DNS-1123 subdomain). MaxKubeName = 253 )
const ( // MaxMongoDatabase is the longest database name MongoDB accepts, in bytes. MaxMongoDatabase = 63 // MaxMongoNamespace is the longest namespace (database, a dot and collection) MongoDB accepts, in bytes. MaxMongoNamespace = 255 )
const MaxPostgresIdentifier = 63
MaxPostgresIdentifier is the longest name PostgreSQL keeps (NAMEDATALEN - 1), in bytes.
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.
var ErrListLoop = errors.New("objectstore: the listing repeats a continuation token")
ErrListLoop is the cause of a listing whose continuation token repeats.
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 CheckNextToken ¶ added in v1.5.0
CheckNextToken checks the token that a page gives for the next one. A listing that has no token for more pages, or repeats the token of its request, never ends: it is a failure of the store, not a long listing.
func CloudListPrefix ¶ added in v1.5.0
CloudListPrefix is the name prefix of a listing of prefix below the prefix of the connection. With no prefix of the connection it is prefix itself; with one, the slash after it is part of the prefix, so a sibling that only starts with the same letters is never listed.
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 PageSize32 ¶ added in v1.5.0
PageSize32 is the number of entries of a page as the 32 bit field of a service request takes it, from the limit of the request (see objectstore.PageSize).
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 RelativeName ¶ added in v1.5.0
RelativeName is the key of an object below the prefix of the connection, the one a Get takes, and false for an object that a Get could not read: a name outside the prefix, or one that is no valid key (a placeholder of a folder, a name with a control character).
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 RetryAfterAt ¶ added in v1.5.0
RetryAfterAt is RetryAfter for a given current time, which only the HTTP date form reads.
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 ValidDynamoTable ¶ added in v1.5.0
ValidDynamoTable reports whether name is a DynamoDB table name: 3 to 255 bytes of ASCII letters, digits, underscore, hyphen and dot.
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 ValidKubeName ¶ added in v1.5.0
ValidKubeName reports whether name is the name of a ConfigMap: a DNS-1123 subdomain, labels of lowercase letters, digits and hyphens joined by dots, at most MaxKubeName bytes.
func ValidKubeNamespace ¶ added in v1.5.0
ValidKubeNamespace reports whether name is a Kubernetes namespace name: a DNS-1123 label, lowercase letters, digits and hyphens, starting and ending with a letter or a digit, at most MaxKubeLabel bytes.
func ValidListPrefix ¶ added in v1.5.0
ValidListPrefix reports whether the prefix of a listing, relative to the connection, can name objects of a cloud store: it is no absolute path, has no control character or backslash, and with the prefix of the connection fits the limit of the services. It may end in a slash, or in part of a name.
func ValidMongoCollection ¶ added in v1.5.0
ValidMongoCollection reports whether name is a collection of the database that a flag source may read: not empty, no $, slash, backslash or control character, not in the system. namespace, and with the database name within MaxMongoNamespace bytes.
func ValidMongoDatabase ¶ added in v1.5.0
ValidMongoDatabase reports whether name is a MongoDB database name: not empty, at most MaxMongoDatabase bytes, none of the characters / \ . space " $ * < > : | ? and no control character.
func ValidPostgresIdentifier ¶ added in v1.5.0
ValidPostgresIdentifier reports whether name may be used as a schema, table or column name of a flag source: any name that PostgreSQL accepts as a quoted identifier, as GO Feature Flag does: not empty, valid UTF-8, no NUL, at most MaxPostgresIdentifier bytes (PostgreSQL cuts a longer name without a word, so it would name another table). It is no protection against injection: the store quotes every name as an identifier, which doubles a quote and nothing in a quoted name ends it.
func ValidProjectSlug ¶ added in v1.5.0
ValidProjectSlug reports whether slug is the path of a GitLab project: group/project or group/subgroup/project, two or more non-empty parts, none of them "." or "..". A single all-digit segment is a numeric project ID, which GitLab documents for the same place.
func ValidRepositorySlug ¶ added in v1.5.0
ValidRepositorySlug reports whether slug is owner/repo: two non-empty parts, none of them "." or "..". It is the one rule of the bootstrap validation and of the GitHub store, so that a refusal does not depend on where it is made.
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 PostgresKey ¶ added in v1.5.0
type PostgresKey struct {
// Schema is the schema of the table; empty for the search path of the connection.
Schema string
// Table is the table that holds the flags, one row for each flag.
Table string
// Flagset selects the rows of one flag set of the table; empty for every row.
Flagset string
}
PostgresKey is the flag set that a key of a postgresql connection names.
func ParsePostgresKey ¶ added in v1.5.0
func ParsePostgresKey(key string) (PostgresKey, bool)
ParsePostgresKey reads the key of a flag set of a postgresql connection: <table>.json, <schema>.<table>.json, and with the flag set column <table>/<flagset>.json or <schema>.<table>/<flagset>.json. The names are checked with ValidPostgresIdentifier and have no dot and no slash: a table or schema whose name has one cannot be written in a key. The flag set is a value (a bind parameter), so only a control character or invalid UTF-8 refuses it. It reports false for any other key.
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.