Documentation
¶
Overview ¶
Package engine runs CCHP operations through embedded Restish v2.
cchp owns the command tree, policy and output contract; Restish builds and sends the HTTP request from the pinned engine spec. The two meet only through Restish's supported embedding interfaces: a branded CLI with bundled config, a custom auth handler, a JSON content type that sends bodies byte for byte, a capture formatter, Restish's raw body output for downloads, and the process HTTP transport, which guards every request and records each response head.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Commands ¶
Commands lists the operation commands Restish builds from the engine spec, with any warnings it printed. cchp-gen uses it to run the whole spec through the engine and report operations it cannot build as unsupported.
func DecodeJSON ¶
DecodeJSON decodes one JSON document keeping numbers as json.Number.
func SameOrigin ¶
SameOrigin compares scheme, host and effective port.
Types ¶
type Engine ¶
type Engine struct {
// BaseURL is the bound server, for example https://hub.example.com.
BaseURL string
// Token is the management token; empty for public operations and dry runs.
Token string
// StateDir holds the materialised engine spec and Restish's private config and cache.
StateDir string
// SpecGzip is the embedded engine spec.
SpecGzip []byte
// UserAgent is sent with every request.
UserAgent string
}
Engine executes operations against one bound server.
type Event ¶
type Event struct {
Payload any
}
Event is one server-sent event as Restish decoded it.
type NotSentError ¶
type NotSentError struct{ Err error }
NotSentError reports a failure before any byte reached the server.
func (*NotSentError) Error ¶
func (e *NotSentError) Error() string
func (*NotSentError) Unwrap ¶
func (e *NotSentError) Unwrap() error
type PlannedRequest ¶
type PlannedRequest struct {
Method string `json:"method"`
URL string `json:"url"`
Header http.Header `json:"headers"`
Body []byte `json:"-"`
}
PlannedRequest is what a dry run would have sent.
type Request ¶
type Request struct {
Op *catalog.Operation
// PathArgs holds path parameter values in path template order.
PathArgs []string
// Flags holds non-path parameters as flag/value pairs; array values repeat.
Flags []Flag
// Headers are extra "Name: value" request headers managed by cchp.
Headers []string
// JSONBody is sent byte for byte as the application/json body.
JSONBody []byte
// BinaryFile is sent as the raw request body.
BinaryFile string
// FormFiles maps multipart field names to local file paths.
FormFiles map[string]string
// Retry allows Restish's automatic retry of transient failures (reads only).
Retry bool
// HeaderTimeout bounds the wait for response headers.
HeaderTimeout time.Duration
// MaxBodyMiB raises the response size limit for downloads.
MaxBodyMiB int
// MaxEvents stops a stream after this many events.
MaxEvents int
// OnEvent receives stream events; returning an error stops the stream.
OnEvent func(Event) error
// RawBody returns the response body byte for byte whatever its Content-Type,
// server-sent events and NDJSON included; downloads use it.
RawBody bool
// DryRun builds the request without sending it.
DryRun bool
}
Request is one operation call.
type UnknownOutcomeError ¶
type UnknownOutcomeError struct{ Err error }
UnknownOutcomeError reports a failure after the request may have reached the server.
func (*UnknownOutcomeError) Error ¶
func (e *UnknownOutcomeError) Error() string
func (*UnknownOutcomeError) Unwrap ¶
func (e *UnknownOutcomeError) Unwrap() error