gitrest

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: BSD-2-Clause Imports: 10 Imported by: ? 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 gitrest is the write half of the API. It hands a fully rendered file to the vault's git-rest service, which commits and pushes it as the vault's own git identity. The API never touches git itself and the vault volume stays mounted read-only.

Index

Constants

View Source
const HeaderGatewayInitator = "X-Gateway-Initator"

HeaderGatewayInitator is the caller-identity header git-rest's auth middleware requires to be non-empty — it answers 500 when the header is missing, before it ever checks the secret. The misspelling (missing the second "i") is deliberate and part of git-rest's frozen public contract, so it is reproduced verbatim.

View Source
const HeaderGatewaySecret = "X-Gateway-Secret"

HeaderGatewaySecret is the header git-rest reads the shared secret from.

View Source
const Initiator = "vault-api"

Initiator is the value this client sends in HeaderGatewayInitator. git-rest only checks that the header is non-empty; the value is what its request log records as the caller.

Variables

View Source
var ErrClaimConflict = stderrors.New("claim ref conflict")

ErrClaimConflict is returned when git-rest's compare-and-swap rejects a claim ref write because another holder won the race. It is a benign, expected outcome — the caller asked for a claim someone else holds — so handlers map it to 409 rather than reporting it as a failure of this API.

Functions

This section is empty.

Types

type ClaimRef added in v0.14.0

type ClaimRef struct {
	Ref        string `json:"ref"`
	SHA        string `json:"sha"`
	Cluster    string `json:"cluster"`
	TaskID     string `json:"task_id"`
	LeaseUntil string `json:"lease_until"`
}

ClaimRef is one claim ref as git-rest reports it. The field names are git-rest's, reproduced verbatim: this type is the wire shape, not the typed API's vocabulary.

type ClaimRefRequest added in v0.14.0

type ClaimRefRequest struct {
	ExpectedSHA string `json:"expected_sha"`
	Cluster     string `json:"cluster"`
	TaskID      string `json:"task_id"`
	LeaseUntil  string `json:"lease_until"`
}

ClaimRefRequest is the create/renew body. An empty ExpectedSHA means the ref must not exist yet — that is git-rest's compare-and-swap, and it is what makes exactly one of several concurrent acquirers win.

type Client

type Client interface {
	// WriteFile replaces path with content. git-rest answers {"ok":true} and no
	// SHA, so the resulting commit is identified afterwards from git log, never
	// from this call's response.
	WriteFile(ctx context.Context, path string, content []byte) error
}

Client writes one complete file through git-rest.

func NewClient

func NewClient(baseURL string, gatewaySecret string, httpClient *http.Client) Client

NewClient returns a Client that posts to baseURL. gatewaySecret is sent as X-Gateway-Secret; an empty secret sends no header, matching a git-rest instance started without one.

type RefClient added in v0.14.0

type RefClient interface {
	// PutClaimRef creates or renews the claim at key. Returns ErrClaimConflict
	// when the compare-and-swap loses.
	PutClaimRef(ctx context.Context, key string, request ClaimRefRequest) (ClaimRef, error)
	// ListClaimRefs returns every claim ref under prefix, read live from the
	// origin.
	ListClaimRefs(ctx context.Context, prefix string) ([]ClaimRef, error)
	// DeleteClaimRef releases the claim at key. expectedSHA is mandatory and is
	// the compare-and-swap token; a stale one returns ErrClaimConflict.
	DeleteClaimRef(ctx context.Context, key string, expectedSHA string) error
}

RefClient reads and writes claim refs through git-rest. It is separate from Client because the two talk to different routes and answer different errors: a file write either lands or fails, while a claim write has a third outcome — it lost the race — that callers must be able to distinguish.

func NewRefClient added in v0.14.0

func NewRefClient(baseURL string, gatewaySecret string, httpClient *http.Client) RefClient

NewRefClient returns a RefClient that talks to baseURL. It shares the gateway headers with NewClient: git-rest refuses a request that carries no initiator, and checks the secret only when one is configured.

type StatusError

type StatusError struct {
	StatusCode int
	Body       string
}

StatusError is a non-2xx answer from git-rest. The handler maps it to the status the caller should see, so a refusal upstream is not reported as a failure of this API.

func (*StatusError) Error

func (e *StatusError) Error() string

Error returns the git-rest status and the body it answered with.

Jump to

Keyboard shortcuts

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