cachebroker

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemaVersion     = 1
	MaximumConfigSize = 256 * 1024
	DefaultConfigPath = "/etc/gha-fleet/cache-broker.yaml"
)
View Source
const (
	ClaimPath  = "/api/v1/cache/claim"
	HealthPath = "/healthz"
)
View Source
const (
	JournalSchemaVersion = 1

	ClaimTokenBytes = 32
	ClaimTTL        = 15 * time.Minute
)

Variables

This section is empty.

Functions

func HashToken

func HashToken(token []byte) string

func ValidateClaimEndpoint

func ValidateClaimEndpoint(value string) error

Types

type Claim

type Claim struct {
	InstanceName      string    `json:"instance_name"`
	PoolName          string    `json:"pool_name"`
	Role              string    `json:"role"`
	TokenSHA256       string    `json:"token_sha256"`
	CreatedAt         time.Time `json:"created_at"`
	ExpiresAt         time.Time `json:"expires_at"`
	ClaimedRepository string    `json:"claimed_repository,omitempty"`
	ClaimedAt         time.Time `json:"claimed_at,omitempty"`
}

type ClaimRequest

type ClaimRequest struct {
	InstanceName  string `json:"instance_name"`
	RunnerName    string `json:"runner_name"`
	Repository    string `json:"repository"`
	RepositoryID  int64  `json:"repository_id,omitempty"`
	WorkflowRunID int64  `json:"workflow_run_id,omitempty"`
	RunAttempt    int64  `json:"run_attempt,omitempty"`
	JobName       string `json:"job_name,omitempty"`
	WorkflowRef   string `json:"workflow_ref,omitempty"`
	CommitSHA     string `json:"commit_sha,omitempty"`
	Token         string `json:"claim_token"`
}

type Config

type Config struct {
	SchemaVersion int          `yaml:"schema_version" json:"schema_version"`
	ListenAddress string       `yaml:"listen_address" json:"listen_address"`
	Endpoint      string       `yaml:"endpoint" json:"endpoint"`
	Region        string       `yaml:"region" json:"region"`
	Bucket        string       `yaml:"bucket" json:"bucket"`
	CAFile        string       `yaml:"ca_file" json:"ca_file"`
	JournalFile   string       `yaml:"journal_file" json:"journal_file"`
	JournalLock   string       `yaml:"journal_lock_file" json:"journal_lock_file"`
	Repositories  []Repository `yaml:"repositories" json:"repositories"`
}

func Load

func Load(path string) (Config, error)

func (Config) Delivery

func (c Config) Delivery(repository, role string) (Repository, Identity, bool)

func (Config) Identity

func (c Config) Identity(repository, role string) (Identity, bool)

func (Config) Validate

func (c Config) Validate() error

type Delivery

type Delivery struct {
	SchemaVersion int    `json:"schema_version"`
	DeliveryID    string `json:"delivery_id"`
	Role          string `json:"role"`
	Mode          string `json:"mode"`
	Endpoint      string `json:"endpoint"`
	Region        string `json:"region"`
	Bucket        string `json:"bucket"`
	PrefixRoot    string `json:"prefix_root"`
	AccessKey     string `json:"access_key"`
	SecretKeyB64  string `json:"secret_key_b64"`
	CAPEMB64      string `json:"ca_pem_b64"`
}

type Handler

type Handler struct {
	Config Config
	Store  Store
	Logger *slog.Logger
	Now    func() time.Time
}

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type Identity

type Identity struct {
	Role          string `yaml:"role" json:"role"`
	Mode          string `yaml:"mode" json:"mode"`
	Prefix        string `yaml:"prefix" json:"prefix"`
	AccessKeyFile string `yaml:"access_key_file" json:"access_key_file"`
	SecretKeyFile string `yaml:"secret_key_file" json:"secret_key_file"`
}

type Journal

type Journal struct {
	SchemaVersion int              `json:"schema_version"`
	Generation    uint64           `json:"generation"`
	UpdatedAt     time.Time        `json:"updated_at"`
	Claims        map[string]Claim `json:"claims"`
}

func (Journal) Validate

func (j Journal) Validate() error

type Repository

type Repository struct {
	Name   string     `yaml:"name" json:"name"`
	Bucket string     `yaml:"bucket,omitempty" json:"bucket,omitempty"`
	Roles  []Identity `yaml:"roles" json:"roles"`
}

type Store

type Store struct {
	Path, LockPath string
	Now            func() time.Time
}

func (Store) Add

func (s Store) Add(ctx context.Context, instance, pool, role string, token []byte) error

func (Store) Consume

func (s Store) Consume(ctx context.Context, instance string, token []byte, repository string) (Claim, error)

func (Store) Read

func (s Store) Read(ctx context.Context) (Journal, error)

func (Store) Remove

func (s Store) Remove(ctx context.Context, instance string) error

func (Store) Verify

func (s Store) Verify(ctx context.Context, instance string, token []byte) (Claim, error)

Jump to

Keyboard shortcuts

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