Documentation
¶
Overview ¶
Package version holds what every versioned resource of API v6 shares: the build states, how a wait reads them, the error a failed build turns into and the four operations each versioned client exposes.
In v6 a save produces an immutable Draft, and nothing reaches traffic until a build takes that Draft through queued and building to ready. A step that writes configuration therefore does not finish when the API answers; it finishes when the build it started settles. This package is the vocabulary those steps share, so the seven versioned resources do not each redefine it.
Index ¶
- Variables
- func BuildDone(s State) (bool, error)
- func ErrorFor(errBody string, httpResp *http.Response, err error) error
- func NewStatusError(resp *http.Response, shown error) error
- func Retryable(err error) (bool, time.Duration)
- type BuildError
- type Item
- type Meta
- type Object
- type State
- type StatusError
- type Versioned
Constants ¶
This section is empty.
Variables ¶
var ErrBuildFailed = errors.New("build did not produce a usable version")
ErrBuildFailed is what BuildDone wraps when a build settles without a usable version.
var ErrConflict = errors.New("the API refused the change")
ErrConflict is a 409 that is not a name in use.
Functions ¶
func BuildDone ¶
BuildDone is the done function for waiting on a build that this run started. It reports true once the build has settled, with ErrBuildFailed when it settled without a usable version.
Draft does not end the wait even though it is settled: right after the build request the API may still report the version as draft until the build is queued, and if it never leaves draft the wait's timeout says so.
func ErrorFor ¶
ErrorFor is the error a v6 client returns for a failed call: the v4 handling (utils.ErrorPerStatusCodeV4), except for a 409. v4 reads every 409 as a name already in use, which is what its create retries rely on, but in v6 a 409 also means a state conflict (a release whose resources can no longer change, say). So a 409 is a name in use only when the API's message says so; otherwise the error is the API's message.
errBody is what utils.LogAndRewindBodyV4 returns, a summary of the body, not the body itself; the API's JSON is read from httpResp, which that call rewinds.
func NewStatusError ¶
NewStatusError wraps shown with the status and Retry-After of resp. Without a response (the request never got one) it returns shown unchanged. It never returns nil: a call that failed stays failed even when nothing explains it, so its caller never goes on with an empty result.
func Retryable ¶
Retryable is the retry rule for waits on the v6 API, in the shape poll.Options.Retryable takes. It reads the errors the clients already return (utils.ErrorPerStatusCodeV4), plus the status the polled reads attach with NewStatusError:
- 429 is retried after Retry-After, or on the next poll when it is absent;
- 5xx, a timeout and a request that got no response are retried on the next poll (ErrorPerStatusCodeV4 maps all of them to ErrorInternalServerError or ErrorTimeoutAPICall);
- any other error ends the wait.
Types ¶
type BuildError ¶
type BuildError struct {
Kind string // "application", "connector", ...
Name string
ID int64
VersionID string
// State is the last state seen: the failed one, or the one the build was
// stuck in when the wait gave up.
State State
TraceID string // when the API returns one
Err error
}
BuildError is one build that did not reach ready. A step that waits on several builds joins one BuildError per failure with errors.Join, so the user sees everything that went wrong at once.
func (*BuildError) Error ¶
func (e *BuildError) Error() string
func (*BuildError) Unwrap ¶
func (e *BuildError) Unwrap() error
type Item ¶
Item is a sub-resource inside a version (a rule, a cache setting, a function instance, a WAF exception) as the v6 clients return it.
type Meta ¶
Meta is one version of a resource as the version endpoints return it. Since SDK 0.3.0 those return their own model (ApplicationVersion and so on), which carries the version's id and state but not the resource's id.
type Object ¶
type Object interface {
GetId() int64
GetName() string
GetVersionId() string
GetVersionState() string
}
Object is a versioned resource as the v6 clients return it, in the way the v4 clients return a small response interface. Every SDK model of a versioned resource has these getters.
type State ¶
type State string
State is the build state the v6 API reports as version_state (resources) or state (releases).
func (State) Bindable ¶
Bindable reports whether a Workload binding accepts an Environment or a Deployment in this state: the API takes only queued, building or ready. The API is not consistent about case (draft, DRAFT), so neither is this.
func (State) Failed ¶
Failed reports whether a settled state means the build did not produce a usable version. Draft is settled but not failed: nothing was built yet.
type StatusError ¶
type StatusError struct {
StatusCode int
// RetryAfter is the delay the API asked for with Retry-After, or zero.
RetryAfter time.Duration
Err error
}
StatusError carries the HTTP status of a failed v6 call next to the error the CLI already shows for it, so a wait can tell a call worth repeating from one that never will succeed. Unwrap returns the shown error, so errors.Is against the utils sentinels keeps working.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) Unwrap ¶
func (e *StatusError) Unwrap() error
type Versioned ¶
type Versioned interface {
// CreateVersion opens a new Draft. An empty from clones the latest ready
// version, which is the API's default. It returns the new version id.
CreateVersion(ctx context.Context, id int64, from, comment string) (string, error)
// Build queues the build of a Draft. It returns as soon as the API accepts
// the request; VersionState tells when the build settles.
Build(ctx context.Context, id int64, versionID, comment string) error
// CancelBuild asks the API to stop a build that has not settled yet.
CancelBuild(ctx context.Context, id int64, versionID string) error
// VersionState reads the build state of one version.
VersionState(ctx context.Context, id int64, versionID string) (State, error)
}
Versioned is the contract the seven resources with a build share (applications, connectors, custom pages, firewalls, functions, network lists and WAFs). It only describes what their clients in pkg/api/v6 already do, so the build steps drive any of them without repeating the code per resource.