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 ¶
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.
const HeaderGatewaySecret = "X-Gateway-Secret"
HeaderGatewaySecret is the header git-rest reads the shared secret from.
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 ¶
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"`
// SpawnedAt is absent on a claim whose holder has not created its Job, and on
// every claim written before git-rest carried the field. It is the evidence a
// peer uses to tell a holder that ran the task from one that only held the key.
SpawnedAt string `json:"spawned_at,omitempty"`
}
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"`
// SpawnedAt is written only when the holder records that it created the
// claim's Job. Omitting it leaves the key out of the stored payload.
SpawnedAt string `json:"spawned_at,omitempty"`
}
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.
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
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 ¶
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.