mountset

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 33 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mountset is the set of mounts an agni server or CLI serves, over goapplib storage's mounts registry (agni issue 1759). It reads the --mount and --mount-root flags into fixed folder mounts, keeps the runtime mounts CreateMount makes in --store, resolves a mount:// URI to a host path for the OS-backed adapters, and maps the library's errors onto agni's service errors. The library keeps every path inside its mount. The package is outside internal/ so an embedder can serve the same mounts (C13), and so the datasheet service, a module of its own, can import it (agni issue 744).

Index

Constants

View Source
const BlobsDir = "blobs"

BlobsDir is the folder under --uploads that holds every blob, laid out as goapplib's blobs.Dir keeps them.

View Source
const ConnectionsDir = "connections"

ConnectionsDir is the folder under --store that holds the connections private sources are read through (agni issue 1724). agni serve writes it, and agnids reads it.

View Source
const RecordsDir = "mounts"

RecordsDir is the folder under --store that holds one record per runtime mount.

View Source
const SnapshotsDir = "mounts"

SnapshotsDir is the folder under --uploads that holds the views of runtime mounts. A view is <uploads>/mounts/<name>/<commit>/, hard links to the blobs laid out as the source had them.

View Source
const UserTokensDir = "usertokens"

UserTokensDir is the folder under --store that holds people's own tokens, each sealed under --connections-key (agni issue 1728).

Variables

This section is empty.

Functions

func Discover

func Discover(root string) ([]mounts.Mount, error)

Discover turns each immediate SUBDIRECTORY of root into a mount named after it, so a container can expose design folders by bind-mounting them under one path with no flags (`-v ~/boards:/workspace/boards`). Parse is the explicit half, and Merge combines the two.

A missing root is NOT an error and returns no mounts, because the container always passes --mount-root and one with nothing bind-mounted should still start. A root that is a file is an error. Order is os.ReadDir's (sorted by filename), so ListMounts is stable across restarts. Non-directories and dotfiles (.DS_Store, .git) are skipped.

func Err

func Err(err error) error

Err maps an error from goapplib's storage module onto agni's service errors, so the transport classifies it as it classifies agni's own. An error that wraps none of the library's sentinels passes through unchanged. The message is kept.

A Git LFS object the driver couldn't read is FAILED_PRECONDITION, whatever reason ErrLFS wraps with it, since the mount and the file exist and the message names the file (agni issue 1809).

func Find

func Find(ms []mounts.Mount, name string) (mounts.Mount, bool)

Find returns the mount with the given name from a set of mounts.

func Folder

func Folder(name, dir string) mounts.Mount

Folder is the fixed mount that serves dir, an absolute path, as name.

func Merge

func Merge(discovered, explicit []mounts.Mount) []mounts.Mount

Merge combines discovered mounts with explicitly configured ones. Explicit wins a name collision. The operator typed --mount for this run, and a discovered mount is whatever sat under the mount root. Order is discovered then explicit, so ListMounts is stable.

func Parse

func Parse(specs []string) ([]mounts.Mount, error)

Parse turns repeated `name=path` flag values into fixed folder mounts, each path resolved to an absolute directory. It rejects an empty name or path, a duplicate name, or a path that is not an existing directory. Order is preserved so ListMounts reflects the command line.

func SignedInConnection added in v0.10.0

func SignedInConnection(login string) string

SignedInConnection is the id of the connection SaveSignedIn keeps for a GitHub login.

Types

type Config

type Config struct {
	// Fixed are the mounts from the flags, in the order ListMounts shows them.
	Fixed []mounts.Mount
	// Uploads is the --uploads folder, "" for none. With Records, it holds runtime mounts' blobs and
	// views.
	Uploads string
	// UploadsMount names the fixed mount that serves the uploaded designs, which a link can't name.
	UploadsMount string
	// Records is the folder of runtime mount records under --store, "" for none.
	Records string
	// Connections is the folder of connection records under --store, "" for none. A runtime mount
	// naming a connection reads its source with that connection's token (agni issue 1724).
	Connections string
	// GitHubAPI and GitHubRaw are GitHub's API root and raw host, set by a test or for GitHub
	// Enterprise. Empty takes the library's defaults.
	GitHubAPI, GitHubRaw string
	// Limits caps a snapshot or a link. Zero takes the library's default of 256 MB and 100,000 files.
	Limits mounts.Limits
	// ReadOnly opens the records and blobs for reading alone, as agnids does over a store agni
	// serve writes. Open then neither rewrites old records nor builds snapshot views.
	ReadOnly bool
	// Log gets a line for each old record Open rewrites or can't, and each view it can't build.
	Log io.Writer
	// UserTokens is the folder under --store holding people's own tokens, sealed under
	// ConnectionsKey, "" for none (agni issue 1728).
	UserTokens string
	// ConnectionsKey is where the key that seals people's tokens is, as a secret reference such as
	// env:NAME. It holds 64 hex characters. Empty keeps no person's token.
	ConnectionsKey string
	// GitHubApp is the GitHub App's OAuth client the server signs people in through (agni issue
	// 1772). goapplib refreshes a signed-in person's token through it, and revokes it on a
	// disconnect. Nil keeps pasted tokens alone, which need neither.
	GitHubApp *oauth2.Config
	// Stores, when set, hold the runtime mount records, the connections and people's tokens in place
	// of the Records, Connections and UserTokens folders, as `--store sqlite://` does (agni issue
	// 1733). A records folder that an older agni wrote is migrated, and a Stores is not, since no
	// older agni wrote one.
	Stores *Stores
	// HidePrivate leaves out every mount that reads through a connection, from List and from
	// Resolve, for a server that asks who its callers are but can't check their connections. agnids
	// with --auth and no --connections-key is one (agni issue 1728). With ReadOnly, Connections,
	// UserTokens and ConnectionsKey, a reader checks callers through CanRead instead (agni issue
	// 1778).
	HidePrivate bool
	// S3Endpoint, GCSEndpoint and GraphAPI point the S3, Cloud Storage and Microsoft Graph drivers
	// at another host: an S3-compatible store such as MinIO, a national cloud, or a test's fake.
	// Empty takes each service's public endpoint (agni issues 1729, 1730).
	S3Endpoint, GCSEndpoint, GraphAPI string
	// Blobs is the blob store under Uploads, when the server opened one itself, such as a bucket
	// behind the uploads folder for an s3:// or gs:// --uploads (agni issue 1730). Nil opens
	// <Uploads>/blobs.
	Blobs blobs.Linker
	// Subscriptions keeps the Graph change-notification subscriptions CreateWebhook makes on
	// SharePoint mounts, one record per mount, so RenewSubscriptions finds them after a restart.
	// Nil keeps none, and CreateWebhook refuses a SharePoint mount.
	Subscriptions records.Store
}

Config says what a Table serves.

type Stores added in v0.11.0

type Stores struct {
	Mounts      mounts.RecordStore
	Connections connections.Store
	UserTokens  outbound.UserTokenStore
}

Stores are the record stores a Table reads and writes in place of folders under --store. A nil field keeps none of that kind, as an empty folder name does.

type Table

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

Table is a server's live mount list over goapplib's mounts registry (agni issues 1735, 1759). The mounts from its flags are fixed. With Records and Uploads it also serves the GitHub, S3, Cloud Storage and SharePoint mounts CreateMount made (agni issues 1729, 1730), each a record in --store, and every process sharing the store sees them within a second. Every OS-backed adapter resolves through a Table, so a mount made at runtime is reachable at once.

func NewTable

func NewTable(fixed ...mounts.Mount) *Table

NewTable returns a table serving fixed and nothing else, for the CLI and for a server with no store.

func Open

func Open(cfg Config) (*Table, error)

Open returns the table cfg describes. With Records and Uploads it first rewrites any record an older agni wrote (see migrate).

func (*Table) Blobs

func (t *Table) Blobs() blobs.Linker

Blobs is the blob store under --uploads, nil without one.

func (*Table) CanRead added in v0.10.0

func (t *Table) CanRead(ctx context.Context, source string) error

CanRead asks GitHub, through the caller's own connections, whether the caller can read source. A server connection never answers for a person, since it can read what the server can.

func (*Table) Connections

func (t *Table) Connections() connections.Store

Connections is the store of connection records, nil for a table with none.

func (*Table) CreateMount

func (t *Table) CreateMount(ctx context.Context, name, source, ref, connection string) (service.MountInfo, error)

CreateMount snapshots a source and serves it as name: a github://<owner>/<repo> at ref, or an s3://, gs:// or msgraph:// folder with each file pinned at the version it has now (agni issues 1729, 1730). A bucket or a drive has no refs, so ref must be empty for one, and a Graph source always reads through a connection. A file:// source is refused, because a client must not choose which folder on the server's disk is served.

func (*Table) CreateWebhook added in v0.10.0

func (t *Table) CreateWebhook(ctx context.Context, name, url string, secrets service.WebhookSecrets) (service.Webhook, error)

CreateWebhook makes or updates the push webhook on a github mount's repo, for service.WebhookMaker (agni issue 1726), through goapplib's Registry.EnsureWebhook. It reads through the mount's connection as the caller, so a connection that is one person's own works only for that person. GitHub lets a token manage a repo's hooks only with admin rights on the repo, or a fine-grained token's webhooks permission, and answers any other token with PERMISSION_DENIED.

On a SharePoint mount it subscribes to the drive's changes instead (subscribe, agni issue 1729).

func (*Table) DeleteMount

func (t *Table) DeleteMount(ctx context.Context, name string) error

DeleteMount forgets a runtime mount and removes its views. Its blobs stay until a sweep finds nothing naming them.

func (*Table) Disconnect added in v0.10.0

func (t *Table) Disconnect(ctx context.Context, owner, id string) error

Disconnect removes owner's connection id and its sealed token, for service.UserTokenKeeper, through goapplib's Service.Disconnect (agni issue 1776). A pasted token is deleted with no call to GitHub, since the person made it there and revokes it there.

func (*Table) Find

func (t *Table) Find(name string) (mounts.Mount, bool)

Find returns the mount named name.

func (*Table) Fixed

func (t *Table) Fixed(name string) bool

Fixed reports whether name is a mount from the flags.

func (*Table) Guarding added in v0.10.0

func (t *Table) Guarding(mount string) string

Guarding returns the private source a mount reads, its github:// source when it reads through a connection, and "" for any other mount (agni issue 1728). A mount that needs no connection reads a public repo or a folder on the server, which every caller the server lets in may read.

func (*Table) Info

func (t *Table) Info(m mounts.Mount) service.MountInfo

Info is m as the service port describes it.

func (*Table) List

func (t *Table) List() []mounts.Mount

List returns every mount the table serves: the fixed ones in configuration order, then the runtime ones by name. A store that fails after a good read keeps the last good list.

func (*Table) MountsOf added in v0.10.0

func (t *Table) MountsOf(ctx context.Context, source string) ([]string, error)

MountsOf names every mount whose source is source, for service.MountsOf (agni issue 1726). It counts the mounts a viewer can't see too, since a push moves every design that follows it. GitHub's owner and repo names ignore case.

func (*Table) MountsUsing

func (t *Table) MountsUsing(_ context.Context, id string) ([]string, error)

MountsUsing names the runtime mounts that read through the connection id, sorted, so a connection in use isn't deleted under them.

func (*Table) Readers

func (t *Table) Readers(ctx context.Context, name string) (service.MountReader, error)

Readers is the service.MountReaders a linked artifact reads through (agni issues 1723, 1759). Each reader is the registry's ResolveAt, ListAt and FetchAt for one mount. A GitHub mount lists a commit's files with their git blob ids and downloads only what the blobs lack. A folder from the flags is read as it is now. The uploads mount holds uploaded files and can't be linked.

func (*Table) Registry

func (t *Table) Registry() *mounts.Registry

Registry is the goapplib registry the table serves from.

func (*Table) RenewSubscriptions added in v0.11.0

func (t *Table) RenewSubscriptions(ctx context.Context, before time.Duration, clientState []byte, log io.Writer) (int, error)

RenewSubscriptions renews every Graph subscription the server keeps that ends within before, and returns how many it renewed (agni issue 1729). One Graph no longer knows is made again at the same URL. A mount that's gone takes its record with it. It logs each subscription it can't renew to log and goes on to the next.

func (*Table) Resolve

func (t *Table) Resolve(uri mounts.URI) (string, error)

Resolve maps uri to a host path inside its mount, for the OS-backed adapters. An unknown mount is service.ErrNotFound and a path that leaves its mount is service.ErrInvalidPath. A path may run into an archive, which archivefs reads as a folder (agni issue 1591). The library resolves the archive file, and the rest of the path is joined on for archivefs to read.

func (*Table) Root

func (t *Table) Root(m mounts.Mount) string

Root returns the host folder m serves from: a folder mount's own path, or a GitHub snapshot's view, built on first use. It returns "" for a mount with no folder here.

func (*Table) SaveServerSecret added in v0.11.0

func (t *Table) SaveServerSecret(ctx context.Context, id, secret string) error

SaveServerSecret seals secret as server connection id's token or App key, for service.UserTokenKeeper, through goapplib's Service.SaveServerSecret (agni issue 1802). Saving again rotates it.

func (*Table) SaveSignedIn added in v0.10.0

func (t *Table) SaveSignedIn(ctx context.Context, owner, login string, tok *oauth2.Token) (string, error)

SaveSignedIn keeps the token GitHub issued when owner signed in as login, as owner's own connection SignedInConnection(login), and returns its id (agni issue 1772). It makes the connection the first time and replaces its token after that. goapplib refreshes the token through Config.GitHubApp, and a disconnect revokes it at GitHub. A connection of owner's own by that id that isn't a sign-in is ErrFailedPrecondition, and so is a server with no --connections-key.

func (*Table) SaveUserToken added in v0.10.0

func (t *Table) SaveUserToken(ctx context.Context, owner, id, token string) error

SaveUserToken seals token as owner's own connection id, for service.UserTokenKeeper. The person pasted it, so it is kept as pasted, and a disconnect deletes it without asking GitHub to revoke it. The server needs --connections-key to seal it.

type Workspace

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

Workspace is the OS-backed service.Workspace over a mount table. It resolves a URI to a host path with Resolve, which keeps it inside the mount root, and lists it with archivefs.OSReadDir, which lists an archive as a folder. Both the engine's server and the datasheet service list folders through it (agni issue 744).

func NewWorkspace

func NewWorkspace(t *Table) *Workspace

NewWorkspace lists folders inside the mounts t serves, including any made at runtime.

func (*Workspace) ListDir

func (w *Workspace) ListDir(_ context.Context, uri mounts.URI) ([]service.DirEntry, error)

ListDir resolves the URI and reads one directory level. The service maps an error wrapping service.ErrInvalidPath to InvalidArgument. It maps any other error to NotFound, including an unknown mount or a missing directory.

func (*Workspace) Mounts

func (w *Workspace) Mounts() []service.MountInfo

Mounts returns the served mounts as the port's runtime-neutral MountInfo.

func (*Workspace) ReadFile

func (w *Workspace) ReadFile(_ context.Context, uri mounts.URI) ([]byte, error)

ReadFile reads one file inside its mount, for service.FileReader. A directory is an error.

Jump to

Keyboard shortcuts

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