generic

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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

func DeliveryID(r *http.Request, body []byte) string

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

func Detect(body []byte) (string, error)

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

func NameFromPath(path string) (string, bool)

NameFromPath extracts the integration name from a concrete request path of the form /generic/<name>/webhooks.

func PathFor

func PathFor(name string) string

PathFor is the concrete webhook path of one named generic integration, the inverse of NameFromPath.

func Sign

func Sign(secret, body []byte) string

Sign computes the SignatureHeader value for a body: "sha256=<hex>" of the HMAC-SHA256 under the integration's shared secret. It is exported because both sides of the contract need it: patchy signs outbound calls here, and test/replay tooling signs inbound deliveries the same way.

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

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

func NewResolver(c *Client, integration string) *Resolver

NewResolver builds the write-back for one integration.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, alerts []source.AlertRef, v source.Verdict) error

Resolve implements source.Resolver: one POST carrying every alert, any 2xx is success.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source is the generic source plugin for one integration.

func NewSource

func NewSource(name string, o Options) *Source

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.

func (*Source) ID

func (s *Source) ID() string

ID implements source.Handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL