gitstore

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package gitstore persists per-app repo-path GitOps config (plan §7.6): the repo URL/ref/paths, the FSM state (deployed/staged commit, update_state), and the secret material (PAT/deploy-key, webhook HMAC secret) AES-256-GCM at rest. The webhook token is stored only as a SHA-256 hash; the token itself is never persisted or logged.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidMooringFile

func ValidMooringFile(name string) bool

ValidMooringFile reports whether name is an acceptable per-app mooring file.

Types

type Config

type Config struct {
	Project        string
	RepoURL        string
	Ref            string
	ComposePath    string
	DockerfilePath string
	MooringFile    string // repo-relative mooring file driving this app (default mooring.yaml)
	AutoDeploy     bool
	BuildPolicy    string
	CredKind       string // "" | token | ssh
	DeployedCommit string
	StagedCommit   string
	UpdateState    string
	CommitsBehind  int
	LastFetchAt    int64
	LastFetchError string
	HasWebhook     bool
}

Config is one repo app's GitOps configuration + state.

type GitHubConn

type GitHubConn struct {
	Login string
	Token string
}

GitHubConn is the operator's GitHub OAuth connection (account-level; one row). The token is held encrypted at rest and used only to list repos + install per-repo read-only deploy keys — never for day-to-day fetching.

type SaveInput

type SaveInput struct {
	Project        string
	RepoURL        string
	Ref            string
	ComposePath    string
	DockerfilePath string
	MooringFile    string // "" keeps the stored value (or defaults to mooring.yaml on insert)
	AutoDeploy     bool
	BuildPolicy    string
	// NewCred tri-state: nil keeps, "" clears, value replaces.
	NewCred    *string
	CredKind   string // token | ssh (when NewCred set)
	KnownHosts string // ssh only
}

SaveInput is an operator's repo-app config edit.

type Store

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

Store persists GitOps config.

func New

func New(db *store.DB, cipher *secret.Cipher) *Store

New builds a Store.

func (*Store) Creds

func (s *Store) Creds(project string) (git.Creds, error)

Creds returns decrypted fetch credentials for a project.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, project string) error

Delete removes an app's entire GitOps row — repo config, deploy FSM, the encrypted fetch credential, and the webhook material all live on this one row, so the row delete fully purges them. Used by the app-delete teardown.

func (*Store) DeleteGitHubConn

func (s *Store) DeleteGitHubConn(ctx context.Context) error

DeleteGitHubConn removes the connection (operator clicks Disconnect). Existing per-repo deploy keys keep working — they don't depend on this token.

func (*Store) Get

func (s *Store) Get(project string) (Config, bool, error)

Get returns a repo app's config (no secret material).

func (*Store) GitHubConn

func (s *Store) GitHubConn(ctx context.Context) (conn GitHubConn, ok bool, err error)

GitHubConn loads the connection (ok=false when none is configured). The decrypted token never leaves this layer except to the GitHub client.

func (*Store) List

func (s *Store) List() ([]Config, error)

List returns all repo apps. It selects every column in ONE query and scans each row directly — it must NOT call Get() inside the row loop. The DB pool is capped at a single connection (store.SetMaxOpenConns(1)), so a nested query issued while these rows are still open self-deadlocks: the open rows pin the only connection and the nested query waits forever for a connection that never frees, stranding the pool and hanging every subsequent request (session validation included).

func (*Store) RotateWebhook

func (s *Store) RotateWebhook(ctx context.Context, project string) (token string, err error)

RotateWebhook generates a new webhook token (returned once) + HMAC secret, storing only the token hash + the encrypted secret.

func (*Store) Save

func (s *Store) Save(ctx context.Context, in SaveInput) error

Save validates + upserts a repo app's config (URL through the SSRF allowlist).

func (*Store) SaveGitHubConn

func (s *Store) SaveGitHubConn(ctx context.Context, login, token string) error

SaveGitHubConn upserts the single GitHub connection (token encrypted at rest).

func (*Store) SetDeployed

func (s *Store) SetDeployed(ctx context.Context, project, sha string)

SetDeployed records a successful deploy (pins deployed_commit, FSM up_to_date).

func (*Store) SetFetchError

func (s *Store) SetFetchError(ctx context.Context, project, classified string)

SetFetchError records a classified fetch error (never raw git stderr).

func (*Store) SetFetchResult

func (s *Store) SetFetchResult(ctx context.Context, project, stagedSha string, behind int, state string)

SetFetchResult records a successful fetch outcome + FSM transition.

func (*Store) SetState

func (s *Store) SetState(ctx context.Context, project, state string)

SetState transitions the FSM (e.g. deploying, update_blocked).

func (*Store) WebhookLookup

func (s *Store) WebhookLookup(token string) (project string, hmacSecret []byte, ok bool)

WebhookLookup resolves a token to its project + decrypted HMAC secret.

Jump to

Keyboard shortcuts

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