metadata

package
v0.18.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	COMPRESSION_THRESHOLD = 0 // files above this size are stored compressed. The chi Compress middleware does not have a threshold,
	// so the threshold is set to zero here
	BROTLI_COMPRESSION_LEVEL = 9 // https://paulcalvano.com/2018-07-25-brotli-compression-how-much-will-it-reduce-your-content/ seems

)
View Source
const CURRENT_DB_VERSION = 17
View Source
const CURRENT_FILE_CACHE_VERSION = 1

Variables

View Source
var ErrAppNotFound = errors.New("app not found")

ErrAppNotFound is returned when an app entry does not exist in the metadata store.

View Source
var ErrConfigAlreadyExists = errors.New("config already exists")
View Source
var ErrConfigNotFound = errors.New("config not found")
View Source
var ErrNoConfigDraft = errors.New("no staged config draft")

Functions

func GlobMatch

func GlobMatch(patterns []string, fileName string) (bool, error)

GlobMatch returns true if the file name matches any of the patterns

Types

type CertStorage added in v0.16.11

type CertStorage struct {
	*types.Logger
	// contains filtered or unexported fields
}

CertStorage is the database backed storage for the cert info. Implements the certmagic.Storage interface.

func NewCertStorage added in v0.16.11

func NewCertStorage(ctx context.Context, logger *types.Logger, metadata *Metadata) (*CertStorage, error)

func (*CertStorage) Delete added in v0.16.11

func (c *CertStorage) Delete(ctx context.Context, id string) error

Delete deletes the certificate with the given id.

func (*CertStorage) Exists added in v0.16.11

func (c *CertStorage) Exists(ctx context.Context, id string) bool

Exists checks if the certificate with the given id exists.

func (*CertStorage) List added in v0.16.11

func (c *CertStorage) List(ctx context.Context, prefix string, recursive bool) ([]string, error)

List lists the certificates with the given prefix.

func (*CertStorage) Load added in v0.16.11

func (c *CertStorage) Load(ctx context.Context, id string) ([]byte, error)

Load loads the certificate with the given id.

func (*CertStorage) Lock added in v0.16.11

func (c *CertStorage) Lock(ctx context.Context, id string) error

Lock locks the certificate with the given id.

func (*CertStorage) Stat added in v0.16.11

func (c *CertStorage) Stat(ctx context.Context, id string) (certmagic.KeyInfo, error)

Stat returns the information about the certificate with the given id.

func (*CertStorage) Store added in v0.16.11

func (c *CertStorage) Store(ctx context.Context, id string, value []byte) error

Store stores the certificate with the given id and value.

func (*CertStorage) Unlock added in v0.16.11

func (c *CertStorage) Unlock(ctx context.Context, id string) error

Unlock unlocks the certificate with the given id.

type DbFile

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

func NewDBFile

func NewDBFile(name string, compressionType string, data []byte, fi DbFileInfo) *DbFile

func (*DbFile) Close

func (f *DbFile) Close() error

func (*DbFile) Name

func (f *DbFile) Name() string

func (*DbFile) Read

func (f *DbFile) Read(dst []byte) (int, error)

func (*DbFile) ReadCompressed

func (f *DbFile) ReadCompressed() ([]byte, string, error)

func (*DbFile) Seek

func (f *DbFile) Seek(offset int64, whence int) (int64, error)

func (*DbFile) Stat

func (f *DbFile) Stat() (fs.FileInfo, error)

type DbFileInfo

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

func (*DbFileInfo) IsDir

func (fi *DbFileInfo) IsDir() bool

func (*DbFileInfo) ModTime

func (fi *DbFileInfo) ModTime() time.Time

func (*DbFileInfo) Mode

func (fi *DbFileInfo) Mode() fs.FileMode

func (*DbFileInfo) Name

func (fi *DbFileInfo) Name() string

func (*DbFileInfo) Size

func (fi *DbFileInfo) Size() int64

func (*DbFileInfo) Sys

func (fi *DbFileInfo) Sys() any

type DbFileReader

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

func NewDbFileReader

func NewDbFileReader(compressionType string, data []byte) *DbFileReader

func (*DbFileReader) Read

func (f *DbFileReader) Read(dst []byte) (int, error)

func (*DbFileReader) ReadCompressed

func (f *DbFileReader) ReadCompressed() ([]byte, string, error)

func (*DbFileReader) Seek

func (f *DbFileReader) Seek(offset int64, whence int) (int64, error)

type DbFs

type DbFs struct {
	*types.Logger
	// contains filtered or unexported fields
}

func NewDbFs

func NewDbFs(logger *types.Logger, fileStore *FileStore, specFiles types.SpecFiles) (*DbFs, error)

func (*DbFs) CreateTempSourceDir

func (d *DbFs) CreateTempSourceDir() (string, error)

func (*DbFs) FileHash

func (d *DbFs) FileHash(excludeGlob []string) (string, error)

FileHash returns a hash of the file names and their corresponding sha256 hashes

func (*DbFs) Glob

func (d *DbFs) Glob(pattern string) (matches []string, err error)

func (*DbFs) Open

func (d *DbFs) Open(name string) (fs.File, error)

func (*DbFs) ReadFile

func (d *DbFs) ReadFile(name string) ([]byte, error)

func (*DbFs) Reset

func (d *DbFs) Reset()

func (*DbFs) Stat

func (d *DbFs) Stat(name string) (fs.FileInfo, error)

func (*DbFs) StatNoSpec

func (d *DbFs) StatNoSpec(name string) (fs.FileInfo, error)

func (*DbFs) StaticFiles

func (d *DbFs) StaticFiles() []string

type FileCache added in v0.14.7

type FileCache struct {
	*types.Logger
	// contains filtered or unexported fields
}

func InitFileCache added in v0.14.7

func InitFileCache(logger *types.Logger, config *types.ServerConfig) (*FileCache, error)

func (*FileCache) AddCache added in v0.14.7

func (f *FileCache) AddCache(ctx context.Context, sha string, compressionType string, content []byte) error

func (*FileCache) Close added in v0.18.5

func (f *FileCache) Close() error

Close closes the file cache database connection pool.

func (*FileCache) GetCachedFile added in v0.14.7

func (f *FileCache) GetCachedFile(ctx context.Context, sha string) ([]byte, string, error)

func (*FileCache) VersionUpgrade added in v0.14.7

func (f *FileCache) VersionUpgrade(config *types.ServerConfig) error

type FileStore

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

func NewFileStore

func NewFileStore(appId types.AppId, version int, metadata *Metadata, tx types.Transaction) (*FileStore, error)

func (*FileStore) AddAppVersionDisk

func (f *FileStore) AddAppVersionDisk(ctx context.Context, tx types.Transaction, metadata types.AppMetadata, checkoutDir string) error

func (*FileStore) GetAppFiles

func (f *FileStore) GetAppFiles(ctx context.Context, tx types.Transaction) ([]types.AppFile, error)

func (*FileStore) GetAppVersion

func (f *FileStore) GetAppVersion(ctx context.Context, tx types.Transaction, version int) (*types.AppVersion, error)

func (*FileStore) GetAppVersions

func (f *FileStore) GetAppVersions(ctx context.Context, tx types.Transaction) ([]types.AppVersion, error)

func (*FileStore) GetFileBySha

func (f *FileStore) GetFileBySha(sha string) ([]byte, string, error)

func (*FileStore) GetFileByShaTx

func (f *FileStore) GetFileByShaTx(ctx context.Context, tx types.Transaction, sha string) ([]byte, string, error)

func (*FileStore) GetHighestVersion

func (f *FileStore) GetHighestVersion(ctx context.Context, tx types.Transaction, appId types.AppId) (int, error)

func (*FileStore) IncrementAppVersion

func (f *FileStore) IncrementAppVersion(ctx context.Context, tx types.Transaction, metadata *types.AppMetadata) error

func (*FileStore) PromoteApp

func (f *FileStore) PromoteApp(ctx context.Context, tx types.Transaction, prodAppId types.AppId, metadata *types.AppMetadata) error

func (*FileStore) Reset

func (f *FileStore) Reset()

type LeaderElection added in v0.16.21

type LeaderElection struct {
	*types.Logger
	// contains filtered or unexported fields
}

func NewLeaderElection added in v0.16.21

func NewLeaderElection(logger *types.Logger, metadata *Metadata, config *types.ServerConfig, nodeId string, hostname string) *LeaderElection

func (*LeaderElection) CreateTables added in v0.16.21

func (l *LeaderElection) CreateTables(ctx context.Context, tx types.Transaction) error

func (*LeaderElection) IsLeader added in v0.16.21

func (l *LeaderElection) IsLeader() bool

func (*LeaderElection) StartLoop added in v0.16.21

func (l *LeaderElection) StartLoop(parentCtx context.Context)

func (*LeaderElection) Stop added in v0.16.21

func (l *LeaderElection) Stop()

type LeaderState added in v0.16.21

type LeaderState struct {
	LeaderID               string
	Hostname               string
	LastHeartbeatAt        time.Time
	LastLeadershipChangeAt time.Time
}

type Metadata

type Metadata struct {
	*types.Logger

	AppNotifyFunc    func(types.AppUpdatePayload)
	ConfigNotifyFunc func(types.ConfigUpdatePayload)
	// contains filtered or unexported fields
}

Metadata is the metadata persistence layer

func NewMetadata

func NewMetadata(logger *types.Logger, config *types.ServerConfig) (*Metadata, error)

NewMetadata creates a new metadata persistence layer

func (*Metadata) BeginTransaction

func (m *Metadata) BeginTransaction(ctx context.Context) (types.Transaction, error)

BeginTransaction starts a new Transaction

func (*Metadata) CleanupAppVersions added in v0.16.22

func (m *Metadata) CleanupAppVersions(app types.AppInfo) error

func (*Metadata) CleanupExpiredKV added in v0.17.1

func (m *Metadata) CleanupExpiredKV(ctx context.Context) error

func (*Metadata) CleanupFiles added in v0.16.22

func (m *Metadata) CleanupFiles() error

func (*Metadata) ClearServiceDefault added in v0.17.2

func (m *Metadata) ClearServiceDefault(ctx context.Context, tx types.Transaction, serviceType, exceptName string) error

ClearServiceDefault unsets the is_default flag for any service of the given service_type except for the service with the given name. If exceptName is empty, the default flag is cleared for all services of that type.

func (*Metadata) ClearServiceStaging added in v0.17.2

func (m *Metadata) ClearServiceStaging(ctx context.Context, tx types.Transaction, serviceType, staging string) error

func (*Metadata) Close added in v0.16.21

func (m *Metadata) Close()

Close stops background goroutines owned by Metadata (leader election and the postgres listener) and closes the database connection pools.

func (*Metadata) CommitTransaction

func (m *Metadata) CommitTransaction(tx types.Transaction) error

CommitTransaction commits a transaction

func (*Metadata) CountServices added in v0.17.2

func (m *Metadata) CountServices(ctx context.Context, tx types.Transaction, serviceType string) (int, error)

CountServices returns the number of services of the given service_type.

func (*Metadata) CreateApp

func (m *Metadata) CreateApp(ctx context.Context, tx types.Transaction, app *types.AppEntry) error

func (*Metadata) CreateBinding added in v0.17.2

func (m *Metadata) CreateBinding(ctx context.Context, tx types.Transaction, binding *types.Binding) error

func (*Metadata) CreateBuilderActivity added in v0.18.6

func (m *Metadata) CreateBuilderActivity(ctx context.Context, tx types.Transaction, activity *types.BuilderActivity) error

func (*Metadata) CreateBuilderSession added in v0.18.6

func (m *Metadata) CreateBuilderSession(ctx context.Context, tx types.Transaction, session *types.BuilderSession) error

func (*Metadata) CreateService added in v0.17.2

func (m *Metadata) CreateService(ctx context.Context, tx types.Transaction, service *types.Service) error

func (*Metadata) CreateSync

func (m *Metadata) CreateSync(ctx context.Context, tx types.Transaction, sync *types.SyncEntry) error

func (*Metadata) DeleteApp

func (m *Metadata) DeleteApp(ctx context.Context, tx types.Transaction, id types.AppId) error

func (*Metadata) DeleteBinding added in v0.17.2

func (m *Metadata) DeleteBinding(ctx context.Context, tx types.Transaction, path string) error

func (*Metadata) DeleteBuilderSession added in v0.18.6

func (m *Metadata) DeleteBuilderSession(ctx context.Context, tx types.Transaction, id string) error

func (*Metadata) DeleteConfigDraft added in v0.18.4

func (m *Metadata) DeleteConfigDraft(ctx context.Context) error

DeleteConfigDraft drops the staged config draft

func (*Metadata) DeleteKV added in v0.15.3

func (m *Metadata) DeleteKV(ctx context.Context, key string) error

func (*Metadata) DeleteSecretEntry added in v0.18.6

func (m *Metadata) DeleteSecretEntry(ctx context.Context, name string) error

DeleteSecretEntry deletes the secret with the given name, types.ErrSecretNotFound if it does not exist

func (*Metadata) DeleteService added in v0.17.2

func (m *Metadata) DeleteService(ctx context.Context, tx types.Transaction, name, serviceType string) error

func (*Metadata) DeleteSync

func (m *Metadata) DeleteSync(ctx context.Context, tx types.Transaction, id string) error

func (*Metadata) FetchKV added in v0.15.3

func (m *Metadata) FetchKV(ctx context.Context, key string) (map[string]any, error)

func (*Metadata) FetchKVBlob added in v0.15.3

func (m *Metadata) FetchKVBlob(ctx context.Context, key string) ([]byte, error)

func (*Metadata) GetAllApps

func (m *Metadata) GetAllApps(includeInternal bool) ([]types.AppInfo, error)

func (*Metadata) GetAppEntry added in v0.18.0

func (m *Metadata) GetAppEntry(ctx context.Context, pathDomain types.AppPathDomain) (*types.AppEntry, error)

func (*Metadata) GetAppEntryTx added in v0.18.0

func (m *Metadata) GetAppEntryTx(ctx context.Context, tx types.Transaction, pathDomain types.AppPathDomain) (*types.AppEntry, error)

func (*Metadata) GetAppsForDomain

func (m *Metadata) GetAppsForDomain(domain string) ([]string, error)

func (*Metadata) GetBinding added in v0.17.2

func (m *Metadata) GetBinding(ctx context.Context, tx types.Transaction, path string) (*types.Binding, error)

func (*Metadata) GetBuilderSession added in v0.18.6

func (m *Metadata) GetBuilderSession(ctx context.Context, tx types.Transaction, id string) (*types.BuilderSession, error)

func (*Metadata) GetCertStorage added in v0.16.11

func (m *Metadata) GetCertStorage() certmagic.Storage

GetCertStorage returns the cert storage implementation which persists the cert info to the database.

func (*Metadata) GetConfig added in v0.14.10

func (m *Metadata) GetConfig() (*types.DynamicConfig, error)

func (*Metadata) GetConfigDraft added in v0.18.4

func (m *Metadata) GetConfigDraft(ctx context.Context) (*types.ConfigDraft, error)

GetConfigDraft returns the staged config draft, ErrNoConfigDraft if none

func (*Metadata) GetConfigVersion added in v0.18.4

func (m *Metadata) GetConfigVersion(ctx context.Context, versionId string) (*types.DynamicConfig, error)

GetConfigVersion returns the full dynamic config snapshot for a history version

func (*Metadata) GetDefaultService added in v0.17.2

func (m *Metadata) GetDefaultService(ctx context.Context, tx types.Transaction, serviceType string) (*types.Service, error)

func (*Metadata) GetLinkedApps

func (m *Metadata) GetLinkedApps(ctx context.Context, tx types.Transaction, mainAppId types.AppId) ([]*types.AppEntry, error)

GetLinkedApps gets all the apps linked to the given main app (staging and preview apps)

func (*Metadata) GetSecretEntry added in v0.18.6

func (m *Metadata) GetSecretEntry(ctx context.Context, name string) (*types.SecretEntry, error)

GetSecretEntry returns the secret row for the given name, types.ErrSecretNotFound if it does not exist

func (*Metadata) GetService added in v0.17.2

func (m *Metadata) GetService(ctx context.Context, tx types.Transaction, serviceType, name string) (*types.Service, error)

func (*Metadata) GetSyncEntries

func (m *Metadata) GetSyncEntries(ctx context.Context, tx types.Transaction) ([]*types.SyncEntry, error)

GetSyncEntries gets all the sync entries for the given webhook type

func (*Metadata) GetSyncEntry

func (m *Metadata) GetSyncEntry(ctx context.Context, tx types.Transaction, id string) (*types.SyncEntry, error)

func (*Metadata) GetVersionUsers added in v0.18.6

func (m *Metadata) GetVersionUsers() (map[types.AppId]map[int]string, error)

GetVersionUsers returns the user who created each app version, keyed by app id and version. Used to annotate app listings with who performed the last (active version) update, in one query instead of per app

func (*Metadata) InitConfig added in v0.14.10

func (m *Metadata) InitConfig(ctx context.Context, user string, dynamicConfig *types.DynamicConfig) error

func (*Metadata) InsertSecretEntry added in v0.18.6

func (m *Metadata) InsertSecretEntry(ctx context.Context, entry *types.SecretEntry) error

InsertSecretEntry inserts a new secret row, types.ErrSecretExists if a row with the same name is already present

func (*Metadata) IsLeader added in v0.16.21

func (m *Metadata) IsLeader() bool

IsLeader returns true if the current server is the leader

func (*Metadata) ListBindings added in v0.17.2

func (m *Metadata) ListBindings(ctx context.Context, tx types.Transaction, source string) ([]*types.Binding, error)

ListBindings returns bindings filtered by the optional source. Empty string means no filter.

func (*Metadata) ListBuilderActivity added in v0.18.6

func (m *Metadata) ListBuilderActivity(ctx context.Context, sessionId, afterId string, limit int) ([]*types.BuilderActivity, error)

ListBuilderActivity returns activity rows for a session in insertion order (activity ids are time-ordered ksuids). afterId returns rows later than the given id, for incremental fetches; limit 0 means no limit

func (*Metadata) ListBuilderSessions added in v0.18.6

func (m *Metadata) ListBuilderSessions(ctx context.Context, userID string) ([]*types.BuilderSession, error)

ListBuilderSessions returns all sessions, newest first, optionally filtered to one user

func (*Metadata) ListConfigHistory added in v0.18.4

func (m *Metadata) ListConfigHistory(ctx context.Context) ([]types.ConfigHistoryEntry, error)

ListConfigHistory returns the config history entries, newest first

func (*Metadata) ListSecretEntries added in v0.18.6

func (m *Metadata) ListSecretEntries(ctx context.Context, includeValues bool) ([]*types.SecretEntry, error)

ListSecretEntries returns all secret rows, sorted by name. With includeValues false the ciphertext and nonce columns are not fetched; listing does not need to pull up to 1MiB blobs per row

func (*Metadata) ListServices added in v0.17.2

func (m *Metadata) ListServices(ctx context.Context, tx types.Transaction, serviceType, name string) ([]*types.Service, error)

ListServices returns services filtered by the optional serviceType and name. Empty string means no filter.

func (*Metadata) NotifyAppUpdate

func (m *Metadata) NotifyAppUpdate(appPathDomains []types.AppPathDomain) error

NotifyAppUpdate sends a notification through the postgres listener that an app has been updated

func (*Metadata) NotifyConfigUpdate added in v0.15.0

func (m *Metadata) NotifyConfigUpdate() error

NotifyConfigUpdate sends a notification through the postgres listener that the config has been updated

func (*Metadata) RollbackTransaction

func (m *Metadata) RollbackTransaction(tx types.Transaction) error

RollbackTransaction rolls back a transaction

func (*Metadata) ServiceExists added in v0.17.2

func (m *Metadata) ServiceExists(ctx context.Context, tx types.Transaction, serviceType, name string) (bool, error)

func (*Metadata) SetConfigDraft added in v0.18.4

func (m *Metadata) SetConfigDraft(ctx context.Context, draft *types.ConfigDraft) error

SetConfigDraft creates or replaces the staged config draft

func (*Metadata) StoreKV added in v0.15.3

func (m *Metadata) StoreKV(ctx context.Context, key string, value map[string]any, expireAt *time.Time) error

func (*Metadata) StoreKVBlob added in v0.15.3

func (m *Metadata) StoreKVBlob(ctx context.Context, key string, value []byte, expireAt *time.Time) error

func (*Metadata) UpdateAppMetadata

func (m *Metadata) UpdateAppMetadata(ctx context.Context, tx types.Transaction, app *types.AppEntry) error

func (*Metadata) UpdateAppSettings

func (m *Metadata) UpdateAppSettings(ctx context.Context, tx types.Transaction, app *types.AppEntry) error

func (*Metadata) UpdateBinding added in v0.17.2

func (m *Metadata) UpdateBinding(ctx context.Context, tx types.Transaction, binding *types.Binding) error

func (*Metadata) UpdateBuilderSession added in v0.18.6

func (m *Metadata) UpdateBuilderSession(ctx context.Context, tx types.Transaction, session *types.BuilderSession) error

func (*Metadata) UpdateConfig added in v0.14.10

func (m *Metadata) UpdateConfig(ctx context.Context, user string, oldVersionId string, dynamicConfig *types.DynamicConfig) error

func (*Metadata) UpdateKV added in v0.15.3

func (m *Metadata) UpdateKV(ctx context.Context, key string, value map[string]any) error

func (*Metadata) UpdateKVBlob added in v0.15.3

func (m *Metadata) UpdateKVBlob(ctx context.Context, key string, value []byte) error

func (*Metadata) UpdateSecretEntry added in v0.18.6

func (m *Metadata) UpdateSecretEntry(ctx context.Context, entry *types.SecretEntry) error

UpdateSecretEntry updates the value (and metadata) of an existing secret, types.ErrSecretNotFound if the name is not present

func (*Metadata) UpdateSecretEntryIfUnchanged added in v0.18.6

func (m *Metadata) UpdateSecretEntryIfUnchanged(ctx context.Context, entry *types.SecretEntry, prevKeyId string, prevNonce []byte) (bool, error)

UpdateSecretEntryIfUnchanged updates the row only if its current key_id and nonce still match prevKeyId/prevNonce, returning whether a row was updated

func (*Metadata) UpdateService added in v0.17.2

func (m *Metadata) UpdateService(ctx context.Context, tx types.Transaction, service *types.Service) error

func (*Metadata) UpdateSourceUrl added in v0.14.7

func (m *Metadata) UpdateSourceUrl(ctx context.Context, tx types.Transaction, app *types.AppEntry) error

func (*Metadata) UpdateSyncStatus

func (m *Metadata) UpdateSyncStatus(ctx context.Context, tx types.Transaction, id string, status *types.SyncJobStatus) error

func (*Metadata) UpsertKVBlob added in v0.17.1

func (m *Metadata) UpsertKVBlob(ctx context.Context, key string, value []byte, expireAt *time.Time) error

func (*Metadata) VersionUpgrade

func (m *Metadata) VersionUpgrade(config *types.ServerConfig) error

Jump to

Keyboard shortcuts

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