gitrestclient

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists = stderrors.New("file already exists")

ErrAlreadyExists is returned by PostIfAbsent when the target path is already occupied (git-rest responds 409 Conflict for a create-only write). It is a benign conflict, not a transport failure — callers use errors.Is to treat it as "already there" instead of an error worth retrying.

Functions

This section is empty.

Types

type GitClient

type GitClient interface {
	// EnsureCloned clones the repo if not present, validates if already cloned.
	EnsureCloned(ctx context.Context) error
	// Pull runs git pull on the local clone.
	Pull(ctx context.Context) error
	// CommitAndPush stages all changes, creates a commit with the given message, and pushes to the remote.
	CommitAndPush(ctx context.Context, message string) error
	// AtomicWriteAndCommitPush writes content to absPath and commits+pushes under a single lock.
	// Atomicity (no interleaving with other writes) is guaranteed by the implementation:
	// - gitClient (local-disk): sync.Mutex around the whole sequence.
	// - gitRestGitClientAdapter: relies on per-task serialization (Kafka partitioning by task_id).
	AtomicWriteAndCommitPush(
		ctx context.Context,
		absPath string,
		content []byte,
		message string,
	) error
	// AtomicWriteIfAbsentAndCommitPush writes content to absPath only when no file
	// exists there yet, then commits+pushes. Returns ErrAlreadyExists (via
	// errors.Is) when the path is occupied; nothing is written in that case.
	AtomicWriteIfAbsentAndCommitPush(
		ctx context.Context,
		absPath string,
		content []byte,
		message string,
	) error
	// AtomicReadModifyWriteAndCommitPush reads absPath, calls modify on its contents
	// to produce new contents, writes the result, and commits+pushes.
	// Atomicity (no interleaving with other writes) is guaranteed by the implementation:
	// - gitClient (local-disk): sync.Mutex around the whole sequence.
	// - gitRestGitClientAdapter: relies on per-task serialization (Kafka partitioning by task_id).
	// modify must return the new file bytes or an error.
	// If modify returns an error, the file is not written and no commit is made.
	AtomicReadModifyWriteAndCommitPush(
		ctx context.Context,
		absPath string,
		modify func(current []byte) ([]byte, error),
		message string,
	) error
	// Path returns the local clone path.
	Path() string
	// ListFiles returns relative file paths under the repo root matching the single-level
	// glob pattern (e.g. "tasks/*.md"). Paths are relative to the repo root.
	ListFiles(ctx context.Context, glob string) ([]string, error)
	// ReadFile reads the file at relPath (relative to repo root, e.g. "tasks/foo.md")
	// and returns its content.
	ReadFile(ctx context.Context, relPath string) ([]byte, error)
	// WriteFile writes content to relPath (relative to repo root) on local disk.
	// It does NOT commit or push — use AtomicWriteAndCommitPush for that.
	WriteFile(ctx context.Context, relPath string, content []byte) error
}

GitClient is the interface for vault file operations used throughout the controller.

func NewGitClient

func NewGitClient(gitRestClient GitRestClient, basePath string) GitClient

NewGitClient creates a GitClient backed by git-rest HTTP calls. basePath is the logical root path used when computing relative paths (e.g. "/data/vault") — it does NOT need to exist on disk. gitRestClient is the HTTP client created by NewGitRestClient.

type GitRestClient

type GitRestClient interface {
	// Get retrieves the current content of the file at relPath.
	Get(ctx context.Context, relPath string) ([]byte, error)
	// Post writes content to relPath; git-rest auto-commits and pushes.
	Post(ctx context.Context, relPath string, content []byte) error
	// PostIfAbsent writes content to relPath only when no file exists there yet;
	// git-rest auto-commits and pushes. Returns ErrAlreadyExists (via errors.Is)
	// when relPath is already occupied — nothing is written in that case.
	PostIfAbsent(ctx context.Context, relPath string, content []byte) error
	// Delete removes the file at relPath; git-rest auto-commits and pushes.
	Delete(ctx context.Context, relPath string) error
	// List returns relative paths matching the single-level glob pattern (e.g. "tasks/*.md").
	List(ctx context.Context, glob string) ([]string, error)
	// IsReady reports whether git-rest's /readiness returns 200.
	// Returns (false, nil) when git-rest returns 503 — that is a valid not-ready state, not an error.
	// Returns (false, err) only on network failure or unexpected response.
	IsReady(ctx context.Context) (bool, error)
}

GitRestClient is the HTTP client for git-rest's /api/v1/files REST API. All paths are relative to the repo root (e.g. "tasks/foo.md").

func NewGitRestClient

func NewGitRestClient(
	baseURL, gatewaySecret, gatewayInitiator string,
	metrics metrics.Metrics,
) GitRestClient

NewGitRestClient creates a GitRestClient targeting the git-rest instance at baseURL. gatewaySecret is the shared secret enforced by git-rest's gateway-secret auth (git-rest spec 004). When gatewaySecret is empty, no auth headers are sent (backward-compat with auth-disabled git-rest). gatewayInitiator is the caller identity logged by git-rest on auth failure; pass a stable, human-readable value (e.g. "agent-task-controller").

Jump to

Keyboard shortcuts

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