integration

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 30 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 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

View Source
const (
	// AnnotationProjectedBody is the hash of the last rendered body+labels.
	AnnotationProjectedBody = "patchy.bitwisemedia.uk/projected-body"
	// AnnotationProjectedEnrichments is the hash of the last projected
	// enrichment sticky comments.
	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.

View Source
const BranchPrefix = "patchy/"

BranchPrefix prefixes every remediation branch; the finding name follows, so pull-request webhooks resolve their Finding from the head ref alone.

View Source
const DefaultWindow = time.Hour

DefaultWindow is the accumulation window when unconfigured.

View Source
const TrackingURLIndex = "status.tracking.url"

TrackingURLIndex is the field-indexer key mapping a tracking item's html URL to its Finding.

Variables

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

func NewCreds(r client.Reader) *Creds

NewCreds builds a Creds reading through r (the manager's API reader so Secrets stay uncached).

func (*Creds) App added in v0.5.4

func (c *Creds) App(ctx context.Context, integ *v1alpha1.Integration) (app *ghclient.App, ok bool, err error)

App returns the Integration's GitHub App for app-level (JWT) calls like the webhook delivery log. ok is false for a PAT credential — PATs cannot see App webhook deliveries.

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

func (c *Creds) Validate(ctx context.Context, integ *v1alpha1.Integration) error

Validate checks the Integration's secret carries a usable API credential and a webhook secret.

func (*Creds) WebhookSecret

func (c *Creds) WebhookSecret(ctx context.Context, integ *v1alpha1.Integration) ([]byte, error)

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) Reconcile

func (r *FindingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile implements the projection control loop.

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.

func (*Ingestor) Ingest

func (in *Ingestor) Ingest(ctx context.Context, integ *v1alpha1.Integration, f source.Finding) error

Ingest folds one scanner finding into the cluster: append its alert to the live pre-investigation Finding of its family, or create the next generation.

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
	// Now tells time; nil means time.Now (tests override).
	Now func() time.Time
}

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.

func (*Receiver) Handle

func (r *Receiver) Handle(ctx context.Context, e webhook.Event) error

Handle implements webhook.Handler for the /github/webhooks path.

func (*Receiver) Secrets

func (r *Receiver) Secrets(ctx context.Context) [][]byte

Secrets returns every configured github Integration's webhook secret — the candidate set for delivery validation (webhook.Config.SecretsFor).

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.

func (*Signals) Handle

func (s *Signals) Handle(ctx context.Context, integ *v1alpha1.Integration, e webhook.Event) error

Handle applies one tracking-system delivery.

Jump to

Keyboard shortcuts

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