forge

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 14 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 forge resolves a finding's repository URL to the Forge custom resource whose credentials may act on it, and mints per-operation scoped tokens from that Forge's secret.

It is the one shared path to forge access: source-controller resolves read scope (clone/tarball), remediation-controller resolves write scope (branch push, pull request). Matching is host equality, then the org allowlist, then the repository regexes. When several Forges match, the more constrained spec wins (orgs set beats unset, then repositories set beats unset). A remaining tie is ErrAmbiguous: an operator configuration error, never silently resolved.

Index

Constants

View Source
const (
	SecretKeyToken      = ghsecret.KeyToken
	SecretKeyAppID      = ghsecret.KeyAppID
	SecretKeyPrivateKey = ghsecret.KeyPrivateKey
)

Secret keys a Forge credential Secret may carry. Integration secrets use the same shape (see internal/ghsecret).

Variables

View Source
var (
	// ErrNoMatch: no Forge's filters cover the repository.
	ErrNoMatch = errors.New("no forge matches repository")
	// ErrAmbiguous: two or more Forges match with equal specificity.
	ErrAmbiguous = errors.New("ambiguous forge match")
)

Sentinel errors callers branch on (they become Finding condition reasons).

Functions

func Host

func Host(f *v1alpha1.Forge) string

Host returns the host a Forge covers: spec.baseURL's host when set (a bare host or a URL are both accepted), else the provider's public host.

func ParseRepoURL

func ParseRepoURL(raw string) (host string, repo ghclient.Repo, err error)

ParseRepoURL splits a repository URL into host and owner/name. It accepts http(s) URLs with or without a .git suffix or trailing path segments. The host is lowercased; owner and name keep their case. The org filter compares owners case-insensitively, but repository regexes match the name as given.

Types

type Resolved

type Resolved struct {
	// Forge whose credentials cover the repository.
	Forge *v1alpha1.Forge
	// Repo is the parsed owner/name.
	Repo ghclient.Repo
	// Host the repository lives on (lowercase, no port).
	Host string
}

Resolved is a repository bound to the Forge allowed to act on it.

func Resolve

func Resolve(forges []v1alpha1.Forge, repoURL string) (*Resolved, error)

Resolve picks the Forge covering repoURL from the given Forges. It is pure: callers list the Forges (informer cache) and pass them in.

type Scope

type Scope string

Scope is the credential scope a caller needs.

const (
	ScopeRead  Scope = "read"
	ScopeWrite Scope = "write"
)

Credential scopes: read mints contents:read (clone/tarball); write mints contents:write (branch push). Pull-request creation uses the same installation client.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store resolves Forges and mints their credentials.

func NewStore

func NewStore(r client.Reader) *Store

NewStore builds a Store reading Forges and Secrets through r. Pass the manager's API reader (not the cache) so Secrets need no list/watch grant.

func (*Store) Client

func (s *Store) Client(ctx context.Context, res *Resolved) (*ghclient.Client, error)

Client returns an API client authenticated for the resolved repository, used for archive downloads, head-SHA resolution, and pull requests.

func (*Store) ContentsPermission added in v0.15.0

func (s *Store) ContentsPermission(ctx context.Context, res *Resolved) (string, error)

ContentsPermission reports the contents permission the resolved Forge's credential holds on the repository: "write", "read" or "none" for a GitHub App installation (none when the App is not installed on it), and "unknown" for a PAT, whose scopes patchy cannot see.

func (*Store) ProxyURL added in v0.11.2

func (s *Store) ProxyURL(ctx context.Context, res *Resolved) (string, error)

ProxyURL returns the resolved Forge's effective proxy URL (the spec proxy with the Secret's basic-auth credentials attached) for callers building their own client, such as the write-path pusher. "" means no spec proxy, so the environment applies.

func (*Store) Resolve

func (s *Store) Resolve(ctx context.Context, namespace, repoURL string) (*Resolved, error)

Resolve lists the Forges in namespace and picks the one covering repoURL.

func (*Store) Token

func (s *Store) Token(ctx context.Context, res *Resolved, scope Scope) (string, time.Time, error)

Token mints a short-lived token for the resolved repository at the given scope. With App auth the token is installation-scoped to the single repository. With a PAT the static token is returned as-is: a PAT cannot be narrowed, so it is for dev only.

func (*Store) Validate

func (s *Store) Validate(ctx context.Context, f *v1alpha1.Forge) error

Validate checks the Forge's secret is usable: a non-empty PAT, or a parseable App credential, either way with a parseable proxy URL. The Forge reconciler calls this for the Ready condition.

Jump to

Keyboard shortcuts

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