Documentation
¶
Overview ¶
Package comparison normalises payloads with scripts, then diffs or hashes them.
Index ¶
- type Config
- type Hash
- type Scripts
- func (s *Scripts) Compare(ctx context.Context, typeName Option[schema.TypeRef], reference, candidate any) (differences []string, err error)
- func (s *Scripts) Endpoints() []javascript.Endpoint
- func (s *Scripts) Hash(ctx context.Context, identity string, typeName Option[schema.TypeRef], ...) (Hash, error)
- func (s *Scripts) NormaliseResponse(ctx context.Context, rule javascript.Rule, status int, body Option[any]) (Option[int], Option[any], error)
- func (s *Scripts) Rules() []javascript.Rule
- func (s *Scripts) Schema() *schema.Schema
- func (s *Scripts) SelectRule(ctx context.Context, rules []javascript.Rule, request javascript.Request, ...) (Option[javascript.Rule], error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// ScriptsDir holds the normaliser scripts, which are all loaded as one set.
ScriptsDir string `` /* 165-byte string literal not displayed */
// Schema types every payload the scripts register for.
Schema schema.Config `embed:""`
// ComparisonTimeout limits one response comparison.
ComparisonTimeout time.Duration `default:"1s" help:"Maximum duration of one response comparison."`
}
Config contains the command-line configuration for scripts and comparison.
type Hash ¶ added in v0.25.0
Hash identifies a payload by its identity and normalised content, so equivalent payloads share a hash.
type Scripts ¶ added in v0.25.0
type Scripts struct {
// contains filtered or unexported fields
}
Scripts is one immutable set of normaliser scripts and the schema they were checked against. It is safe for concurrent use.
func New ¶
New loads every script in the configured directory and checks that each declared endpoint type exists.
func (*Scripts) Compare ¶ added in v0.25.0
func (s *Scripts) Compare(ctx context.Context, typeName Option[schema.TypeRef], reference, candidate any) (differences []string, err error)
Compare normalises both payloads as typeName and returns the paths at which they differ. Untyped payloads are compared without normalisers.
func (*Scripts) Endpoints ¶ added in v0.25.0
func (s *Scripts) Endpoints() []javascript.Endpoint
Endpoints returns every declared endpoint, ingress first, in declaration order.
func (*Scripts) Hash ¶ added in v0.25.0
func (s *Scripts) Hash(ctx context.Context, identity string, typeName Option[schema.TypeRef], side string, payload any) (Hash, error)
Hash returns SHA-256 over identity and the canonical JSON of the normalised payload. side only labels log records.
func (*Scripts) NormaliseResponse ¶ added in v0.43.0
func (s *Scripts) NormaliseResponse(ctx context.Context, rule javascript.Rule, status int, body Option[any]) (Option[int], Option[any], error)
NormaliseResponse applies a rule's normaliser to one response. A None status or body is not compared, and a returned body must still be the rule's type.
func (*Scripts) Rules ¶ added in v0.43.0
func (s *Scripts) Rules() []javascript.Rule
Rules returns the ingress rules in declaration order.
func (*Scripts) Schema ¶ added in v0.25.0
Schema returns the payload types the scripts were checked against.
func (*Scripts) SelectRule ¶ added in v0.43.0
func (s *Scripts) SelectRule(ctx context.Context, rules []javascript.Rule, request javascript.Request, response javascript.Response) (Option[javascript.Rule], error)
SelectRule returns the first rule that selects a response. rules must be in declaration order, and the request must match each rule's pattern, if it has one.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package javascript evaluates Spectre payload normaliser scripts.
|
Package javascript evaluates Spectre payload normaliser scripts. |