Documentation
¶
Overview ¶
Package mirror keeps a one-way mirror from motte to external git remotes.
Index ¶
- Constants
- Variables
- func GitRef(stored string) (string, bool)
- func MaybeAskpass(args []string, stdout io.Writer) bool
- func StoredRef(git string) (string, bool)
- type Class
- type Clock
- type Config
- type Engine
- func (e *Engine) Deliver(ctx context.Context, body []byte, signature string) error
- func (e *Engine) Mirror(name string) (Entry, bool)
- func (e *Engine) Mirrors() []Entry
- func (e *Engine) Refs(ctx context.Context, name, after string, limit int) ([]Ref, error)
- func (e *Engine) Registry() *prometheus.Registry
- func (e *Engine) RequestReconcile(name string) bool
- func (e *Engine) RequestReset()
- func (e *Engine) Run(ctx context.Context) error
- func (e *Engine) Stats(ctx context.Context) ([]Stats, error)
- type Entry
- type GitHubApp
- type Hit
- type HookResult
- type MotteConfig
- type Options
- type Ref
- type Service
- type Stats
- type Store
Constants ¶
const ( // DefaultDiskBudget is the default size of the clone cache. DefaultDiskBudget = 20 << 30 // DefaultIdleTTL is the default idle time of a clone. DefaultIdleTTL = 168 * time.Hour )
const (
// DefaultGitHubAPI is the API base URL when the configuration names none.
DefaultGitHubAPI = "https://api.github.com"
)
Variables ¶
var ( // ErrSignature is the error of a delivery that the secret does not sign. ErrSignature = errors.New("mirror: bad signature") // ErrBody is the error of a signed delivery that is not an event. ErrBody = errors.New("mirror: bad event body") )
Functions ¶
func GitRef ¶
GitRef maps a stored ref name to the git ref name. A stored name under refs/heads/ has none.
func MaybeAskpass ¶
MaybeAskpass runs the askpass helper when the environment asks for it. It returns false for a normal start. git runs the program of GIT_ASKPASS with the prompt as its only argument, and the program is the ward binary.
Types ¶
type Clock ¶
Clock is the source of time and of waits. Inside a synctest bubble the real clock is a fake one.
type Config ¶
type Config struct {
DataDir string
Motte MotteConfig
PublicURL string
HookSecret []byte
Mirrors []Entry
// GitHubAPI is the API base URL for the GitHub App credential. Empty means DefaultGitHubAPI.
GitHubAPI string
DiskBudget int64
IdleTTL time.Duration
// Askpass is the program that git runs for the remote credential. It is the ward binary.
Askpass string
}
Config is the configuration of the engine.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs the mirror.
func (*Engine) Deliver ¶
Deliver handles one delivery of a ref event. It answers before any git work: it only records state.
func (*Engine) Registry ¶
func (e *Engine) Registry() *prometheus.Registry
Registry is the Prometheus registry of the engine.
func (*Engine) RequestReconcile ¶
RequestReconcile asks the worker of a mirror for a Reconcile. It returns at once.
func (*Engine) RequestReset ¶
func (e *Engine) RequestReset()
RequestReset asks for a Reset. It returns at once.
type Entry ¶
type Entry struct {
Name string `json:"name"`
Repo string `json:"repo"`
Remote string `json:"remote"`
Refs []string `json:"refs"`
Username string `json:"username"`
CredentialFile string `json:"credential_file,omitempty"`
GitHubApp *GitHubApp `json:"github_app,omitempty"`
PruneUnknown bool `json:"prune_unknown"`
}
Entry is one mirror of the configuration.
func ParseEntries ¶
ParseEntries decodes and checks the WARD_MIRRORS list. It rejects an unknown field.
type GitHubApp ¶
type GitHubApp struct {
AppID int64 `json:"app_id"`
InstallationID int64 `json:"installation_id"`
KeyFile string `json:"key_file"`
}
GitHubApp is a GitHub App installation that supplies the remote credential.
type HookResult ¶
type HookResult int
HookResult is how the sequence of a delivered event compares with the partition state.
const ( HookBaseline HookResult = iota HookInOrder HookRepeat HookGap )
type MotteConfig ¶
type MotteConfig struct {
URL string
Kid string
Key ed25519.PrivateKey
}
MotteConfig says how ward reaches motte and signs its grants.
type Options ¶
type Options struct {
Clock Clock
Logger *slog.Logger
// Done is called after a unit of work ends: kind is batch, reconcile, catchup, reset or init, and mirror is empty
// for work that belongs to no mirror. It must not block.
Done func(kind, mirror string)
}
Options are the parts that a caller may replace.
type Ref ¶
type Ref struct {
Mirror string
Name string
LastPartition int
LastSeq int64
Dirty bool
Version int64
DirtySince time.Time
Pushed string
PushedSet bool
Attempts int
NextAttempt time.Time
Failure Class
Message string
FailureSince time.Time
PushedAt time.Time
}
Ref is the state of one ref of one mirror. PushedSet is false while ward knows nothing about the remote value.
type Stats ¶
type Stats struct {
Mirror string
Reconciled bool
Dirty int
Failing map[Class]int
OldestDirty time.Time
}
Stats summarises the refs of one mirror.
type Store ¶
type Store interface {
Ping(ctx context.Context) error
Service(ctx context.Context) (Service, error)
// SetSubscription stores the subscription and the events cursor. With clearSeq it also clears last_seq of every partition.
SetSubscription(ctx context.Context, id, cursor string, clearSeq bool) error
// RecordHook compares the sequence of the event with its partition, stores last_seq and the triggers, and says how.
RecordHook(ctx context.Context, hit Hit, now time.Time) (HookResult, error)
// RecordPage stores the triggers of a catch-up page, last_seq where it is higher, and the new cursor.
RecordPage(ctx context.Context, hits []Hit, cursor string, now time.Time) error
// Due returns the dirty refs of a mirror that may be acted on now, and the earliest later next_attempt (zero if none).
Due(ctx context.Context, mirror string, now time.Time) ([]Ref, time.Time, error)
// RecordPush stores a push result. It clears dirty only when the version of the ref is still version.
RecordPush(ctx context.Context, mirror, ref string, version int64, pushed string, now time.Time) error
// RecordFailure counts a failed action. It moves next_attempt only when the version of the ref is still version.
RecordFailure(ctx context.Context, mirror, ref string, version int64, class Class, message string, next, now time.Time) error
SetPushed(ctx context.Context, mirror, ref, pushed string) error
// Reconciled triggers each ref of targets, sets its pushed value, and records the mirror.
Reconciled(ctx context.Context, mirror string, targets map[string]string, now time.Time) error
HasMirror(ctx context.Context, name string) (bool, error)
StateRefs(ctx context.Context, mirror string) ([]string, error)
Refs(ctx context.Context, mirror, after string, limit int) ([]Ref, error)
Stats(ctx context.Context) ([]Stats, error)
}
Store is the transactional state store. Each method that writes is one transaction.