Documentation
¶
Overview ¶
Package generic is the wire contract of patchy's generic integration: the JSON shapes and headers an external process exchanges with patchy when it acts as a finding source, a verdict resolver, or a context enhancer. The process can be anything that speaks HTTP (a scheduled job querying a warehouse store, an internal CMDB, a vendor bridge), registered as an Integration with spec.provider: generic.
Three exchanges, all JSON bodies signed with the integration's shared secret (HMAC-SHA256 over the raw body, carried in SignatureHeader):
- Inbound findings: the process POSTs a Payload of normalized findings to /generic/<integration-name>/webhooks.
- Verdict write-back: patchy POSTs a ResolveRequest to the configured resolver URL when a finding is dismissed.
- Enhancement: patchy POSTs an EnhanceRequest to the configured enhancer URL for each opened finding; the response body is an EnhanceResponse (204 or an empty body contributes nothing).
The full protocol (validation rules, semantics, and worked signature examples) is documented in docs/integrations/generic.md. External processes import this package, so the exported API is self-contained and depends on nothing under internal/.
Index ¶
Constants ¶
const ( // SignatureHeader carries "sha256=<hex of HMAC-SHA256(secret, body)>". SignatureHeader = "X-Patchy-Signature-256" // DeliveryHeader optionally carries a caller-chosen unique id for an // inbound delivery, used for deduplication. Absent, patchy derives one // from the body, so byte-identical redeliveries still dedup. DeliveryHeader = "X-Patchy-Delivery" )
Headers of the generic exchanges. Both directions sign the raw JSON body with the integration's shared secret and carry the result in SignatureHeader; the receiver recomputes the HMAC over the exact bytes received and compares in constant time.
const ( // EventFindings delivers findings. EventFindings = "findings" // EventPing is a connectivity test; patchy answers 204 and ingests // nothing. EventPing = "ping" )
Payload event discriminators.
const Version = "v1"
Version is the contract version this package describes. Every exchanged body carries it; patchy rejects any other value.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlertRef ¶
type AlertRef struct {
// ID is the alert's identifier in the source system: the delivered
// alertId, or the delivered alertNumber rendered as a string.
ID string `json:"id"`
// URL is the alert in the source system, when it was delivered.
URL string `json:"url,omitempty"`
}
AlertRef names one alert of the resolved finding, as the integration originally delivered it.
type EnhanceRequest ¶
type EnhanceRequest struct {
// Version is the contract version, always Version.
Version string `json:"version"`
// Integration is the requesting Integration's name, so one process can
// serve several integrations from a single endpoint.
Integration string `json:"integration"`
// Issue is the finding under enhancement.
Issue Issue `json:"issue"`
}
EnhanceRequest is what patchy POSTs to the integration's enhancer URL.
type EnhanceResponse ¶
type EnhanceResponse struct {
// Owners are logins responsible for the finding, in preference order;
// the pipeline uses them for issue assignment.
Owners []string `json:"owners,omitempty"`
// CommentMarkdown is arbitrary content, kept as one sticky comment on
// the tracking issue, attributed to this integration. Semi-structured
// facts belong in Attributes.
CommentMarkdown string `json:"commentMarkdown,omitempty"`
// Attributes are semi-structured facts (system name, environment,
// tier), projected as tracking labels.
Attributes map[string]string `json:"attributes,omitempty"`
// Repository resolves the repository of a finding that arrived without
// one. Ignored when the finding already has a repository; only
// provider "github" is honoured today.
Repository *source.RepositoryRef `json:"repository,omitempty"`
}
EnhanceResponse is the enhancer's contribution. Answering 204, or 200 with an empty body, contributes nothing. That is the right reply for a finding the process has no context on.
type Finding ¶
type Finding struct {
// Repo is the repository the finding was raised against; omit for a
// cloud finding (an enhancer may resolve its repository later).
Repo *Repo `json:"repo,omitempty"`
// CloudResource is the cloud resource the finding was raised against;
// omit for a code finding.
CloudResource *source.CloudResource `json:"cloudResource,omitempty"`
// AlertID is the finding's identifier in the source system. It
// supersedes AlertNumber.
AlertID string `json:"alertId,omitempty"`
// AlertNumber is the source-native finding number, for tools that
// number rather than name their findings.
AlertNumber int `json:"alertNumber,omitempty"`
// Advisories are the categorization identifiers (GHSA/CVE/CWE numbers,
// or tool-native rule keys), most authoritative first: Advisories[0] is
// the accumulation key. Empty, patchy falls back to a key derived from
// RuleID (else AlertID/AlertNumber), so findings of the same rule fold.
Advisories []string `json:"advisories,omitempty"`
// RuleID is the tool's rule identifier.
RuleID string `json:"ruleId,omitempty"`
// Title is a one-line human summary. Required.
Title string `json:"title"`
// Description is the full markdown description; it becomes the tracking
// issue body's finding section verbatim.
Description string `json:"description,omitempty"`
// Severity is low, medium, high, or critical. Required.
Severity string `json:"severity"`
// HTMLURL links back to the finding in the source tool.
HTMLURL string `json:"htmlUrl,omitempty"`
// Locations are the places the finding was raised, when available.
Locations []source.Location `json:"locations,omitempty"`
}
Finding is one normalized security finding. The external process does its own normalization: patchy validates the shape and ingests, it does not interpret tool-native payloads.
A finding names a Repo, a CloudResource, or both; one with neither is rejected, because there would be nothing to accumulate it against. It must also carry AlertID or a positive AlertNumber, the identity that write-back and duplicate merging key on.
type Issue ¶
type Issue struct {
// Repo is the repository the finding was raised against; absent for a
// cloud finding whose repository is not yet resolved.
Repo *Repo `json:"repo,omitempty"`
// Number is the tracking issue number, when one exists.
Number int `json:"number,omitempty"`
// Title is the finding title.
Title string `json:"title"`
// Body is the finding description markdown.
Body string `json:"body,omitempty"`
// Labels are the tracking labels.
Labels []string `json:"labels,omitempty"`
// CloudResource is set when the finding is about a cloud resource
// rather than repository code.
CloudResource *source.CloudResource `json:"cloudResource,omitempty"`
}
Issue is the view of a finding an external enhancer receives: the same projection in-tree enhancers see, JSON-tagged for the wire.
type Payload ¶
type Payload struct {
// Version must be Version.
Version string `json:"version"`
// Event is EventFindings or EventPing.
Event string `json:"event"`
// Findings are the delivered findings; required (non-empty) for
// EventFindings, ignored for EventPing.
Findings []Finding `json:"findings,omitempty"`
}
Payload is the inbound envelope an external process POSTs to /generic/<integration-name>/webhooks.
type Repo ¶
type Repo struct {
// Owner is the organization or user.
Owner string `json:"owner"`
// Name is the repository name.
Name string `json:"name"`
}
Repo identifies a repository by owner and name on the configured forge.
type ResolveRequest ¶
type ResolveRequest struct {
// Version is the contract version, always Version.
Version string `json:"version"`
// Integration is the requesting Integration's name.
Integration string `json:"integration"`
// Alerts are the alerts to resolve.
Alerts []AlertRef `json:"alerts"`
// Verdict is the decision to record.
Verdict Verdict `json:"verdict"`
}
ResolveRequest is what patchy POSTs to the integration's resolver URL when a finding is dismissed, so the source system can close its own record. The process must treat it as idempotent: patchy retries on failure, so the same alerts may be resolved more than once. Any 2xx answer is success.
type Verdict ¶
type Verdict struct {
// Kind is the decision. "ignore" is the only kind today: the
// investigation judged the finding a false positive or not exploitable.
Kind string `json:"kind"`
// Reason is a short machine-facing reason code.
Reason string `json:"reason,omitempty"`
// Comment is human-readable justification.
Comment string `json:"comment,omitempty"`
}
Verdict is the pipeline's decision on the finding.