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) SelectsStatus(rule Rule, status int) (bool, error)
- type FieldTarget
- type Program
- type Request
- type RequestPattern
- type RequestScript
- type RequestSelector
- type Rule
- 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.
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 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
Request is an inbound HTTP request as a rule's request function sees it.
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 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) 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.