Documentation
¶
Overview ¶
Package javascript evaluates Spectre payload normaliser scripts.
Index ¶
- func ModuleDeclaration() string
- func WriteModuleDeclaration(output string) error
- type Action
- type ActionIgnore
- type ActionMatch
- type Endpoint
- type Evaluator
- func (e *Evaluator) Close()
- func (e *Evaluator) NormaliseField(target FieldTarget, value Option[any]) (Option[any], error)
- func (e *Evaluator) NormaliseMessage(target schema.TypeRef, value Option[any]) (Option[any], error)
- func (e *Evaluator) NormaliseResponse(rule Rule, response any) (Option[any], error)
- func (e *Evaluator) SelectsRequest(rule Rule, request Request) (bool, error)
- func (e *Evaluator) SelectsRequestHeader(rule Rule, name string, value Option[string]) (bool, error)
- func (e *Evaluator) SelectsResponseHeader(rule Rule, name string, value Option[string]) (bool, error)
- func (e *Evaluator) SelectsStatus(rule Rule, status int) (bool, error)
- type FieldTarget
- type HeaderScript
- type HeaderSelector
- type HeaderValue
- type Program
- type Request
- type RequestPattern
- type RequestScript
- type RequestSelector
- type Response
- type Rule
- func (r Rule) Action() Action
- func (r Rule) Index() int
- func (r Rule) Protocol() model.Protocol
- func (r Rule) Request() RequestSelector
- func (r Rule) RequestHeaders() []HeaderSelector
- func (r Rule) ResponseHeaders() []HeaderSelector
- func (r Rule) SelectsEveryResponse() bool
- func (r Rule) SelectsRequestHeaders(header http.Header) bool
- func (r Rule) Status() StatusSelector
- func (r Rule) String() string
- type StatusAny
- type StatusCodes
- type StatusScript
- type StatusSelector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModuleDeclaration ¶ added in v0.19.0
func ModuleDeclaration() string
ModuleDeclaration returns the TypeScript declaration of the spectre module.
func WriteModuleDeclaration ¶ added in v0.19.0
WriteModuleDeclaration writes the module declaration to output, creating its parent directory.
Types ¶
type Action ¶ added in v0.43.0
type Action interface {
// contains filtered or unexported methods
}
Action is what happens to the responses a rule selects.
type ActionIgnore ¶ added in v0.43.0
type ActionIgnore struct{}
ActionIgnore skips comparison, so the responses never quarantine.
type ActionMatch ¶ added in v0.43.0
ActionMatch decodes bodies as Type, or as text when Type is None, then compares them after the rule's normaliser, if it has one.
type Endpoint ¶ added in v0.12.0
type Endpoint struct {
// contains filtered or unexported fields
}
Endpoint maps a protocol-specific request pattern to a payload type.
func (Endpoint) Pattern ¶ added in v0.12.0
Pattern returns the protocol-specific pattern the endpoint matches.
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator owns the JavaScript runtime for one payload normalisation. It is confined to its caller because Sobek runtime access is not synchronized.
func (*Evaluator) Close ¶
func (e *Evaluator) Close()
Close releases the evaluator's context watcher.
func (*Evaluator) NormaliseField ¶ added in v0.11.0
func (e *Evaluator) NormaliseField(target FieldTarget, value Option[any]) (Option[any], error)
NormaliseField invokes the normaliser registered for a JSON field path. None stands for an absent field in both the argument and the result.
func (*Evaluator) NormaliseMessage ¶ added in v0.11.0
NormaliseMessage invokes the normaliser registered for an object type. None stands for an absent message in both the argument and the result.
func (*Evaluator) NormaliseResponse ¶ added in v0.43.0
NormaliseResponse invokes a rule's response normaliser on a JSON response object. None stands for an undefined result.
func (*Evaluator) SelectsRequest ¶ added in v0.43.0
SelectsRequest reports whether a rule's request function accepts a request.
func (*Evaluator) SelectsRequestHeader ¶ added in v0.44.0
func (e *Evaluator) SelectsRequestHeader(rule Rule, name string, value Option[string]) (bool, error)
SelectsRequestHeader reports whether a rule's function for a request header accepts its value, which is undefined when the request lacks the header.
func (*Evaluator) SelectsResponseHeader ¶ added in v0.44.0
func (e *Evaluator) SelectsResponseHeader(rule Rule, name string, value Option[string]) (bool, error)
SelectsResponseHeader reports whether a rule's function for a response header accepts its value, which is undefined when the response lacks the header.
type FieldTarget ¶ added in v0.19.0
type FieldTarget struct {
// contains filtered or unexported fields
}
FieldTarget identifies a JSON field path relative to an explicitly named type. The two components remain separate because namespace names can overlap field paths.
func NewFieldTarget ¶ added in v0.19.0
func NewFieldTarget(typeName schema.TypeRef, path string) FieldTarget
NewFieldTarget creates a target without resolving it against a schema.
func (FieldTarget) Path ¶ added in v0.19.0
func (t FieldTarget) Path() string
Path returns the JSON field path relative to the root type.
func (FieldTarget) String ¶ added in v0.19.0
func (t FieldTarget) String() string
String returns a human-readable target name, not a unique identity.
func (FieldTarget) Type ¶ added in v0.19.0
func (t FieldTarget) Type() schema.TypeRef
Type returns the fully qualified name of the target's root object type.
type HeaderScript ¶ added in v0.44.0
type HeaderScript struct{ Name string }
HeaderScript selects the messages whose header a script function accepts.
type HeaderSelector ¶ added in v0.44.0
type HeaderSelector interface {
// contains filtered or unexported methods
}
HeaderSelector selects the requests or responses a rule applies to by one header.
type HeaderValue ¶ added in v0.44.0
type HeaderValue struct{ Name, Value string }
HeaderValue selects messages whose header, with its values joined by ", ", equals Value. It never selects a message without the header.
func (HeaderValue) Selects ¶ added in v0.44.0
func (h HeaderValue) Selects(value Option[string]) bool
Selects reports whether a header's joined value equals Value.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is one immutable set of scripts, shared by all payload normalisations. It retains no runtime-local callback state.
func NewProgram ¶
func NewProgram(ctx context.Context, evaluationTimeout time.Duration, declarations fs.FS, scripts fs.FS) (*Program, error)
NewProgram type-checks every TypeScript script against the schema declarations, links them, then evaluates them once within evaluationTimeout to collect their registrations.
func (*Program) Endpoints ¶ added in v0.12.0
Endpoints returns the endpoints declared for a direction, in declaration order.
func (*Program) Fields ¶
func (p *Program) Fields() []FieldTarget
Fields returns the declared type names and JSON field paths, sorted by type then path.
func (*Program) NewEvaluator ¶
NewEvaluator creates an isolated evaluator for one payload normalisation. Re-evaluation must reproduce the registrations used to build the schema plan.
type Request ¶ added in v0.43.0
type Request struct {
Method string
// Path is escaped and excludes the query.
Path string
Header http.Header
}
Request is an inbound HTTP request as a rule's selectors see it.
func (Request) HeaderValue ¶ added in v0.44.0
HeaderValue returns a header's values joined by ", ", or None without any.
type RequestPattern ¶ added in v0.43.0
type RequestPattern struct{ Pattern string }
RequestPattern selects requests matching a ServeMux pattern.
type RequestScript ¶ added in v0.43.0
type RequestScript struct{}
RequestScript selects the requests a script function accepts.
type RequestSelector ¶ added in v0.43.0
type RequestSelector interface {
// contains filtered or unexported methods
}
RequestSelector selects the requests a rule applies to.
type Response ¶ added in v0.44.0
Response is an HTTP response as a rule's selectors see it.
func (Response) HeaderValue ¶ added in v0.44.0
HeaderValue returns a header's values joined by ", ", or None without any.
type Rule ¶ added in v0.43.0
type Rule struct {
// contains filtered or unexported fields
}
Rule decides how ingress compares the responses it selects. Rules apply in declaration order, and the first that selects a response decides.
func (Rule) Action ¶ added in v0.43.0
Action returns what happens to the responses the rule selects.
func (Rule) Request ¶ added in v0.43.0
func (r Rule) Request() RequestSelector
Request returns how the rule selects requests.
func (Rule) RequestHeaders ¶ added in v0.44.0
func (r Rule) RequestHeaders() []HeaderSelector
RequestHeaders returns how the rule selects requests by their headers, sorted by name.
func (Rule) ResponseHeaders ¶ added in v0.44.0
func (r Rule) ResponseHeaders() []HeaderSelector
ResponseHeaders returns how the rule selects responses by their headers, sorted by name.
func (Rule) SelectsEveryResponse ¶ added in v0.44.0
SelectsEveryResponse reports whether the rule selects every response to a request its pattern and request header values select.
func (Rule) SelectsRequestHeaders ¶ added in v0.44.0
SelectsRequestHeaders reports whether a request has the header values the rule requires. Header functions are left to the caller.
func (Rule) Status ¶ added in v0.43.0
func (r Rule) Status() StatusSelector
Status returns how the rule selects responses by status.
type StatusCodes ¶ added in v0.43.0
type StatusCodes struct{ Codes []int }
StatusCodes selects responses with one of the codes.
type StatusScript ¶ added in v0.43.0
type StatusScript struct{}
StatusScript selects the responses whose status a script function accepts.
type StatusSelector ¶ added in v0.43.0
type StatusSelector interface {
// contains filtered or unexported methods
}
StatusSelector selects the responses a rule applies to by their status.