endpoint

package
v0.15.1 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: 23 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 endpoint is gitd's git endpoint: sandboxes that cannot mount gitd's directories clone and push over smart HTTP, with tokens of gitd's own that open one repository each, never the git host's credential.

A token opens one repository for reading and one sandbox repository for writing. The sandbox repository borrows the pool's objects and takes the sandbox's pushes; publishing takes a branch from it to the git host through the same checks as publishing a workspace. Tokens are kept hashed, in memory only, and expire.

Index

Constants

View Source
const (
	// DefaultLife is how long a token lives when its caller says nothing, and MaxLife the
	// longest it may live: a leaked token opens little, for little time.
	DefaultLife = time.Hour
	MaxLife     = 24 * time.Hour
)
View Source
const DefaultMaxPush int64 = 1 << 30

DefaultMaxPush is the most a push may send when the configuration says nothing.

View Source
const Prefix = "/git/"

Prefix is where the endpoint answers: `<prefix><host>/<path>.git`, as a sandbox clones it.

Variables

This section is empty.

Functions

func Secret

func Secret(request *http.Request) string

Secret is the token a request brings: the password of its basic authentication, as git sends what a clone URL carries, or its user when no password came, or a bearer token.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler answers git's smart HTTP for the sandbox repositories, to whoever brings a token: the repository in the address must be the token's, and only a token that may write may push. Nothing else is served — no dumb protocol, no browsing.

func NewHandler

func NewHandler(runner *git.Runner, tokens *Tokens, sandboxes *Sandboxes, maxPush int64) *Handler

NewHandler returns the endpoint over these sandboxes, opened by these tokens, taking pushes of at most maxPush bytes.

func (*Handler) Opens

func (handler *Handler) Opens(secret string) bool

Opens says whether secret is a token of this endpoint, so that one listener can serve the endpoints of several tenants.

func (*Handler) ServeHTTP

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

func (*Handler) UseLimits

func (handler *Handler) UseLimits(limits interface{ WithinDisk() error })

UseLimits refuses pushes once limits say the tenant's disk is full.

type Sandbox

type Sandbox struct {
	ID         string
	Repository repo.Repo
	Made       time.Time
}

Sandbox is one sandbox repository: its ID, the repository it is of, and when it was made.

type Sandboxes

type Sandboxes struct {
	Dir string
	// contains filtered or unexported fields
}

Sandboxes are the sandbox repositories under Dir: one bare repository per sandbox, borrowing its pool's objects, holding the pool's branches as they were when it was made and whatever the sandbox pushed. gitd writes their configuration; a sandbox reaches them only through git's smart HTTP, which cannot.

func NewSandboxes

func NewSandboxes(dir string, runner *git.Runner, pools *pool.Pools) *Sandboxes

NewSandboxes returns the sandbox repositories under dir.

func (*Sandboxes) All

func (sandboxes *Sandboxes) All() []string

All are the IDs of every sandbox repository.

func (*Sandboxes) Get

func (sandboxes *Sandboxes) Get(ctx context.Context, id string) (Sandbox, error)

Get reads back the sandbox repository with this ID.

func (*Sandboxes) Make

func (sandboxes *Sandboxes) Make(ctx context.Context, repository repo.Repo, branch string) (Sandbox, error)

Make makes a sandbox repository of repository, whose pool must hold what it should show: its branches and tags are taken from the pool, its objects borrowed from it. A clone of it starts on branch, or on the repository's default branch when branch is empty.

func (*Sandboxes) Measure

func (sandboxes *Sandboxes) Measure()

Measure finds what disk the sandbox repositories take, which counts toward a tenant's disk limit.

func (*Sandboxes) Path

func (sandboxes *Sandboxes) Path(id string) string

Path is where the sandbox repository with this ID is, whether it exists or not.

func (*Sandboxes) Remove

func (sandboxes *Sandboxes) Remove(ctx context.Context, id string) error

Remove deletes a sandbox repository, and takes it off its pool.

func (*Sandboxes) Retire

func (sandboxes *Sandboxes) Retire(ctx context.Context, unusedFor time.Duration, tokens *Tokens) int

Retire removes the sandbox repositories no token alive holds and nothing has pushed to for unusedFor, and says how many.

func (*Sandboxes) RetireEvery

func (sandboxes *Sandboxes) RetireEvery(ctx context.Context, every, unusedFor time.Duration, tokens *Tokens)

RetireEvery removes, every so often until ctx ends, the sandbox repositories no token alive holds and nothing has pushed to for unusedFor.

func (*Sandboxes) Used

func (sandboxes *Sandboxes) Used() int64

Used is the disk the sandbox repositories took when last measured.

type Token

type Token struct {
	ID         string
	Repository repo.Repo
	Sandbox    string
	Writable   bool
	Issued     time.Time
	Expires    time.Time
}

Token is what a token opens, never the token itself: its ID, which can be shown and revoked by, the repository it reads, the sandbox repository it writes to when Writable, and when it stops opening anything.

type Tokens

type Tokens struct {
	// contains filtered or unexported fields
}

Tokens are the tokens issued and not yet expired or revoked, by the hash of their secret.

func NewTokens

func NewTokens() *Tokens

NewTokens returns an empty set of tokens.

func (*Tokens) Alive

func (tokens *Tokens) Alive() []Token

Alive are the tokens still alive, the soonest to expire first; expired ones are forgotten on the way.

func (*Tokens) Check

func (tokens *Tokens) Check(secret string) (Token, bool)

Check answers what the token with this secret opens, if it is one and still alive.

func (*Tokens) Issue

func (tokens *Tokens) Issue(repository repo.Repo, sandbox string, writable bool, life time.Duration) (string, Token, error)

Issue makes a token for repository and its sandbox repository, living life (DefaultLife when zero, never longer than MaxLife), and answers its secret, shown this once.

func (*Tokens) Revoke

func (tokens *Tokens) Revoke(id string) (Token, bool)

Revoke ends the token with this ID, and says whether there was one.

func (*Tokens) RevokeSandbox

func (tokens *Tokens) RevokeSandbox(sandbox string)

RevokeSandbox ends every token of a sandbox repository, as when it is removed.

Jump to

Keyboard shortcuts

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