server

package
v1.0.0-alpha.22 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 43 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 server is the ingest service behind costroid serve: the result-stream and OTLP paths, pricing against the pinned catalog, and the per-PR view.

Index

Constants

View Source
const EgressUsage = `` /* 569-byte string literal not displayed */

EgressUsage is egress' help page. costroid help egress prints it on stdout, and a command line egress cannot read prints it on stderr.

View Source
const KeysUsage = `` /* 746-byte string literal not displayed */

KeysUsage is keys' help page. costroid help keys prints it on stdout, and a command line keys cannot read prints it on stderr.

View Source
const ServeUsage = `` /* 2764-byte string literal not displayed */

ServeUsage is serve's help page. costroid help serve prints it on stdout, and a flag serve cannot parse prints it on stderr.

Variables

This section is empty.

Functions

func EgressMain

func EgressMain(ctx context.Context, args []string, stdout, stderr io.Writer) int

EgressMain runs costroid egress and returns an exit code.

func KeysMain

func KeysMain(ctx context.Context, args []string, stdout, stderr io.Writer) int

KeysMain runs costroid keys and returns an exit code.

func Main

func Main(ctx context.Context, args []string, stderr io.Writer) int

Main runs costroid serve until ctx ends and returns an exit code.

Types

type ApprovalHost

type ApprovalHost interface {
	scm.Host
	scm.History
	policy.Branches
}

ApprovalHost is what the approve button needs from one repository: the pull request, the approver's role, costroid.yml at the head of the base branch, and the commit's check runs.

type Config

type Config struct {
	Ledger   Ledger
	Verifier TokenVerifier
	Catalog  *catalog.Catalog
	// PseudonymKey is the master key the per-tenant HMAC keys derive from.
	PseudonymKey []byte
	// GatewayEnvironment is the GitHub environment whose jobs may attest a
	// minted credential. Empty trusts none, and then no row reads exact.
	GatewayEnvironment string
	// Spend keeps the gateway's attested spend. Nil, the service refuses a
	// spend attestation and treats every token-verified spend as agent counts.
	Spend SpendLedger
	// App serves POST /webhooks/github. Nil, the route is not served.
	App    *GitHubApp
	Now    func() time.Time
	Logger *slog.Logger
}

Config wires a Server.

type GitHubApp

type GitHubApp struct {
	// Secret is the webhook secret GitHub signs each delivery with.
	Secret        []byte
	Installations Installations
	// Deliveries keeps the delivery ids taken. Nil keeps them in this
	// process's memory, which a restart forgets.
	Deliveries scm.DeliveryStore
	// Hosts reaches a repository as one of the App's installations. Without
	// it, an approve press is refused and logged: the service holds no App
	// key to post a check with.
	Hosts RepositoryHosts
}

GitHubApp configures POST /webhooks/github. A Config without one does not serve the route.

type Installations

type Installations interface {
	AddRepositories(ctx context.Context, installation int64, account string, repositories []store.Repository) error
	RemoveRepositories(ctx context.Context, installation int64, repositories []int64) error
	SuspendInstallation(ctx context.Context, installation int64, account string, suspended bool) error
	DeleteInstallation(ctx context.Context, installation int64) error
	// Installation answers store.ErrNotFound for an installation it does not
	// hold.
	Installation(ctx context.Context, installation int64) (store.Installation, error)
}

Installations keeps the App's installations: ids and names, never a token.

type Ledger

type Ledger interface {
	TenantForOwner(ctx context.Context, host, owner string) (store.TenantID, error)
	TenantForKey(ctx context.Context, keySHA256 string) (store.TenantID, error)
	Ingest(ctx context.Context, tenant store.TenantID, batch store.Batch) (store.Receipt, error)
	PullRequest(ctx context.Context, tenant store.TenantID, repo, pr string) ([]store.Line, error)
	Attest(ctx context.Context, tenant store.TenantID, minted store.MintedCredential) error
	MintedCredentials(ctx context.Context, tenant store.TenantID, keys []string) (map[string]store.MintedCredential, error)
}

Ledger is what the service needs from the store.

type RepositoryHosts

type RepositoryHosts interface {
	Repository(installation int64, repository string) (ApprovalHost, error)
}

RepositoryHosts reaches one repository, owner/name, as one installation.

type Server

type Server struct {
	Config
	// contains filtered or unexported fields
}

Server handles ingest and the view.

func New

func New(config Config) *Server

New returns the service. Now and Logger default to the real clock and the default logger.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the service's routes.

func (*Server) ProcessWebhooks

func (s *Server) ProcessWebhooks(ctx context.Context)

ProcessWebhooks applies the verified deliveries until ctx ends. It returns at once when the route is not served.

type SpendLedger

type SpendLedger interface {
	// AttestSpend records a key's USD spend. The key must be attested as
	// minted for the run named: store.ErrAttestedElsewhere and
	// store.ErrNotMinted say it is not. A key's spend is the largest figure
	// attested for it, because a gateway's count only grows.
	AttestSpend(ctx context.Context, tenant store.TenantID, key store.MintedCredential, usd decimal.Decimal) error
	// GatewaySpend reads the pull request's measured spend. Rows counts its
	// budget-eligible rows whose credential is a key minted for the row's own
	// run, with credential_basis minted, and whose spend a close job attested.
	// USD adds up the attested spend of those keys, each key once.
	GatewaySpend(ctx context.Context, tenant store.TenantID, repo, pr string) (rows int64, usd decimal.Decimal, err error)
}

SpendLedger keeps what costroid gateway close attests: the gateway's own count of a minted key's spend, in USD. The count is the gateway's, so it stands as a budget's evidence where the token counts on the rows cannot.

type TokenVerifier

type TokenVerifier interface {
	Verify(ctx context.Context, token string) (oidc.Identity, error)
}

TokenVerifier checks a CI OIDC token.

Jump to

Keyboard shortcuts

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