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
- func Secret(request *http.Request) string
- type Handler
- type Sandbox
- type Sandboxes
- func (sandboxes *Sandboxes) All() []string
- func (sandboxes *Sandboxes) Get(ctx context.Context, id string) (Sandbox, error)
- func (sandboxes *Sandboxes) Make(ctx context.Context, repository repo.Repo, branch string) (Sandbox, error)
- func (sandboxes *Sandboxes) Measure()
- func (sandboxes *Sandboxes) Path(id string) string
- func (sandboxes *Sandboxes) Remove(ctx context.Context, id string) error
- func (sandboxes *Sandboxes) Retire(ctx context.Context, unusedFor time.Duration, tokens *Tokens) int
- func (sandboxes *Sandboxes) RetireEvery(ctx context.Context, every, unusedFor time.Duration, tokens *Tokens)
- func (sandboxes *Sandboxes) Used() int64
- type Token
- type Tokens
- func (tokens *Tokens) Alive() []Token
- func (tokens *Tokens) Check(secret string) (Token, bool)
- func (tokens *Tokens) Issue(repository repo.Repo, sandbox string, writable bool, life time.Duration) (string, Token, error)
- func (tokens *Tokens) Revoke(id string) (Token, bool)
- func (tokens *Tokens) RevokeSandbox(sandbox string)
Constants ¶
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 )
const DefaultMaxPush int64 = 1 << 30
DefaultMaxPush is the most a push may send when the configuration says nothing.
const Prefix = "/git/"
Prefix is where the endpoint answers: `<prefix><host>/<path>.git`, as a sandbox clones it.
Variables ¶
This section is empty.
Functions ¶
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 ¶
NewHandler returns the endpoint over these sandboxes, opened by these tokens, taking pushes of at most maxPush bytes.
func (*Handler) Opens ¶
Opens says whether secret is a token of this endpoint, so that one listener can serve the endpoints of several tenants.
type Sandbox ¶
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 ¶
NewSandboxes returns the sandbox repositories under dir.
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 ¶
Path is where the sandbox repository with this ID is, whether it exists or not.
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.
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 (*Tokens) Alive ¶
Alive are the tokens still alive, the soonest to expire first; expired ones are forgotten on the way.
func (*Tokens) Check ¶
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) RevokeSandbox ¶
RevokeSandbox ends every token of a sandbox repository, as when it is removed.