database

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const MaxBundleStatusRetention = 10
View Source
const SQLiteMemoryOnlyDSN = "file::memory:?cache=shared"

Variables

View Source
var ErrNotAuthorized = errors.New("not authorized")
View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Data

type Data struct {
	Path string `sql:"path"`
	Data []byte `sql:"data"`
}

type Database

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

Database implements the database operations. It will hide any differences between the varying SQL databases from the rest of the codebase.

func New added in v0.3.0

func New() *Database

func (*Database) CloseDB

func (d *Database) CloseDB()

func (*Database) DB

func (d *Database) DB() *sql.DB

func (*Database) DeleteBundle

func (d *Database) DeleteBundle(ctx context.Context, principal, tenant, name string) error

func (*Database) DeleteSecret

func (d *Database) DeleteSecret(ctx context.Context, principal, tenant, name string) error

func (*Database) DeleteSource

func (d *Database) DeleteSource(ctx context.Context, principal, tenant, name string) error

func (*Database) DeleteStack

func (d *Database) DeleteStack(ctx context.Context, principal, tenant, name string) error

func (*Database) Dialect

func (d *Database) Dialect() (string, error)

func (*Database) GetBundle

func (d *Database) GetBundle(ctx context.Context, principal, tenant, name string) (*config.Bundle, error)

func (*Database) GetBundleStatus added in v0.6.0

func (d *Database) GetBundleStatus(ctx context.Context, id int) (*config.BundleStatus, error)

GetBundleStatus retrieves a single bundle state record by ID.

func (*Database) GetLatestBundleStatus added in v0.6.0

func (d *Database) GetLatestBundleStatus(ctx context.Context, principal, tenant, bundle string) (*config.BundleStatus, error)

GetLatestBundleStatus returns the most recent status record for the given tenant and bundle across all revisions. Returns nil and ErrNotFound if no records exist.

func (*Database) GetPrincipalID

func (db *Database) GetPrincipalID(ctx context.Context, apiKey string) (string, error)

func (*Database) GetSecret

func (d *Database) GetSecret(ctx context.Context, principal, tenant, name string) (*config.SecretRef, error)

func (*Database) GetSource

func (d *Database) GetSource(ctx context.Context, principal, tenant, name string) (*config.Source, error)

func (*Database) GetStack

func (d *Database) GetStack(ctx context.Context, principal, tenant, name string) (*config.Stack, error)

func (*Database) InitDB

func (d *Database) InitDB(ctx context.Context) error

func (*Database) ListBundleStatuses added in v0.6.0

func (d *Database) ListBundleStatuses(ctx context.Context, principal, tenant, bundle, revision string, limit int) ([]*config.BundleStatus, error)

ListBundleStatuses returns bundle status records for the given tenant and bundle, ordered by bundle status id DESC. If revision is provided, results are filtered by revision. If revision is empty, returns records across all revisions. A limit of 0 defaults to MaxBundleStatusRetention; values above MaxBundleStatusRetention are capped.

func (*Database) ListBundles

func (d *Database) ListBundles(ctx context.Context, principal, tenant string, opts ListOptions) ([]*config.Bundle, string, error)

func (*Database) ListSecrets

func (d *Database) ListSecrets(ctx context.Context, principal, tenant string, opts ListOptions) ([]*config.SecretRef, string, error)

func (*Database) ListSources

func (d *Database) ListSources(ctx context.Context, principal, tenant string, opts ListOptions) ([]*config.Source, string, error)

ListSources returns a list of sources in the database. Note it does not return the source data.

func (*Database) ListStacks

func (d *Database) ListStacks(ctx context.Context, principal, tenant string, opts ListOptions) ([]*config.Stack, string, error)

func (*Database) LoadConfig

func (d *Database) LoadConfig(ctx context.Context, bar *progress.Bar, principal, tenant string, root *config.Root) error

LoadConfig loads the configuration from the configuration file into the database. Env vars for values are getting resolved at this point. We don't store "${ADMIN_TOKEN}" in the DB, but lookup the current field. Failing lookups are treated as errors! Secrets are the exception: they are stored as-is, so if their value refers to an env var, it's replaced on use.

func (*Database) QuerySourceData

func (d *Database) QuerySourceData(sourceID int64, sourceName string) func(context.Context) iter.Seq2[Data, error]

func (*Database) QuerySourceID added in v0.3.0

func (d *Database) QuerySourceID(ctx context.Context, tenant, sourceName string) (int64, error)

func (*Database) SourcesDataDelete

func (d *Database) SourcesDataDelete(ctx context.Context, sourceName, path string, principal, tenant string) error

func (*Database) SourcesDataGet

func (d *Database) SourcesDataGet(ctx context.Context, sourceName, path string, principal, tenant string) (any, bool, error)

func (*Database) SourcesDataPatch

func (d *Database) SourcesDataPatch(ctx context.Context, sourceName, path string, principal, tenant string, patch jsonpatch.Patch) error

func (*Database) SourcesDataPut

func (d *Database) SourcesDataPut(ctx context.Context, sourceName, path string, data any, principal, tenant string) error

func (*Database) Tenants added in v0.3.0

func (d *Database) Tenants(ctx context.Context) iter.Seq2[Tenant, error]

func (*Database) UpsertBundle

func (d *Database) UpsertBundle(ctx context.Context, principal, tenant string, bundle *config.Bundle) error

func (*Database) UpsertBundleStatus added in v0.6.0

func (d *Database) UpsertBundleStatus(ctx context.Context, tenant, bundle, revision, phase, status, errMsg string) (int, error)

UpsertBundleStatus creates or updates a bundle status record with the given phase and status. For a given tenant+bundle+revision combination, only one record exists. If a record already exists for the combination, it updates the phase and status. Old records beyond the retention limit (MaxBundleStatusRetention) are cleaned up in the same transaction.

func (*Database) UpsertPrincipal

func (db *Database) UpsertPrincipal(ctx context.Context, principal Principal) error

func (*Database) UpsertPrincipalTx

func (db *Database) UpsertPrincipalTx(ctx context.Context, tx *sql.Tx, principal Principal) error

func (*Database) UpsertSecret

func (d *Database) UpsertSecret(ctx context.Context, principal, tenant string, secret *config.Secret) error

func (*Database) UpsertSource

func (d *Database) UpsertSource(ctx context.Context, principal, tenant string, source *config.Source) error

func (*Database) UpsertStack

func (d *Database) UpsertStack(ctx context.Context, principal, tenant string, stack *config.Stack) error

func (*Database) UpsertToken

func (d *Database) UpsertToken(ctx context.Context, principal, tenant string, token *config.Token) error

func (*Database) WithAccessFactory added in v0.4.0

func (d *Database) WithAccessFactory(accessFactory ext_authz.AccessFactory) *Database

func (*Database) WithAuthorizer added in v0.4.0

func (d *Database) WithAuthorizer(authorizer ext_authz.Authorizer) *Database

func (*Database) WithConfig

func (d *Database) WithConfig(config *config.Database) *Database

func (*Database) WithLogger

func (d *Database) WithLogger(log *logging.Logger) *Database

func (*Database) WithRawRootConfig added in v0.6.0

func (d *Database) WithRawRootConfig(rawRootConfig []byte) *Database

type ListOptions

type ListOptions struct {
	Limit  int
	Cursor string
	// contains filtered or unexported fields
}

type Principal

type Principal struct {
	Id        string
	Role      string
	Tenant    string
	CreatedAt string
}

type Tenant added in v0.3.0

type Tenant struct {
	Name string `sql:"name"`
}

Jump to

Keyboard shortcuts

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