vault

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package vault is an always-on project archive store for multi-device / multi- operator sync. It holds full-project zips (same layout as control's export) under a configurable directory — typically served over Tailscale Serve.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeAddr

func NormalizeAddr(addr string) string

NormalizeAddr ensures host:port (default 127.0.0.1:9977).

func ParseRev

func ParseRev(s string) (int, error)

ParseRev parses a revision path segment.

func ValidSlug

func ValidSlug(id string) bool

ValidSlug reports whether id is a safe project vault identifier.

Types

type Auth

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

Auth manages vault bearer tokens (hashed at rest).

func OpenAuth

func OpenAuth(dir string) (*Auth, error)

func (*Auth) Check

func (a *Auth) Check(authHeader string) (TokenScope, error)

Check validates Authorization bearer and returns scope.

func (*Auth) Create

func (a *Auth) Create(scope TokenScope, label string) (raw string, rec tokenRecord, err error)

Create mints a new token.

func (*Auth) EnsureBootstrap

func (a *Auth) EnsureBootstrap() (raw string, created bool, err error)

EnsureBootstrap creates a full-scope token if none exist. Returns the raw token (only shown once) and whether it was newly created.

func (*Auth) HasTokens

func (a *Auth) HasTokens() bool

HasTokens reports whether any token is configured.

type ProjectInfo

type ProjectInfo struct {
	ID           string `json:"id"`
	Revisions    int    `json:"revisions"`
	LatestRev    int    `json:"latestRev"`
	LatestSize   int64  `json:"latestSize"`
	LatestAt     int64  `json:"latestAt"`
	LatestLabel  string `json:"latestLabel,omitempty"`
	LatestSHA256 string `json:"latestSha256,omitempty"`
}

ProjectInfo is a list-row for one vault project.

type RevInfo

type RevInfo struct {
	Rev      int    `json:"rev"`
	Size     int64  `json:"size"`
	SHA256   string `json:"sha256"`
	At       int64  `json:"at"`
	Label    string `json:"label,omitempty"`
	Source   string `json:"source,omitempty"`
	Filename string `json:"filename"`
}

RevInfo describes one stored revision.

type Server

type Server struct {
	Store *Store
	Auth  *Auth
	Addr  string // listen address (set after Listen)
	// contains filtered or unexported fields
}

Server is the HTTP vault API.

func NewServer

func NewServer(st *Store, auth *Auth) *Server

NewServer builds handlers.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler exposes the mux for tests.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe binds addr and serves until ln is closed.

type Store

type Store struct {
	Dir  string
	Keep int // max revisions per project; <=0 means 10
	// contains filtered or unexported fields
}

Store is a filesystem-backed vault root.

func Open

func Open(dir string, keep int) (*Store, error)

Open initializes or loads a vault directory.

func (*Store) DeleteProject

func (s *Store) DeleteProject(id string) error

DeleteProject removes a project and all revisions.

func (*Store) DeleteRev

func (s *Store) DeleteRev(id string, rev int) error

DeleteRev removes one revision.

func (*Store) List

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

List returns every project with latest revision summary.

func (*Store) OpenRev

func (s *Store) OpenRev(id string, rev int) (io.ReadCloser, RevInfo, error)

OpenRev opens the zip for a revision (caller closes). rev<=0 means latest.

func (*Store) Put

func (s *Store) Put(id, label, source string, r io.Reader) (RevInfo, error)

Put stores r as a new revision of project id. Returns the revision metadata.

func (*Store) Revisions

func (s *Store) Revisions(id string) ([]RevInfo, error)

Revisions lists revisions for a project (oldest first).

func (*Store) Status

func (s *Store) Status() map[string]any

Status returns vault root facts for /api/vault/status.

type TokenScope

type TokenScope string

TokenScope is "full" (read+write) or "read".

const (
	ScopeFull TokenScope = "full"
	ScopeRead TokenScope = "read"
)

Jump to

Keyboard shortcuts

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