Documentation
¶
Index ¶
- Constants
- func ApplyChanges(req *domain.Request, ch *RequestChanges)
- func EnvText(v any) string
- func WithQuery(rawURL string, pairs []Pair) string
- type Cookie
- type DockerClient
- type ExecParams
- type ExecResult
- type Executor
- type GraphQLChanges
- type GraphQLData
- type Pair
- type Phase
- type Protocol
- type PythonExecutor
- type RequestChanges
- type RequestData
- type ResponseData
- type ScriptError
- type TestResult
Constants ¶
const ( PythonContainerName = "chapar-python-executor" PythonExecutorName = "Python" // ScriptTimeout is how long one script may run before the executor // kills it. ScriptTimeout = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func ApplyChanges ¶ added in v0.7.0
func ApplyChanges(req *domain.Request, ch *RequestChanges)
ApplyChanges writes what a pre-request script changed into req, which must be the per-send copy: the saved request is never changed. Headers, metadata and path params the script returns replace the enabled ones.
Types ¶
type DockerClient ¶
type DockerClient struct {
// contains filtered or unexported fields
}
DockerClient wraps the Docker SDK client
func NewDockerClient ¶
func NewDockerClient() (*DockerClient, error)
NewDockerClient creates a new Docker client
type ExecParams ¶
type ExecParams struct {
Phase Phase
Protocol Protocol
Req *RequestData
// Res is nil in pre-request scripts.
Res *ResponseData
Env *domain.Environment
}
type ExecResult ¶
type ExecResult struct {
// Request is what a pre-request script changed; nil after post-request.
Request *RequestChanges `json:"request"`
EnvSet map[string]any `json:"env_set"`
EnvUnset []string `json:"env_unset"`
Prints []string `json:"prints"`
Tests []TestResult `json:"tests"`
// Skip is set when a pre-request script called chapar.skip().
Skip bool `json:"skip"`
SkipReason string `json:"skip_reason"`
Error *ScriptError `json:"error"`
}
func (*ExecResult) ApplyEnv ¶ added in v0.7.0
func (r *ExecResult) ApplyEnv(env *domain.Environment) bool
ApplyEnv writes the script's environment changes into env and reports whether anything changed. Values that are not text are stored as JSON.
func (*ExecResult) FailedTests ¶ added in v0.7.0
func (r *ExecResult) FailedTests() int
FailedTests counts the tests that did not pass.
func (*ExecResult) Summary ¶ added in v0.7.0
func (r *ExecResult) Summary() string
Summary describes the prints and tests of a run, one per line, for the request timeline.
type Executor ¶
type Executor interface {
Init(cfg domain.ScriptingConfig) error
Execute(ctx context.Context, script string, params *ExecParams) (*ExecResult, error)
Name() string
Shutdown() error
}
func GetExecutor ¶
func GetExecutor(language string, cfg domain.ScriptingConfig) (Executor, error)
type GraphQLChanges ¶ added in v0.7.0
type GraphQLData ¶ added in v0.7.0
type Pair ¶ added in v0.7.0
type Pair [2]string
Pair is one header, metadata entry or query param. It travels as a two-element JSON array, so repeated keys and their order survive.
func ParseQuery ¶ added in v0.7.0
ParseQuery returns the query params of rawURL, unescaped. It works on URLs that still hold {{variables}}, which url.Parse may reject.
type Protocol ¶ added in v0.7.0
type Protocol string
Protocol is the kind of request a script runs for.
func ProtocolOf ¶ added in v0.7.0
func ProtocolOf(t domain.RequestType) Protocol
ProtocolOf maps a request type to the protocol scripts see.
type PythonExecutor ¶
type PythonExecutor struct {
// contains filtered or unexported fields
}
func NewPythonExecutor ¶
func NewPythonExecutor(cfg domain.ScriptingConfig) *PythonExecutor
func (*PythonExecutor) Execute ¶
func (p *PythonExecutor) Execute(ctx context.Context, script string, params *ExecParams) (*ExecResult, error)
func (*PythonExecutor) Init ¶
func (p *PythonExecutor) Init(cfg domain.ScriptingConfig) error
func (*PythonExecutor) Name ¶
func (p *PythonExecutor) Name() string
func (*PythonExecutor) Shutdown ¶
func (p *PythonExecutor) Shutdown() error
type RequestChanges ¶ added in v0.7.0
type RequestChanges struct {
URL *string `json:"url,omitempty"`
Method *string `json:"method,omitempty"`
Headers *[]Pair `json:"headers,omitempty"`
Body *string `json:"body,omitempty"`
Query *[]Pair `json:"query,omitempty"`
PathParams *map[string]string `json:"path_params,omitempty"`
GraphQL *GraphQLChanges `json:"graphql,omitempty"`
}
RequestChanges is what a pre-request script changed. Nil fields were left alone.
func (*RequestChanges) Empty ¶ added in v0.7.0
func (c *RequestChanges) Empty() bool
Empty reports whether the script changed nothing.
type RequestData ¶
type RequestData struct {
URL string `json:"url"`
Method string `json:"method"`
Headers []Pair `json:"headers"`
Body string `json:"body"`
Query []Pair `json:"query,omitempty"`
PathParams map[string]string `json:"path_params,omitempty"`
GraphQL *GraphQLData `json:"graphql,omitempty"`
Resolved *RequestData `json:"resolved,omitempty"`
}
RequestData is the request a script sees. Fields keep their {{variables}}; Resolved holds the same request with them filled in.
For gRPC, URL is the server address, Method the full method name and Headers the metadata. For GraphQL the document and variables are in GraphQL and Body is empty.
func RequestDataFromDomain ¶
func RequestDataFromDomain(req *domain.Request, env *domain.Environment, collection *domain.Collection) *RequestData
RequestDataFromDomain builds what a script sees of req: its fields as saved, with collection headers merged in, and a resolved copy with env and dynamic variables filled in. It changes neither req nor env.
type ResponseData ¶
type ResponseData struct {
StatusCode int `json:"status_code"`
Status string `json:"status"`
Headers []Pair `json:"headers"`
Body string `json:"body"`
ElapsedMS float64 `json:"elapsed_ms"`
Size int `json:"size"`
Error string `json:"error,omitempty"`
Cookies []Cookie `json:"cookies,omitempty"`
Metadata []Pair `json:"metadata,omitempty"`
Trailers []Pair `json:"trailers,omitempty"`
}
ResponseData is the response a post-request script sees. For gRPC, StatusCode is the gRPC code and Metadata/Trailers what the server sent.
type ScriptError ¶ added in v0.7.0
type ScriptError struct {
Type string `json:"type"`
Message string `json:"message"`
Line int `json:"line,omitempty"`
Traceback string `json:"traceback,omitempty"`
}
ScriptError is an exception the script raised, or a failure to run it (a timeout, a crash).
func (*ScriptError) Error ¶ added in v0.7.0
func (e *ScriptError) Error() string
type TestResult ¶ added in v0.7.0
type TestResult struct {
Name string `json:"name"`
Passed bool `json:"passed"`
Error string `json:"error,omitempty"`
}
TestResult is one chapar.test() a script ran.