Documentation
¶
Overview ¶
Package project owns project-file storage. V0.1 ships one backend (local filesystem rooted at a configured path) ; V0.2 adds a weft-block backend so per-project volumes mount into compile microVMs without round-tripping through the host filesystem.
The Store interface centralises authorization : every method takes the caller's Identity, and the implementation enforces "can this user see/edit this project". V0.1 policy : project owner subject == identity.Subject OR identity.Groups contains "loom-admin". V0.2 migrates to openweft project ACL via dex groups.
Index ¶
- Variables
- type File
- type LocalStore
- func (s *LocalStore) DeleteFile(_ context.Context, ident auth.Identity, project, path string) error
- func (s *LocalStore) List(_ context.Context, ident auth.Identity) ([]Project, error)
- func (s *LocalStore) ListFiles(_ context.Context, ident auth.Identity, project string) ([]File, error)
- func (s *LocalStore) ReadFile(_ context.Context, ident auth.Identity, project, path string) (io.ReadCloser, error)
- func (s *LocalStore) Rename(_ context.Context, ident auth.Identity, oldName, newName string) error
- func (s *LocalStore) Root() string
- func (s *LocalStore) WriteFile(_ context.Context, ident auth.Identity, project, path string, body io.Reader) (err error)
- type PostgresStore
- func (s *PostgresStore) Close()
- func (s *PostgresStore) DeleteFile(ctx context.Context, ident auth.Identity, project, path string) error
- func (s *PostgresStore) List(ctx context.Context, ident auth.Identity) ([]Project, error)
- func (s *PostgresStore) ListFiles(ctx context.Context, ident auth.Identity, project string) ([]File, error)
- func (s *PostgresStore) Pool() *pgxpool.Pool
- func (s *PostgresStore) ReadFile(ctx context.Context, ident auth.Identity, project, path string) (io.ReadCloser, error)
- func (s *PostgresStore) Rename(ctx context.Context, ident auth.Identity, oldName, newName string) error
- func (s *PostgresStore) Root() string
- func (s *PostgresStore) WriteFile(ctx context.Context, ident auth.Identity, project, path string, body io.Reader) error
- type Project
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrAccessDenied = errors.New("project: access denied")
ErrAccessDenied is returned by Store impls when the caller lacks permission. Handlers translate to 403.
var ErrInvalidName = errors.New("project: invalid name")
ErrInvalidName is returned by Rename when the destination name is empty, sanitises to empty, or matches the .weft-loom reserved sidecar prefix. Handlers translate to 400.
var ErrNotFound = errors.New("project: not found")
ErrNotFound is returned by Rename when the source project doesn't exist on disk. Handlers translate to 404.
var ErrProjectExists = errors.New("project: destination name already exists")
ErrProjectExists is returned by Rename when the destination name is already taken. Handlers translate to 409.
Functions ¶
This section is empty.
Types ¶
type LocalStore ¶
type LocalStore struct {
// contains filtered or unexported fields
}
LocalStore is the V0.1 backend : projects live under <root>/<owner>/<name>. Owner is identity.Subject ; the subject is sanitised to a safe filesystem name (alphanumeric + dash + underscore) so dex's "subject can be a URL" doesn't escape the root.
func NewLocalStore ¶
func NewLocalStore(root string) *LocalStore
NewLocalStore returns a store rooted at the given absolute path. The directory is created on first write.
func (*LocalStore) DeleteFile ¶ added in v0.4.0
DeleteFile removes <user>/<project>/<path>. Idempotent on missing paths : returns nil even if the file is already gone, so a concurrent delete from another browser tab doesn't bubble up as an error to the UI. Traversal-safe via resolveFile.
func (*LocalStore) ReadFile ¶
func (s *LocalStore) ReadFile(_ context.Context, ident auth.Identity, project, path string) (io.ReadCloser, error)
func (*LocalStore) Rename ¶ added in v0.4.0
Rename moves <root>/<owner>/<oldName> to <root>/<owner>/<newName>. The whole directory (including .weft-loom/ sidecars and the .git dir) travels atomically via os.Rename — git remains attached because git is content-addressed and the working directory name doesn't matter. Refuses if the destination already exists ; that gate is non-atomic vs concurrent Rename calls, but the second caller in a race loses on os.Rename itself (ENOTEMPTY on most filesystems) so we never silently overwrite.
func (*LocalStore) Root ¶ added in v0.4.0
func (s *LocalStore) Root() string
Root exposes the configured filesystem root for callers that need to materialise per-project paths outside the Store interface — e.g. the V0.3 git surface drives go-git directly against the working tree under <root>/<owner>/<project>. The Store interface stays backend-agnostic ; this is a deliberate LocalStore-specific extension and a future S3 backend will simply not satisfy it.
type PostgresStore ¶ added in v0.2.2
type PostgresStore struct {
// contains filtered or unexported fields
}
PostgresStore is the HA-aware project store : metadata lives in PostgreSQL (weft-ha-postgresql handles the failover / replication) and file content lives on a shared weft-block volume mounted at `filesRoot` on every loom-server replica. The two paths are kept in sync transactionally — every WriteFile bumps the projects.updated_at row in the SAME transaction as the file landing on disk via rename-or-fsync, so a crash mid-write leaves the row pointing at the previous content (or the row is rolled back).
Schema migrations run on NewPostgresStore via embedded SQL — see schema.sql. The store IS idempotent across restarts.
func NewPostgresStore ¶ added in v0.2.2
func NewPostgresStore(ctx context.Context, dsn, filesRoot string) (*PostgresStore, error)
NewPostgresStore connects to dsn, runs migrations, and returns a ready store. filesRoot is the mount point of the shared volume (typically /var/lib/weft-loom on the microVM ; the volume itself is provisioned by weft-block as a replicated 3-DC volume).
func (*PostgresStore) Close ¶ added in v0.2.2
func (s *PostgresStore) Close()
Close drops the connection pool. Safe to call multiple times.
func (*PostgresStore) DeleteFile ¶ added in v0.4.0
func (s *PostgresStore) DeleteFile(ctx context.Context, ident auth.Identity, project, path string) error
DeleteFile removes the on-disk file. Idempotent on missing paths. Doesn't bump the project's updated_at row — the V0.2 schema keeps file-level state in the filesystem ; future per-file metadata (history, last_modified_by) will move that bookkeeping here.
func (*PostgresStore) Pool ¶ added in v0.4.0
func (s *PostgresStore) Pool() *pgxpool.Pool
Pool is the connection pool this store uses, so that anything else needing the same database uses the same connections rather than opening a second pool beside it. Collaborative editing keeps its documents here; see internal/server/collab.go.
func (*PostgresStore) ReadFile ¶ added in v0.2.2
func (s *PostgresStore) ReadFile(ctx context.Context, ident auth.Identity, project, path string) (io.ReadCloser, error)
func (*PostgresStore) Rename ¶ added in v0.4.0
func (s *PostgresStore) Rename(ctx context.Context, ident auth.Identity, oldName, newName string) error
Rename moves the project row in Postgres + the working tree on disk. Both happen in one transaction so a crash mid-rename leaves either the old name or the new one in a consistent state. The UPDATE clause WHERE owner_subject=$1 doubles as the authorization check ; an attacker renaming someone else's project hits 0 rows affected and we surface ErrAccessDenied. A unique constraint on (owner_subject, name) maps a name collision to ErrProjectExists.
func (*PostgresStore) Root ¶ added in v0.4.0
func (s *PostgresStore) Root() string
Root mirrors LocalStore.Root : the materialised filesystem root. The V0.3 git surface needs a working tree on disk regardless of whether project metadata is tracked in Postgres or just on the FS.
type Project ¶
type Project struct {
Name string `json:"name"`
Language string `json:"language"`
CreatedAt time.Time `json:"created_at"`
}
Project is the summary returned by List.
type Store ¶
type Store interface {
List(ctx context.Context, ident auth.Identity) ([]Project, error)
ListFiles(ctx context.Context, ident auth.Identity, project string) ([]File, error)
ReadFile(ctx context.Context, ident auth.Identity, project, path string) (io.ReadCloser, error)
WriteFile(ctx context.Context, ident auth.Identity, project, path string, body io.Reader) error
DeleteFile(ctx context.Context, ident auth.Identity, project, path string) error
// Rename moves a project from oldName to newName for the caller.
// Implementations refuse if newName already exists and propagate
// ErrInvalidName for malformed targets. Sidecars under
// .weft-loom/ (sharing.json, owner) travel with the directory ;
// git remotes stay attached because git is content-addressed.
Rename(ctx context.Context, ident auth.Identity, oldName, newName string) error
}
Store is the storage abstraction.