Documentation
¶
Overview ¶
Package sandbox runs the playground on the CLI's embedded OpenFGA server, persisted in a SQLite file.
Index ¶
Constants ¶
const DBEnv = "OPENFGA_PLAYGROUND_DB"
DBEnv overrides the saved playground database location.
Variables ¶
var ErrSchemaTooNew = errors.New("database schema is newer than this binary supports")
ErrSchemaTooNew is returned (wrapped) by OpenDatastore when the database was migrated by a newer binary than this one. The file is left untouched.
Functions ¶
func DefaultPath ¶
DefaultPath returns where the playground database is saved: $OPENFGA_PLAYGROUND_DB if set, else playground.db in the platform's per-user data directory.
func ExtractSamples ¶
ExtractSamples writes each embedded workspace to dir/<name> and returns name -> workspace root.
func OpenDatastore ¶
func OpenDatastore(path string) (storage.OpenFGADatastore, error)
OpenDatastore opens (creating if needed) the SQLite database at path, applies the OpenFGA migrations embedded in this binary, and returns the SQLite datastore with metrics export off.
The returned datastore owns the underlying *sql.DB; callers release it by calling the datastore's Close(). If the database's migration version is above the newest embedded migration, OpenDatastore returns an error wrapping ErrSchemaTooNew before running any migration, so the file is not modified.
func SampleNames ¶
func SampleNames() []string
SampleNames returns the sample store names in creation order.
Types ¶
type Options ¶
type Options struct {
// SavedPath is the persisted playground database. It is only ever read
// (copied) by Start and replaced atomically by Save.
SavedPath string
// Reset ignores an existing SavedPath and starts from the sample stores.
Reset bool
}
Options configures Start.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a playground running on a scratch copy of the database. Nothing reaches SavedPath unless Save is called.
func Start ¶
Start launches the embedded server on a scratch database: a copy of o.SavedPath if it exists (and !o.Reset), else a fresh database seeded with the sample stores. On any failure everything started is stopped and the scratch directory removed.
func (*Session) Close ¶
Close stops everything and removes the scratch dir without saving. It is idempotent and safe after Save.
func (*Session) Save ¶
Save stops the server, then atomically replaces SavedPath with the scratch database and removes the scratch dir. On failure SavedPath is untouched.