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
- func EgressMain(ctx context.Context, args []string, stdout, stderr io.Writer) int
- func KeysMain(ctx context.Context, args []string, stdout, stderr io.Writer) int
- func Main(ctx context.Context, args []string, stderr io.Writer) int
- type ApprovalHost
- type Config
- type GitHubApp
- type Installations
- type Ledger
- type RepositoryHosts
- type Server
- type SpendLedger
- type TokenVerifier
Constants ¶
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.
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.
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 ¶
EgressMain runs costroid egress and returns an exit code.
Types ¶
type ApprovalHost ¶
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 ¶
New returns the service. Now and Logger default to the real clock and the default logger.
func (*Server) ProcessWebhooks ¶
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.