wildcard

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: BSD-2-Clause Imports: 7 Imported by: ? 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 wildcard expands owner-level wildcard allowlist entries (e.g. "github.com/bborbe/*") into concrete "host/owner/repo" entries by listing the owner's repositories via the GitHub API. The resolved entry slice is held in a thread-safe snapshot, refreshed once an hour by a background goroutine.

Allowlists that contain zero wildcard entries do NOT trigger any API calls and do NOT start a refresh goroutine — they are returned through the package unchanged so pure-literal behavior is byte-identical to the pre-wildcard code path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasWildcard

func HasWildcard(entries []string) bool

HasWildcard reports whether any entry in the allowlist is a wildcard entry ("host/owner/*"). Callers use this to short-circuit refresh setup when the allowlist is pure-literal.

func RefreshInterval

func RefreshInterval() time.Duration

RefreshInterval returns the (constant) wildcard refresh cadence. Exposed for assertion in tests that verify spec 039's "invariant at one hour" Non-goal is not regressed.

Types

type Expander

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

Expander resolves wildcard allowlist entries against the GitHub API.

func NewExpander

func NewExpander(client ownerLister) *Expander

NewExpander returns an Expander that uses the given client.

func (*Expander) Expand

func (e *Expander) Expand(ctx context.Context, input []string) ([]string, error)

Expand resolves every wildcard entry in input against the GitHub API and returns a deduplicated slice of concrete "host/owner/repo" entries (literals pass through unchanged). Resolution order: input order, with each wildcard expanded in-place; literals that also appear in a wildcard's expansion are NOT duplicated.

Per-entry failures: ANY API error for a given wildcard entry causes that wildcard's contribution to be empty in the returned slice and the error is returned wrapped with the entry name. Callers that hold a previously-resolved snapshot use ResolvedAllowlist.Refresh (see resolved.go) to merge fresh results with last-known-good fallback.

Emits one glog.V(2) line per wildcard resolution naming the entry, the resolved count, and source="fresh".

type ResolvedAllowlist

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

ResolvedAllowlist holds the current resolved entry slice (concrete host/owner/repo strings; wildcards already expanded).

Reads via Snapshot are wait-free (atomic pointer load). Writes via Refresh hold an internal mutex to avoid two concurrent refreshes overlapping.

func NewResolvedAllowlist

func NewResolvedAllowlist(expander *Expander, input []string) *ResolvedAllowlist

NewResolvedAllowlist returns a ResolvedAllowlist seeded with the given input allowlist (wildcards NOT yet expanded). The snapshot starts as a copy of input MINUS any wildcard entries — so callers that read the snapshot before the first successful Refresh see only the literals, matching spec AC: "Cold start: initial resolution fails ... wildcards contribute zero entries until first successful refresh; literal entries poll normally."

func (*ResolvedAllowlist) Refresh

func (r *ResolvedAllowlist) Refresh(ctx context.Context) error

Refresh re-resolves every wildcard entry against the GitHub API and updates the snapshot. On per-wildcard failure the existing contribution for that wildcard is retained (last-known-good fallback); if ALL wildcards fail, the snapshot is left untouched. Emits a glog.V(2) "wildcard_expanded ... source=last-known-good" line for each wildcard whose refresh failed but had a previously-resolved value.

Refresh is safe to call from multiple goroutines but serializes via an internal mutex — concurrent callers wait their turn.

func (*ResolvedAllowlist) RunRefreshLoop

func (r *ResolvedAllowlist) RunRefreshLoop(ctx context.Context) error

RunRefreshLoop blocks until ctx is cancelled, calling Refresh once per refreshInterval. The first Refresh is invoked IMMEDIATELY (not after the first tick) so the snapshot is populated as fast as possible after startup. Panics in Refresh are recovered and logged; the loop re-arms for the next tick (spec failure mode: "Refresh goroutine panics → Recover, log error at V(0), re-arm the next refresh tick").

Returns nil when ctx is cancelled. Never returns an error otherwise.

func (*ResolvedAllowlist) Snapshot

func (r *ResolvedAllowlist) Snapshot() []string

Snapshot returns the current resolved entry slice. The returned slice is safe to iterate while a concurrent Refresh is in progress; the refresh swaps the pointer atomically.

Callers MUST NOT mutate the returned slice.

Jump to

Keyboard shortcuts

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