source

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 1 Imported by: 1 module, 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 source is patchy's public plugin seam for security-finding sources. A source turns tool-specific deliveries — GitHub Advanced Security code-scanning alerts, Google Cloud Security Command Center notifications, other SAST tools, agentic findings — into normalized Findings. The integration-controller owns everything downstream (accumulation, issue projection, labels), so a new source implements Handler and nothing more.

A source may also implement Resolver, the optional write-back: telling the originating tool what patchy decided, so a finding dismissed here does not stay open there.

Findings are not always about code. A cloud finding names a CloudResource rather than a Repo, and its repository — if it has one — is resolved later by a pkg/enhance enhancer from the resource's ownership labels.

Implementations may live outside this repository; the exported API is deliberately self-contained and depends on nothing under internal/. Dependencies a handler needs to enrich a delivery (an API client to fetch the full alert, say) are injected at construction, not passed per call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertRef added in v0.8.0

type AlertRef struct {
	// ID is the alert's identifier in the source system.
	ID string
	// Source is the handler that produced the alert. The pipeline groups
	// alerts by it and calls each source with only its own, so a Resolver can
	// treat an unparseable ID as bad data rather than as another tool's.
	Source string
	// URL is the alert in the source system, when it has one.
	URL string
}

AlertRef is one alert to act on, as recorded on the finding.

type CloudResource added in v0.8.0

type CloudResource struct {
	// Provider is the cloud platform, e.g. "google".
	Provider string `json:"provider"`
	// Name is the platform's canonical, unique resource identifier — for
	// Security Command Center, the finding's resourceName.
	Name string `json:"name"`
	// Type is the platform's resource type, e.g. "google.cloud.storage.Bucket".
	Type string `json:"type,omitempty"`
	// Project is the enclosing project, subscription, or account id.
	Project string `json:"project,omitempty"`
	// Location is the region or zone, when the platform reports one.
	Location string `json:"location,omitempty"`
	// DisplayName is the resource's human-facing name.
	DisplayName string `json:"display_name,omitempty"`
}

CloudResource identifies a cloud resource a finding was raised against, for findings about infrastructure rather than repository code. The json tags are part of the public contract: it is embedded verbatim in agent handoff files.

type Finding

type Finding struct {
	// Source is the emitting Handler's ID, e.g. "ghas".
	Source string
	// Repo is the repository the finding was raised against. Zero on a cloud
	// finding, whose repository (if it has one at all) is resolved later by a
	// context enhancer.
	Repo Repo
	// CloudResource is the cloud resource the finding was raised against.
	// Nil on a code finding.
	CloudResource *CloudResource
	// AlertNumber is the source-native unique finding number (the
	// code-scanning alert number for GHAS). Ignored when AlertID is set.
	AlertNumber int
	// AlertID is the source-native identifier for tools that do not number
	// their findings — an SCC finding name, say. It supersedes AlertNumber.
	AlertID string
	// Advisories are the categorization identifiers (CWE/CVE/GHSA numbers),
	// most authoritative first: Advisories[0] is the accumulation key
	// (GHSA over CVE over CWE, per the source's judgement).
	Advisories []string
	// RuleID is the tool's rule identifier, e.g. a CodeQL query id.
	RuleID string
	// Title is a one-line human summary.
	Title string
	// Description is the full markdown help/description for the rule.
	Description string
	// Severity is the tool-reported severity, normalized by the handler to
	// low, medium, high, or critical.
	Severity string
	// HTMLURL links back to the finding in the source tool.
	HTMLURL string
	// Locations are the places the finding was raised, when available.
	Locations []Location
}

Finding is a source-agnostic security finding. The integration-controller keys accumulation on (scope, Source, primary advisory) — where scope is the repository for code findings and the cloud resource for infrastructure ones — and stamps the labels and issue content from these fields alone.

A finding names a Repo, a CloudResource, or both. One with neither is rejected: there would be nothing to accumulate it against.

type Handler

type Handler interface {
	// ID names the source; it becomes the security-source label value.
	ID() string
	// Findings normalizes one delivery into zero or more Findings. The event
	// type is the provider's own discriminator — a GitHub webhook event name,
	// or a constant for a provider whose endpoint carries only one kind. A
	// delivery the handler chooses to skip (an action it does not act on,
	// say) returns (nil, nil).
	Findings(ctx context.Context, eventType string, payload []byte) ([]Finding, error)
}

Handler is the interface a finding source implements.

type Lister added in v0.10.0

type Lister interface {
	// List enumerates the source's open findings, calling yield for each
	// until yield returns false or the walk is exhausted. repos narrows the
	// walk to repositories matching any entry — an exact "owner/name" or an
	// "owner/" prefix (a slash-less entry is treated as an owner prefix);
	// empty means the source's full scope. complete is false when the walk
	// ended early — the caller stopped it, or the source's page budget ran
	// out before the estate was covered.
	List(ctx context.Context, repos []string, yield func(Finding) bool) (complete bool, err error)
}

Lister is the optional backfill capability of a source: enumerating the currently open findings the tool already knows about, for alerts that predate webhook coverage and so would otherwise never be delivered.

It is deliberately separate from Handler, like Resolver: a source that only receives deliveries is a complete source — the pipeline type-asserts for Lister and reports backfill unsupported when it is absent, rather than forcing every handler to carry a no-op method.

type Location

type Location struct {
	// Path is repository-relative.
	Path      string `json:"path"`
	StartLine int    `json:"start_line,omitempty"`
	EndLine   int    `json:"end_line,omitempty"`
	// Snippet is the offending source excerpt, when the tool provides one.
	Snippet string `json:"snippet,omitempty"`
}

Location is one place in the repository a finding points at. The json tags are part of the public contract: locations are embedded verbatim in issue manifests and agent handoff files.

type Repo

type Repo struct {
	Owner string
	Name  string
}

Repo identifies a repository by owner and name. Patchy's only forge family is GitHub today, so a bare owner/name pair is unambiguous; a source that needs to name a host uses RepositoryRef instead.

func (Repo) String

func (r Repo) String() string

String returns "owner/name".

type RepositoryRef added in v0.8.0

type RepositoryRef struct {
	// Provider is the forge family, e.g. "github".
	Provider string `json:"provider"`
	// Owner is the organization or user.
	Owner string `json:"owner,omitempty"`
	// Name is the repository name.
	Name string `json:"name,omitempty"`
	// URL is the full https URL. It supersedes Owner/Name when set — the
	// resolver knows its own host, and only a URL can express a self-hosted
	// forge.
	URL string `json:"url,omitempty"`
}

RepositoryRef names a repository fully enough to act on, including the forge it lives on. It is what a context enhancer returns when it resolves the repository for a finding that arrived without one.

type Resolver added in v0.8.0

type Resolver interface {
	// Resolve records the verdict against every alert. It must be idempotent:
	// the pipeline calls it once per phase entry, but retries are possible.
	Resolve(ctx context.Context, alerts []AlertRef, v Verdict) error
}

Resolver is the optional write-back capability of a source: recording the pipeline's triage verdict against the originating tool, so the finding does not sit open there after patchy has closed it here. GHAS dismisses the code-scanning alert; Security Command Center mutes the finding.

It is deliberately separate from Handler. A source that only reads is a complete source — the pipeline type-asserts for Resolver and skips the write-back when it is absent, rather than forcing every handler to carry a no-op method.

type Verdict added in v0.8.0

type Verdict struct {
	// Kind is the decision.
	Kind VerdictKind
	// Reason is the tool-facing reason code, where the tool has a vocabulary.
	Reason string
	// Comment is human-readable justification.
	Comment string
}

Verdict is the pipeline's decision, as told to the originating tool.

type VerdictKind added in v0.8.0

type VerdictKind string

VerdictKind is a triage decision worth telling the source about.

const (
	// VerdictIgnore: the investigation judged the finding a false positive or
	// not exploitable. GHAS dismisses the alert; a cloud source mutes it.
	VerdictIgnore VerdictKind = "ignore"
)

Verdict kinds.

Jump to

Keyboard shortcuts

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