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 ¶
- 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 Config
- type Ledger
- type Server
- type SpendLedger
- type TokenVerifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EgressMain ¶
EgressMain runs costroid egress and returns an exit code.
Types ¶
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
Now func() time.Time
Logger *slog.Logger
}
Config wires a Server.
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 Server ¶
type Server struct {
Config
}
Server handles ingest and the view.
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.