Documentation
¶
Overview ¶
Package generic implements the generic integration's behavior over the wire contract published in pkg/generic: the validating source handler that turns an inbound findings delivery into pkg/source Findings, and the signed outbound HTTP client behind both the verdict resolver and the context-enhancer call.
Unlike every other source package there is no description template here. The external process authors its own markdown, because patchy has no tool-native payload to render, only the normalized contract.
A handler's source id is the Integration's name, not a package constant: any number of generic integrations coexist, and the name keeps their accumulation keys, labels, sticky comments, and write-back dispatch apart.
Index ¶
Constants ¶
const EventFindings = "generic.findings"
EventFindings is the internal event discriminator for a findings delivery. It differs from the wire value so a handler switch cannot confuse the two vocabularies.
const PathPattern = "/generic/{name}/webhooks"
PathPattern is the wildcard ServeMux route generic integrations deliver to: unlike the per-provider routes, each generic Integration has its own path, because each has its own secret and identity.
Variables ¶
This section is empty.
Functions ¶
func DeliveryID ¶
DeliveryID derives the dedup key for a delivery: the caller-chosen DeliveryHeader when present, else the body hash. Byte-identical redeliveries dedup and distinct payloads never do, as for wiz.
func Detect ¶
Detect reports the internal event type of a delivery: "ping" for a connectivity test (the server answers 204), EventFindings for findings. An undecodable body, an unsupported version, or an unknown event is an error, and the caller answers 400.
func NameFromPath ¶
NameFromPath extracts the integration name from a concrete request path of the form /generic/<name>/webhooks.
func PathFor ¶
PathFor is the concrete webhook path of one named generic integration, the inverse of NameFromPath.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the signed outbound HTTP client behind both generic exchanges patchy initiates: verdict write-back and enhancement.
func NewClient ¶
func NewClient(o ClientOptions) (*Client, error)
NewClient builds a Client. Construction makes no network call, so it cannot fail on an endpoint outage, only on missing configuration.
func (*Client) Enhance ¶
func (c *Client) Enhance(ctx context.Context, req pkggeneric.EnhanceRequest) (*pkggeneric.EnhanceResponse, error)
Enhance delivers one enhancement request. It returns (nil, nil) when the endpoint answers 204 or an empty body, meaning nothing to contribute.
type ClientOptions ¶
type ClientOptions struct {
// URL the calls POST to.
URL string
// Secret signs each request body.
Secret []byte
// Timeout bounds each call; zero means defaultTimeout.
Timeout time.Duration
// HTTPClient overrides the transport in tests; nil means a default
// client (the per-call timeout comes from the request context).
HTTPClient *http.Client
}
ClientOptions configure a Client.
type Options ¶
type Options struct {
// MinSeverity drops findings below this level (low/medium/high/
// critical). Empty admits everything.
MinSeverity string
}
Options configure a handler.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver is the generic write-back: it tells the external process what the pipeline decided, over the same signed channel. The process must be idempotent: the contract says so, and patchy retries.
func NewResolver ¶
NewResolver builds the write-back for one integration.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source is the generic source plugin for one integration.
func NewSource ¶
NewSource builds the handler for the named integration. The name becomes the source id of every finding it emits.
func (*Source) Findings ¶
func (s *Source) Findings(_ context.Context, event string, payload []byte) ([]source.Finding, error)
Findings implements source.Handler: it validates one findings delivery and maps it onto source.Finding. Validation is all-or-nothing: any invalid finding fails the whole delivery (the errors are joined), so the external process fixes and re-POSTs rather than half its batch silently landing.