runnerproto

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 15 Imported by: 1 module, 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 runnerproto is the wire protocol between ward and a check runner: the check request that ward sends, its signature, the result that a runner posts and the token that authorizes the post. ward, `ward runner` and a runner of another author share this definition. runner.schema.json describes the JSON bodies.

Index

Constants

View Source
const (
	// LeasesPath is the route that a pull runner polls for a lease. The bearer credential is a runner token.
	LeasesPath = "/v1/runner/leases"
	// LeaseWait is the longest time that ward holds a poll open before it answers 204.
	LeaseWait = 20 * time.Second
)
View Source
const (
	// SignatureHeader carries "sha256=" and the hex HMAC-SHA256 of the request body.
	SignatureHeader = "Ward-Signature"
	// ResultsPath is the route of ward that takes a result, with a check token as the bearer credential.
	ResultsPath = "/v1/results"
	MaxSummary  = 4096
	MaxLogURL   = 2048
)

Variables

This section is empty.

Functions

func MintCheckToken

func MintCheckToken(kid string, key ed25519.PrivateKey, repo, subject string, exp time.Time) (string, error)

MintCheckToken signs a check token for repo. A runner sends it as the bearer credential of PostResult.

func MintRunnerToken

func MintRunnerToken(kid string, key ed25519.PrivateKey, subject string, exp time.Time) (string, error)

MintRunnerToken signs a runner token. A pull runner sends it as the bearer credential of a poll and of a renewal.

func PostResult

func PostResult(ctx context.Context, c *http.Client, baseURL, tok string, res Result) error

PostResult posts res to the ward at baseURL with a check token.

func RenewPath

func RenewPath(leaseID string) string

RenewPath is the route that extends the lease with the given ID.

func Sign

func Sign(secret, body []byte) string

Sign returns the value of SignatureHeader for body.

func Verify

func Verify(secret, body []byte, header string) bool

Verify reports whether header is the signature of body under secret.

Types

type Check

type Check struct {
	Name           string   `json:"name"`
	Run            []string `json:"run"`
	TimeoutSeconds int      `json:"timeout_seconds"`
}

Check is one required check. The runner runs Run at the root of the tree.

func (Check) Hash

func (c Check) Hash() string

Hash is the SHA-256, in lowercase hex, of the compact JSON object of the check.

type Isolation

type Isolation string

Isolation is the strength of the sandbox that a runner reports. A larger rank isolates more.

const (
	IsolationContainer Isolation = "container"
	IsolationGVisor    Isolation = "gvisor"
)

func (Isolation) AtLeast

func (i Isolation) AtLeast(min Isolation) bool

AtLeast reports whether i is a known level that isolates at least as much as min.

func (Isolation) Rank

func (i Isolation) Rank() int

Rank orders isolation levels. An unknown level has rank 0.

type Lease

type Lease struct {
	LeaseID    string  `json:"lease_id"`
	TTLSeconds int     `json:"ttl_seconds"`
	Request    Request `json:"request"`
}

Lease is the answer to a poll: one check request that the runner holds for TTLSeconds, and renews until it posts a result.

func PollLease

func PollLease(ctx context.Context, c *http.Client, baseURL, tok string, iso Isolation) (*Lease, error)

PollLease asks ward for a lease. It returns nil with no error when ward has no work after LeaseWait.

type LeaseRequest

type LeaseRequest struct {
	Isolation Isolation `json:"isolation"`
}

LeaseRequest is the body of a poll. Isolation is the sandbox that the runner uses for every check.

type Renewal

type Renewal struct {
	TTLSeconds int `json:"ttl_seconds"`
}

Renewal is the answer to a renewal.

func RenewLease

func RenewLease(ctx context.Context, c *http.Client, baseURL, tok, leaseID string) (Renewal, error)

RenewLease extends a lease. A final StatusError means that the runner lost the lease and must stop the check.

type Request

type Request struct {
	RequestID string `json:"request_id"`
	Repo      string `json:"repo"`
	Tree      string `json:"tree"`
	Commit    string `json:"commit"`
	Check     Check  `json:"check"`
	CheckHash string `json:"check_hash"`
	Env       string `json:"env"`
}

Request is the body that ward posts to a runner. Commit is a commit of motte whose tree is Tree.

func Decode

func Decode(body []byte) (Request, error)

Decode reads a request body. It checks that check_hash is the hash of check.

type Result

type Result struct {
	RequestID string `json:"request_id"`
	Status    Status `json:"status"`
	Summary   string `json:"summary"`
	LogURL    string `json:"log_url"`
}

Result is the body that a runner posts to ResultsPath.

type Runner

type Runner interface {
	http.Handler
}

Runner is a check runner as ward sees it: Handler serves the hook that ward posts check requests to.

type Status

type Status string

Status is the outcome that a runner reports.

const (
	Pass Status = "pass"
	Fail Status = "fail"
)

type StatusError

type StatusError struct{ Code int }

StatusError is a refusal of ward. A 4xx code other than 429 is final: the runner must not repeat the post.

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Final

func (e *StatusError) Final() bool

Final reports whether the post cannot succeed on a repeat.

Directories

Path Synopsis
Package runnertest is the conformance suite of runnerproto.Runner.
Package runnertest is the conformance suite of runnerproto.Runner.

Jump to

Keyboard shortcuts

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