Documentation
¶
Overview ¶
Package integration is the integration-controller's engine: the edge between patchy and its external systems, driven by Integration resources.
Inbound, the receiver terminates the provider webhook paths (/github/webhooks), validates each delivery against the configured Integrations' webhook secrets, and turns scanner events into Finding resources through the pkg/source handler seam (accumulating alerts into an open finding for the accumulation window). Outbound, the Finding projection reconciler renders each Finding — and its Investigation and Remediation children — as a tracking issue: body, labels, comments, assignment, alert dismissal, and closure. Human signals on the tracking item (/approve comments, issue close/reopen, pull-request merge) flow back as Finding writes.
v1alpha1 simplification: one issues-enabled Integration and one code-scanning-enabled Integration per namespace (they are usually the same object). Ambiguity surfaces as an error condition rather than a guess; a routing field can widen this later.
Index ¶
Constants ¶
const ( // AnnotationProjectedBody is the hash of the last rendered body+labels. AnnotationProjectedBody = "patchy.bitwisemedia.uk/projected-body" // AnnotationProjectedEnrichments counts enrichment comments posted. AnnotationProjectedEnrichments = "patchy.bitwisemedia.uk/projected-enrichments" // AnnotationProjectedInvestigation names the Investigation whose report // comment was posted. AnnotationProjectedInvestigation = "patchy.bitwisemedia.uk/projected-investigation" // AnnotationProjectedRemediation names the Remediation whose report // comment was posted. AnnotationProjectedRemediation = "patchy.bitwisemedia.uk/projected-remediation" // AnnotationProjectedNotice records the phase whose human notice // (hold/hand-off/failure) was posted. AnnotationProjectedNotice = "patchy.bitwisemedia.uk/projected-notice" )
Projection-state annotations on the Finding: what has already been pushed to the tracking item, so re-reconciles stay idempotent without re-reading comments. All are integration-controller-owned.
const BranchPrefix = "patchy/"
BranchPrefix prefixes every remediation branch; the finding name follows, so pull-request webhooks resolve their Finding from the head ref alone.
const DefaultWindow = time.Hour
DefaultWindow is the accumulation window when unconfigured.
const TrackingURLIndex = "status.tracking.url"
TrackingURLIndex is the field-indexer key mapping a tracking item's html URL to its Finding.
Variables ¶
var ( // ErrNoIntegration: no enabled Integration provides the capability. ErrNoIntegration = errors.New("no integration provides the capability") // ErrAmbiguousIntegration: several Integrations provide the capability — // v1alpha1 requires exactly one per namespace. ErrAmbiguousIntegration = errors.New("multiple integrations provide the capability") )
Sentinel errors for integration selection.
Functions ¶
This section is empty.
Types ¶
type Creds ¶
type Creds struct {
// contains filtered or unexported fields
}
Creds reads Integration credential Secrets and builds GitHub clients.
func NewCreds ¶
NewCreds builds a Creds reading through r (the manager's API reader so Secrets stay uncached).
func (*Creds) Client ¶
func (c *Creds) Client(ctx context.Context, integ *v1alpha1.Integration, repo ghclient.Repo) (*ghclient.Client, error)
Client returns an API client for the Integration, authenticated for repo (App installation) or statically (PAT).
func (*Creds) Validate ¶
Validate checks the Integration's secret carries a usable API credential and a webhook secret.
func (*Creds) WebhookSecret ¶
WebhookSecret returns the Integration's receiver HMAC secret.
type FindingReconciler ¶
type FindingReconciler struct {
client.Client
// Creds builds Integration API clients.
Creds *Creds
// Namespace the Findings live in.
Namespace string
// Now is the clock seam; nil means time.Now.
Now func() time.Time
// ClientFor overrides the tracker-client construction in tests.
ClientFor func(ctx context.Context, integ *v1alpha1.Integration, repo ghclient.Repo) (trackerClient, error)
// Log receives diagnostics; nil discards.
Log *slog.Logger
}
FindingReconciler projects each Finding (and its children's results) onto its tracking issue, and owns the accumulation-window condition.
func (*FindingReconciler) SetupWithManager ¶
func (r *FindingReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager wires the reconciler: Findings plus child watches mapped to the owning Finding, and the tracking-URL field index the Signals handler queries.
type Ingestor ¶
type Ingestor struct {
client.Client
// Namespace the Findings live in.
Namespace string
// Window is the accumulation window (default DefaultWindow).
Window time.Duration
// Now is the clock seam; nil means time.Now.
Now func() time.Time
// Log receives ingest diagnostics; nil discards.
Log *slog.Logger
}
Ingestor folds scanner findings into Finding resources. The deterministic name plus AlreadyExists-tolerant create is the idempotency mechanism — no in-process mutex, the API server serializes.
type IntegrationReconciler ¶
type IntegrationReconciler struct {
client.Client
// Creds reads and validates the Integration's secret.
Creds *Creds
// Log receives reconcile diagnostics; nil discards.
Log *slog.Logger
}
IntegrationReconciler validates Integration credentials and maintains the Ready condition and receiver path.
func (*IntegrationReconciler) Reconcile ¶
func (r *IntegrationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)
Reconcile implements the Integration control loop.
func (*IntegrationReconciler) SetupWithManager ¶
func (r *IntegrationReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager wires the reconciler.
type Receiver ¶
type Receiver struct {
// Reader lists Integrations (informer cache).
Reader client.Reader
// Creds builds Integration API clients.
Creds *Creds
// Ingest folds scanner findings into Finding resources.
Ingest *Ingestor
// Signals applies human-signal events to Findings.
Signals *Signals
// Namespace the Integrations and Findings live in.
Namespace string
// Log receives receiver diagnostics; nil discards.
Log *slog.Logger
}
Receiver is the integration-controller's webhook.Handler: it turns validated GitHub deliveries into Finding writes. Scanner events go through the pkg/source handler seam into the Ingestor; tracking events (issues, comments, pull requests) go to the Signals handler.
type Signals ¶
type Signals struct {
client.Client
// Namespace the Findings live in.
Namespace string
// Now is the clock seam; nil means time.Now.
Now func() time.Time
// Log receives diagnostics; nil discards.
Log *slog.Logger
}
Signals applies human actions on tracking items to Findings: the writer of edges 16/17 (PR merged/closed), 19 (issue reopened after dismissal), 20 (issue closed by a human), and of spec.approval.