repoaccess

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 12 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 repoaccess is the wire contract of the integration-controller's internal repository-access endpoint, and the client the status server calls it with.

The status server holds no forge credential, so it cannot ask GitHub whether patchy can read a repository's alerts. The integration-controller can: it holds the Integration credentials already. It answers POST /internal/v1/repository-access on a separate in-cluster listener, authenticating the caller by an audience-bound projected ServiceAccount token (internal/tokenauth). The answer, per repository and Integration, is whether each enabled alert family is readable, plus whether a Forge covers the repository with write access for remediation.

Index

Constants

View Source
const (
	// Path is the endpoint's route on the internal listener.
	Path = "/internal/v1/repository-access"
	// TokenHeader carries the caller's projected ServiceAccount token.
	TokenHeader = "X-Patchy-Caller-Token"
	// Audience is the projected-token audience the endpoint accepts.
	Audience = "patchy-integration-controller"
	// MaxRepositories bounds one request: each repository costs a few GitHub
	// API requests per Integration.
	MaxRepositories = 20
)

The endpoint's fixed contract.

View Source
const (
	ContentsNone    = "none"
	ContentsRead    = "read"
	ContentsWrite   = "write"
	ContentsUnknown = "unknown" // a PAT: patchy cannot see its scopes
)

Contents permission levels a Forge credential reports.

Variables

View Source
var ErrUnavailable = errors.New("repository access check unavailable")

ErrUnavailable reports that the endpoint is not configured.

Functions

func ValidRepository

func ValidRepository(s string) bool

ValidRepository reports whether s is an exact "owner/name".

Types

type Alerts

type Alerts struct {
	CodeScanning   *Check `json:"codeScanning,omitempty"`
	SecretScanning *Check `json:"secretScanning,omitempty"`
}

Alerts holds one check per alert family the Integration ingests; a family it does not ingest is absent.

type Check

type Check struct {
	Status Status `json:"status"`
	Detail string `json:"detail,omitempty"`
}

Check is one probe's outcome. Detail carries GitHub's own message.

type Client

type Client struct {
	// URL is the integration-controller's internal base URL.
	URL string
	// TokenFile is the projected ServiceAccount token; it is read again on
	// every call, because the kubelet rotates it.
	TokenFile string
	// HTTP defaults to a client with a 30-second timeout.
	HTTP *http.Client
}

Client calls the endpoint. The zero URL disables it (Check returns ErrUnavailable).

func (*Client) Check

func (c *Client) Check(ctx context.Context, repos []string) (map[string]Result, error)

Check asks the endpoint about repos and returns the results keyed by repository.

func (*Client) Enabled

func (c *Client) Enabled() bool

Enabled reports whether the client has an endpoint to call.

type ForgeAccess

type ForgeAccess struct {
	// Name is the covering Forge, empty when none covers it.
	Name   string      `json:"name,omitempty"`
	Status ForgeStatus `json:"status"`
	// Contents is the credential's contents permission (Contents*).
	Contents string `json:"contents,omitempty"`
	Detail   string `json:"detail,omitempty"`
}

ForgeAccess is the Forge coverage of one repository.

type ForgeStatus

type ForgeStatus string

ForgeStatus is whether a Forge can remediate the repository.

const (
	// ForgeOK: a Forge covers the repository, and its credential can write
	// contents (or is a PAT, whose scope patchy cannot see).
	ForgeOK ForgeStatus = "ok"
	// ForgeMissing: no Forge covers the repository.
	ForgeMissing ForgeStatus = "missing"
	// ForgeAmbiguous: several Forges cover it equally.
	ForgeAmbiguous ForgeStatus = "ambiguous"
	// ForgeNoWrite: the covering Forge's App cannot write contents.
	ForgeNoWrite ForgeStatus = "no_write"
	// ForgeError: the check itself failed.
	ForgeError ForgeStatus = "error"
)

Forge coverage statuses.

type IntegrationAccess

type IntegrationAccess struct {
	Name   string `json:"name"`
	Alerts Alerts `json:"alerts"`
}

IntegrationAccess is one Integration's view of one repository.

func (IntegrationAccess) Readable

func (ia IntegrationAccess) Readable() bool

Readable reports whether any of the Integration's alert families answered.

type Request

type Request struct {
	// Repositories are exact "owner/name" entries, at most MaxRepositories.
	Repositories []string `json:"repositories"`
}

Request is the endpoint's body.

func (Request) Validate

func (req Request) Validate() error

Validate checks a request's repository list.

type Response

type Response struct {
	Results []Result `json:"results"`
}

Response is the endpoint's answer: one result per requested repository, in request order.

type Result

type Result struct {
	Repo string `json:"repo"`
	// Integrations are the eligible github Integrations (not suspended,
	// with an alert family enabled), sorted by name.
	Integrations []IntegrationAccess `json:"integrations"`
	// Forge reports remediation coverage.
	Forge *ForgeAccess `json:"forge,omitempty"`
}

Result is one repository's access.

func (Result) Backfillable

func (r Result) Backfillable() (string, bool)

Backfillable returns the first Integration, by name, that can read the repository's alerts: the one a one-repository backfill is stamped on.

type Status

type Status string

Status is whether one alert family of one repository is readable through one Integration. The values match internal/ghclient's AccessStatus.

const (
	StatusOK           Status = "ok"
	StatusNotInstalled Status = "not_installed"
	StatusForbidden    Status = "forbidden"
	StatusNotFound     Status = "not_found"
	StatusNoAnalysis   Status = "no_analysis"
	StatusError        Status = "error"
)

Alert access statuses.

Jump to

Keyboard shortcuts

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