Documentation
¶
Overview ¶
Package runner executes parsed requests: it resolves variables, sends the request, evaluates captures and assertions, and persists captured values to the session.
Index ¶
- Constants
- Variables
- func ExitCode(err error) int
- func RedactExpr(expr string) string
- type Description
- type Options
- type Resolved
- type Response
- type Result
- type Runner
- func (r *Runner) AuthSource(req *httpfile.Request) (raw, source string)
- func (r *Runner) Capture(name, value string)
- func (r *Runner) Captured() map[string]string
- func (r *Runner) Describe(req *httpfile.Request) *Description
- func (r *Runner) EnvVars() []VarInfo
- func (r *Runner) MissingError(req *httpfile.Request, missing []string) error
- func (r *Runner) Render(s string) (string, error)
- func (r *Runner) Resolve(req *httpfile.Request) (*Resolved, error)
- func (r *Runner) Results() map[string]*Result
- func (r *Runner) Run(ctx context.Context, req *httpfile.Request) (*Result, error)
- func (r *Runner) RunAll(ctx context.Context, reqs []*httpfile.Request) ([]*Result, error)
- func (r *Runner) SetResult(name string, res *Result)
- func (r *Runner) SetVar(name, value string)
- type TransportError
- type UsageError
- type VarInfo
Constants ¶
const ( ExitOK = 0 ExitAssert = 1 // an assertion or capture failed ExitUsage = 2 // parse error, unknown request, missing variable ExitTransport = 3 // could not reach the server, timeout, TLS failure )
Exit codes returned by the CLI.
const Masked = "***"
Masked is what a hidden value is replaced with in output.
Variables ¶
var Version = "dev"
Version is stamped by the CLI for the User-Agent header.
Functions ¶
func ExitCode ¶
ExitCode maps an error to the CLI exit code.
The exit codes are a public contract, so this unwraps rather than switching on the concrete type: wrapping a TransportError with %w anywhere on the way up would otherwise turn a documented 3 into a 2.
func RedactExpr ¶
RedactExpr keeps the selector and operator of an assertion expression and hides the expected value.
Types ¶
type Description ¶
type Description struct {
Name string `json:"name,omitempty"`
ID string `json:"id"`
File string `json:"file"`
Line int `json:"line"`
Description string `json:"description,omitempty"`
Method string `json:"method"`
URLTemplate string `json:"url_template"`
URL string `json:"url"` // resolved as far as possible
Headers map[string]string `json:"headers"`
Body string `json:"body,omitempty"`
BodyFile string `json:"body_file,omitempty"`
Variables []VarInfo `json:"variables"`
Captures []string `json:"captures,omitempty"`
Asserts []string `json:"asserts,omitempty"`
Steps []string `json:"steps,omitempty"` // # @step phrases
Auth string `json:"auth,omitempty"` // auth spec template
AuthSource string `json:"auth_source,omitempty"` // "request" or "apic.yaml"
Ready bool `json:"ready"` // every variable resolves
}
Description is what `apic describe` shows.
type Options ¶
type Options struct {
Env string // environment name from http-client.env.json
Vars map[string]string // --var overrides
NoSession bool // do not read or write .apic/session.json
Timeout time.Duration // default per-request timeout
Insecure bool // skip TLS verification
KeepGoing bool // in a flow, continue after a failure
Redact bool // mask every request value and capture in output (for CI logs)
Session *session.Store // use this store instead of opening .apic/session.json (tests use session.NewMemory())
}
Options controls a Runner.
type Resolved ¶
type Resolved struct {
Name string `json:"name,omitempty"`
File string `json:"file"`
Line int `json:"line"`
Method string `json:"method"`
URL string `json:"url"`
Headers []httpfile.Header `json:"-"`
Body string `json:"-"`
Auth string `json:"auth,omitempty"` // auth type applied, e.g. "aws"
AuthSpec *auth.Spec `json:"-"` // rendered spec (contains secrets)
// SecretHeaders names headers whose value came from a secret source
// (private env file, .env, session or a capture).
SecretHeaders map[string]bool `json:"-"`
// contains filtered or unexported fields
}
Resolved is a request with every placeholder substituted.
func (Resolved) DisplayBody ¶
DisplayBody returns the body, or the mask when redacting.
func (Resolved) DisplayHeaders ¶
DisplayHeaders returns the request headers with sensitive values masked; with redact set every value is masked.
func (Resolved) DisplayURL ¶
DisplayURL returns the URL with query values masked when redacting.
func (Resolved) MarshalJSON ¶
MarshalJSON renders headers as an object (sensitive values masked) and the body as a string. Result.MarshalJSON applies --redact on top.
type Response ¶
type Response struct {
Status int `json:"status"`
StatusText string `json:"status_text"`
Headers map[string]string `json:"headers"`
Body any `json:"body"` // parsed JSON when the body is JSON, else a string
DurationMs int64 `json:"duration_ms"`
Size int `json:"size"`
}
Response is the JSON-friendly view of a response.
type Result ¶
type Result struct {
OK bool `json:"ok"`
Request Resolved `json:"request"`
Response *Response `json:"response,omitempty"`
Captures map[string]string `json:"captures,omitempty"`
Asserts []assert.Result `json:"asserts,omitempty"`
Errors []string `json:"errors,omitempty"`
Redact bool `json:"-"` // set from Options.Redact
// contains filtered or unexported fields
}
Result is the outcome of running one request.
func (Result) DisplayAsserts ¶
DisplayAsserts returns the assertion results with the values they carry masked when redacting. An assertion like "# @assert body.$.token == {{token}}" bakes the rendered secret into Expr, Expected and Actual, so all three are hidden; Pass and Error are structural and survive.
func (Result) DisplayCaptures ¶
DisplayCaptures returns captures, masked when redacting.
func (*Result) DisplayRawBody ¶
DisplayRawBody returns the raw response body for renderers, masked when redacting.
func (Result) DisplayResponse ¶
DisplayResponse returns the response as it should be shown: status, timing and size survive because they are not secrets and CI needs them, while the body and header values are masked when redacting.
func (Result) MarshalJSON ¶
MarshalJSON masks sensitive request and response headers always, and everything (headers, bodies, query values, captures and assertion values) when Redact is set.
The shadowing fields sit at a shallower depth than the embedded alias, so encoding/json picks them over the originals.
type Runner ¶
type Runner struct {
Project *project.Project
Envs *env.Environments
Session *session.Store
Opts Options
Stderr io.Writer // interactive prompts such as device-code sign-in; nil means os.Stderr
// contains filtered or unexported fields
}
Runner executes requests for one project.
func (*Runner) AuthSource ¶
AuthSource reports the auth spec template for describe: the raw text and where it was declared.
func (*Runner) Capture ¶
Capture stores a value in the capture layer, below --var and shell overrides and above the environment files, exactly like `# @capture`.
func (*Runner) Describe ¶
func (r *Runner) Describe(req *httpfile.Request) *Description
Describe reports a request's variables and where each comes from.
func (*Runner) EnvVars ¶
EnvVar lists the effective variables for the current environment, for `apic env`.
func (*Runner) MissingError ¶
MissingError explains unresolved variables with a hint on how to provide them.
func (*Runner) Render ¶
Render substitutes {{placeholders}} in arbitrary text using the runner's variables (no file-level @vars, since no request is in scope).
func (*Runner) Results ¶
Results returns the named responses of this run, for `{{name.response...}}` references.
func (*Runner) Run ¶
Run resolves, sends and evaluates a single request. A non-nil error is a usage or transport problem; assertion failures are reported in Result.OK.
func (*Runner) RunAll ¶
RunAll runs requests in order as a flow, stopping at the first failure unless KeepGoing is set. Results for requests that ran are always returned.
type TransportError ¶
type TransportError struct{ Err error }
TransportError is a network-level failure.
func (*TransportError) Error ¶
func (e *TransportError) Error() string
func (*TransportError) Unwrap ¶
func (e *TransportError) Unwrap() error
type UsageError ¶
type UsageError struct{ Msg string }
UsageError is a problem with the request definition or invocation.
func (*UsageError) Error ¶
func (e *UsageError) Error() string
type VarInfo ¶
type VarInfo struct {
Name string `json:"name"`
Value string `json:"value,omitempty"`
Source string `json:"source"`
Secret bool `json:"secret,omitempty"`
Missing bool `json:"missing,omitempty"`
CapturedBy string `json:"captured_by,omitempty"` // request that would provide it
}
VarInfo describes where a variable's value came from.