config

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 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 config reads gitd's configuration, a TOML file whose every key has a default.

Index

Constants

View Source
const DefaultMountHelper = "/run/gitd-mount/gitd-mount.sock"

DefaultMountHelper is where gitd-mount answers unless the configuration says otherwise.

View Source
const DefaultPath = "/etc/gitd/gitd.toml"

DefaultPath is the configuration file read when none is given.

View Source
const DefaultSocket = "/run/gitd/gitd.sock"

DefaultSocket is where gitd answers when the configuration says nowhere else.

View Source
const DefaultState = "/var/lib/gitd"

DefaultState is where pools, templates and workspaces live unless configured.

Variables

This section is empty.

Functions

func ValidBranchPrefix

func ValidBranchPrefix(prefix string) bool

ValidBranchPrefix says whether prefix can start a branch name git accepts; empty is no prefix, and valid.

Types

type Audit

type Audit struct {
	RotateBytes int64         `toml:"rotate_bytes"`
	Keep        time.Duration `toml:"keep"`
}

Audit is how the audit log, every publish done or refused, is kept under the state directory: its file is rotated when it reaches RotateBytes, and a rotated file is deleted once older than Keep.

type Config

type Config struct {
	Socket      string       `toml:"socket"`
	State       string       `toml:"state"`
	Roots       []string     `toml:"roots"`
	Git         string       `toml:"git"`
	Metrics     string       `toml:"metrics"`
	KnownHosts  []string     `toml:"known_hosts"`
	Hosts       repo.Hosts   `toml:"hosts"`
	Credentials []Credential `toml:"credentials"`
	// SecretsKeyFile names the key the secrets of connections made through the API are
	// encrypted with, under the state directory: 32 bytes, raw, hex or base64, best a
	// systemd credential. Without one they are kept in files only gitd's user reads.
	SecretsKeyFile string `toml:"secrets_key_file"`

	GitHub       GitHub       `toml:"github"`
	Workspaces   Workspaces   `toml:"workspaces"`
	Publish      Publish      `toml:"publish"`
	Audit        Audit        `toml:"audit"`
	Limits       Limits       `toml:"limits"`
	Housekeeping Housekeeping `toml:"housekeeping"`
	Endpoint     Endpoint     `toml:"endpoint"`
	// Tenants are the customers of a platform hosting many on one gitd, each isolated from
	// the others; without any, gitd is one implicit tenant, as before 0.9.
	Tenants []Tenant `toml:"tenants"`
	// APIKeyFile is the key a caller on the network brings when there are no tenants; its
	// network address answers the API only with one.
	APIKeyFile string `toml:"api_key_file"`
}

Config is how one gitd runs: the Unix socket it answers on, the State directory that holds its pools, lock files and host keys, the Roots that are the only directories a workspace may be made in, the Git binary it runs, where Metrics are served, if anywhere, and the KnownHosts files whose SSH host keys are trusted besides the ones built in (GitHub, GitLab, Bitbucket and Codeberg): a self-hosted GitLab, Gitea or Forgejo goes there; and the Hosts reached on other ports, or over SSH as another user, than the usual ones: `[hosts."git.example.com"] https_port = 3000, ssh_port = 2222`. A host whose SSH is on another port has its key in a known_hosts file as `[git.example.com]:2222 ssh-ed25519 …`.

func Default

func Default() Config

Default is the configuration every key falls back to.

func Load

func Load(path string) (Config, error)

Load reads the file at path over the defaults. A file that is not there is the defaults.

func (Config) AuditLog

func (settings Config) AuditLog() string

AuditLog is where the audit log is kept.

func (Config) Connections

func (settings Config) Connections() string

Connections is where the connections made through the API are kept.

func (Config) ForTenant

func (settings Config) ForTenant(tenant Tenant) Config

ForTenant is the configuration a tenant's part of gitd runs with: gitd's own, with the tenant's state directory, roots and credentials, and its fetches.

func (Config) HasTenants

func (settings Config) HasTenants() bool

HasTenants says whether gitd serves tenants; without, it is one implicit tenant, as before.

func (Config) Locks

func (settings Config) Locks() string

Locks is where the lock files live.

func (Config) Pools

func (settings Config) Pools() string

Pools is where the pools live.

func (Config) PublishingSettings

func (settings Config) PublishingSettings() string

PublishingSettings is where the publishing settings set through the API are kept.

func (Config) Sandboxes

func (settings Config) Sandboxes() string

Sandboxes is where the sandbox repositories of the endpoint live.

func (Config) Templates

func (settings Config) Templates() string

Templates is where the templates copy-on-write workspaces are made from live.

type Credential

type Credential struct {
	Prefix    string     `toml:"prefix"`
	TokenFile string     `toml:"token_file"`
	TokenEnv  string     `toml:"token_env"`
	TokenUser string     `toml:"token_user"`
	SSHKey    string     `toml:"ssh_key"`
	GitHubApp *GitHubApp `toml:"github_app"`
}

Credential is one credential gitd keeps for the repositories under Prefix (empty for any), so that a caller need not send it: a token read from TokenFile or from the environment variable TokenEnv, sent as TokenUser, the SSH key at SSHKey, or a GitHub App whose installation tokens open one repository each. The configuration names where the secret is, never the secret: a TokenFile or an App's key is best a systemd credential (`LoadCredential=`), which lives in memory.

type Endpoint

type Endpoint struct {
	Listen       string `toml:"listen"`
	URL          string `toml:"url"`
	TLSCertFile  string `toml:"tls_cert_file"`
	TLSKeyFile   string `toml:"tls_key_file"`
	MaxPushBytes int64  `toml:"max_push_bytes"`
}

Endpoint is gitd's network address, off unless Listen is set: sandboxes that cannot mount its directories clone and push there with tokens of gitd's own. URL is the address they are given, e.g. `https://gitd.internal:9420`, by default Listen's; TLSCertFile and TLSKeyFile serve it over TLS, without which it should be on a private network only; and MaxPushBytes bounds one push.

func (Endpoint) TLS

func (endpoint Endpoint) TLS() bool

TLS says whether the endpoint is served over TLS.

type GitHub

type GitHub struct {
	LoginClientID string `toml:"login_client_id"`
	LoginApp      string `toml:"login_app"`
}

GitHub is gitd's public GitHub App, which people sign in through: its client ID, which is not a secret, and its name in addresses. A GitHub Enterprise Server needs an App of its own, registered there.

type GitHubApp

type GitHubApp struct {
	AppID          int64  `toml:"app_id"`
	PrivateKeyFile string `toml:"private_key_file"`
}

GitHubApp is a GitHub App by its ID and the file of its private key, read each time it signs, so replacing the file rotates the key.

type Housekeeping

type Housekeeping struct {
	Every       time.Duration `toml:"every"`
	RetireAfter time.Duration `toml:"retire_after"`
	StaleLock   time.Duration `toml:"stale_lock"`
	SweepDepth  int           `toml:"sweep_depth"`
	// TemplateGrace is how long a template no workspace uses is kept, in case one is made
	// from it again soon.
	TemplateGrace time.Duration `toml:"template_grace"`
}

Housekeeping is how often the pools are maintained, how long a pool no workspace borrows from is kept, how old a git `.lock` must be to be taken as left behind, and how many directories below a root the deepest workspace sits, which is how far down a start-up looks for what a crash left half built.

type Limits

type Limits struct {
	Fetches   int           `toml:"fetches"`
	Writes    int           `toml:"writes"`
	Queued    int           `toml:"queued"`
	QueueWait time.Duration `toml:"queue_wait"`
	Operation time.Duration `toml:"operation"`
}

Limits bound how much gitd does at once and for how long: fetches and writes running, operations queued behind them and for how long, and how long one call may take.

type Publish

type Publish struct {
	BranchPrefix string           `toml:"branch_prefix"`
	Presets      []PublishPreset  `toml:"presets"`
	Settings     []PublishSetting `toml:"settings"`
}

Publish is the rules of publishing. BranchPrefix, when set, is what every published branch must start with, e.g. "agents/": with publishing already limited to new branches and never forced, it keeps agents off every branch people use. Settings are the rules of the repositories under a prefix, and Presets the named sets of rules settings take, as the API's PublishingService sets them; those of the file are shown by the API and never changed through it.

type PublishPreset

type PublishPreset struct {
	Name            string   `toml:"name"`
	ProtectedPaths  []string `toml:"protected_paths"`
	KeptPaths       []string `toml:"kept_paths"`
	MaxChangedFiles *int32   `toml:"max_changed_files"`
}

PublishPreset is a named set of rules: paths a publish may not change, paths it may not delete, and at most how many files it may change. One named "recommended" replaces gitd's.

type PublishSetting

type PublishSetting struct {
	Prefix          string       `toml:"prefix"`
	Preset          string       `toml:"preset"`
	ProtectedPaths  []string     `toml:"protected_paths"`
	KeptPaths       []string     `toml:"kept_paths"`
	AllowedPaths    []string     `toml:"allowed_paths"`
	MaxChangedFiles *int32       `toml:"max_changed_files"`
	BranchPrefix    string       `toml:"branch_prefix"`
	PullRequests    PullRequests `toml:"pull_requests"`
}

PublishSetting is the rules of publishing for the repositories under Prefix (empty for every one): the Preset it takes, by name, paths a publish may not change and paths it may not delete, as git's glob pathspecs, paths its own rules leave free, at most how many files it may change, the branch prefix, and how pull requests are opened.

type PullRequests

type PullRequests struct {
	Open                       string   `toml:"open"`
	Draft                      bool     `toml:"draft"`
	Labels                     []string `toml:"labels"`
	RequestReviewFromRequester bool     `toml:"request_review_from_requester"`
}

PullRequests is how publishes open pull requests: Open is "when_asked" or "always", and RequestReviewFromRequester asks the person a publish names to review it.

type Tenant

type Tenant struct {
	Name        string       `toml:"name"`
	APIKeyFile  string       `toml:"api_key_file"`
	Roots       []string     `toml:"roots"`
	Limits      TenantLimits `toml:"limits"`
	Credentials []Credential `toml:"credentials"`
}

Tenant is one customer of a platform that hosts many on one gitd. Each has its own key the platform calls with, its own roots, credentials and limits, and its own pools, templates, workspaces, tokens and audit log, under `<state>/tenants/<name>`: nothing is shared between tenants.

type TenantLimits

type TenantLimits struct {
	Workspaces int    `toml:"workspaces"`
	Disk       string `toml:"disk"`
	Fetches    int    `toml:"fetches"`
	// Sandboxes is how many sandbox repositories of the endpoint it may hold at once.
	Sandboxes int `toml:"sandboxes"`
}

TenantLimits keep one tenant from starving the others: at most Workspaces workspaces, Disk of pools, templates and layers ("50GB", "500MB"; measured each maintenance round), and Fetches reaching the network at once. Zero is no limit, and for Fetches gitd's own.

func (TenantLimits) DiskBytes

func (limits TenantLimits) DiskBytes() (int64, error)

DiskBytes is the disk limit in bytes, zero for none.

type Workspaces

type Workspaces struct {
	Strategy string `toml:"strategy"`
	// MountHelper is the socket of gitd-mount, which mounts overlays for a gitd that may
	// not; the default is used when it exists.
	MountHelper string `toml:"mount_helper"`
}

Workspaces is how new workspaces are made. Strategy "" (or "auto") lets gitd pick: an overlay on a shared template when one can be mounted, else every file written; "overlay" and "copy" ask for one, and "reflink" clones the template to save disk, not time.

Jump to

Keyboard shortcuts

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