cluster

package
v0.0.0-...-9b3cf46 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: AGPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeNone        = DeviceType(0)
	TypeNIC         = DeviceType(1)
	TypeDisk        = DeviceType(2)
	TypeUnixChar    = DeviceType(3)
	TypeUnixBlock   = DeviceType(4)
	TypeUSB         = DeviceType(5)
	TypeGPU         = DeviceType(6)
	TypeInfiniband  = DeviceType(7)
	TypeProxy       = DeviceType(8)
	TypeUnixHotplug = DeviceType(9)
	TypeTPM         = DeviceType(10)
	TypePCI         = DeviceType(11)
)

Supported device types.

View Source
const (
	StoragePoolVolumeTypeNameContainer string = "container"
	StoragePoolVolumeTypeNameVM        string = "virtual-machine"
	StoragePoolVolumeTypeNameImage     string = "image"
	StoragePoolVolumeTypeNameCustom    string = "custom"
)

Leave the string type in here! This guarantees that go treats this is as a typed string constant. Removing it causes go to treat these as untyped string constants which is not what we want.

View Source
const (
	StoragePoolVolumeContentTypeNameFS    string = "filesystem"
	StoragePoolVolumeContentTypeNameBlock string = "block"
	StoragePoolVolumeContentTypeNameISO   string = "iso"
)

Content type names.

Variables

View Source
var ImageSourceProtocol = map[int]string{
	0: "lxd",
	1: "direct",
	2: "simplestreams",
}

ImageSourceProtocol maps image source protocol codes to human-readable names.

View Source
var PreparedStmts = map[int]*sql.Stmt{}

PreparedStmts is a placeholder for transitioning to package-scoped transaction functions.

View Source
var ProjectFeatures = map[string]ProjectFeature{
	"features.images": {
		DefaultEnabled: true,
	},
	"features.profiles": {
		DefaultEnabled: true,
	},
	"features.storage.volumes": {
		DefaultEnabled: true,
	},
	"features.storage.buckets": {
		DefaultEnabled: true,
	},
	"features.networks": {},
	"features.networks.zones": {
		CanEnableNonEmpty: true,
	},
}

ProjectFeatures lists available project features and their behaviours.

View Source
var SchemaVersion = len(updates)

SchemaVersion is the current version of the cluster database schema.

Functions

func APIToDevices

func APIToDevices(apiDevices map[string]map[string]string) (map[string]Device, error)

APIToDevices takes an API format devices map and converts it to a map of db.Device.

func ActivateTLSIdentity

func ActivateTLSIdentity(ctx context.Context, tx *sql.Tx, identifier uuid.UUID, cert *x509.Certificate) error

ActivateTLSIdentity updates a TLS identity to make it valid by adding the fingerprint, PEM encoded certificate, and setting the type.

func AuthGroupExists

func AuthGroupExists(ctx context.Context, tx *sql.Tx, groupName string) (bool, error)

AuthGroupExists returns true if an AuthGroup exists and false otherwise.

func ClearStaleOperationsFromNodes

func ClearStaleOperationsFromNodes(ctx context.Context, tx *sql.Tx, nodeIDs ...int64) error

ClearStaleOperationsFromNodes clears all stale operation records from the database for the given node IDs. This includes: - Deleting ephemeral operations, which are operations that are normally cleared few seconds after they finish. - Marking running bulk operations as failed.

func ClusterGroupExists

func ClusterGroupExists(ctx context.Context, tx *sql.Tx, name string) (bool, error)

ClusterGroupExists checks if a cluster_group with the given key exists. generator: cluster_group Exists

func ClusterLinksConfigStore

func ClusterLinksConfigStore() *query.EntityConfigStore

ClusterLinksConfigStore returns a query.EntityConfigStore for cluster links.

func CreateCertificateLegacy

func CreateCertificateLegacy(ctx context.Context, tx *sql.Tx, object CertificateLegacy) (int64, error)

CreateCertificateLegacy adds a new certificate to the database.

func CreateCertificateLegacyWithProjects

func CreateCertificateLegacyWithProjects(ctx context.Context, tx *sql.Tx, cert CertificateLegacy, projectNames []string) (int64, error)

CreateCertificateLegacyWithProjects stores a CertificateLegacy object in the db, and associates it to a list of project names. It will ignore the ID field from the CertificateLegacy.

func CreateClusterGroup

func CreateClusterGroup(ctx context.Context, tx *sql.Tx, object ClusterGroup) (int64, error)

CreateClusterGroup adds a new cluster_group to the database. generator: cluster_group Create

func CreateClusterLink(ctx context.Context, tx *sql.Tx, object ClusterLinkRow) (int64, error)

CreateClusterLink adds a new cluster link to the database.

func CreateConfig

func CreateConfig(ctx context.Context, tx *sql.Tx, parent string, object Config) error

CreateConfig adds a new config to the database. generator: config Create

func CreateDevices

func CreateDevices(ctx context.Context, tx *sql.Tx, parent string, objects map[string]Device) error

CreateDevices adds a new device to the database. generator: device Create

func CreateIdentityProviderGroup

func CreateIdentityProviderGroup(ctx context.Context, tx *sql.Tx, object IdentityProviderGroupsRow) (int64, error)

CreateIdentityProviderGroup adds a new identity provider group to the database.

func CreateInstance

func CreateInstance(ctx context.Context, tx *sql.Tx, object Instance) (int64, error)

CreateInstance adds a new instance to the database. generator: instance Create

func CreateInstanceConfig

func CreateInstanceConfig(ctx context.Context, tx *sql.Tx, instanceID int64, config map[string]string) error

CreateInstanceConfig adds new instance Config to the database. generator: instance Create

func CreateInstanceDevices

func CreateInstanceDevices(ctx context.Context, tx *sql.Tx, instanceID int64, devices map[string]Device) error

CreateInstanceDevices adds new instance Devices to the database. generator: instance Create

func CreateInstanceSnapshot

func CreateInstanceSnapshot(ctx context.Context, tx *sql.Tx, object InstanceSnapshot) (int64, error)

CreateInstanceSnapshot adds a new instance_snapshot to the database. generator: instance_snapshot Create

func CreateInstanceSnapshotConfig

func CreateInstanceSnapshotConfig(ctx context.Context, tx *sql.Tx, instanceSnapshotID int64, config map[string]string) error

CreateInstanceSnapshotConfig adds new instance_snapshot Config to the database. generator: instance_snapshot Create

func CreateInstanceSnapshotDevices

func CreateInstanceSnapshotDevices(ctx context.Context, tx *sql.Tx, instanceSnapshotID int64, devices map[string]Device) error

CreateInstanceSnapshotDevices adds new instance_snapshot Devices to the database. generator: instance_snapshot Create

func CreateOIDCSession

func CreateOIDCSession(ctx context.Context, tx *sql.Tx, session OIDCSession) error

CreateOIDCSession creates an OIDC session.

func CreateOperationResources

func CreateOperationResources(ctx context.Context, tx *sql.Tx, opID int64, resources map[entity.Type][]api.URL) error

CreateOperationResources registers operation resources in the cluster db.

func CreateProfile

func CreateProfile(ctx context.Context, tx *sql.Tx, object Profile) (int64, error)

CreateProfile adds a new profile to the database. generator: profile Create

func CreateProfileConfig

func CreateProfileConfig(ctx context.Context, tx *sql.Tx, profileID int64, config map[string]string) error

CreateProfileConfig adds new profile Config to the database. generator: profile Create

func CreateProfileDevices

func CreateProfileDevices(ctx context.Context, tx *sql.Tx, profileID int64, devices map[string]Device) error

CreateProfileDevices adds new profile Devices to the database. generator: profile Create

func CreateProject

func CreateProject(ctx context.Context, tx *sql.Tx, object Project) (int64, error)

CreateProject adds a new project to the database. generator: project Create

func CreateProjectConfig

func CreateProjectConfig(ctx context.Context, tx *sql.Tx, projectID int64, config map[string]string) error

CreateProjectConfig adds new project Config to the database. generator: project Create

func CreateReplicator

func CreateReplicator(ctx context.Context, tx *sql.Tx, object ReplicatorRow) (int64, error)

CreateReplicator adds a new replicator to the database.

func CreateTLSIdentity

func CreateTLSIdentity(ctx context.Context, tx *sql.Tx, name string, idType string, fingerprint string, pemCert string) (int64, error)

CreateTLSIdentity creates an Identity and a Certificate, and then adds a row to their association table.

func DeleteBearerIdentitySigningKey

func DeleteBearerIdentitySigningKey(ctx context.Context, tx *sql.Tx, identityID int64) error

DeleteBearerIdentitySigningKey deletes any signing keys for the identity. It returns an api.StatusError with http.StatusNotFound if no key exists.

func DeleteCertificateLegacy

func DeleteCertificateLegacy(ctx context.Context, tx *sql.Tx, fingerprint string) error

DeleteCertificateLegacy deletes the certificate matching the given key parameters.

func DeleteClusterGroup

func DeleteClusterGroup(ctx context.Context, tx *sql.Tx, name string) error

DeleteClusterGroup deletes the cluster_group matching the given key parameters. generator: cluster_group DeleteOne-by-Name

func DeleteClusterLink(ctx context.Context, tx *sql.Tx, name string) error

DeleteClusterLink deletes the cluster link with the given name.

func DeleteConfig

func DeleteConfig(ctx context.Context, tx *sql.Tx, parent string, referenceID int) error

DeleteConfig deletes the config matching the given key parameters. generator: config DeleteMany

func DeleteDevices

func DeleteDevices(ctx context.Context, tx *sql.Tx, parent string, referenceID int) error

DeleteDevices deletes the device matching the given key parameters. generator: device DeleteMany

func DeleteIdentityByAuthenticationMethodAndIdentifier

func DeleteIdentityByAuthenticationMethodAndIdentifier(ctx context.Context, tx *sql.Tx, authenticationMethod string, identifier string) error

DeleteIdentityByAuthenticationMethodAndIdentifier deletes a single identity with the given authentication method and identifier.

func DeleteIdentityByNameAndType

func DeleteIdentityByNameAndType(ctx context.Context, tx *sql.Tx, name string, identityType string) error

DeleteIdentityByNameAndType deletes a single identity with the given name and type. Note that the name of an identity is not guaranteed to be unique for OIDC identities.

func DeleteIdentityProviderGroup

func DeleteIdentityProviderGroup(ctx context.Context, tx *sql.Tx, name string) error

DeleteIdentityProviderGroup deletes the identity provider group matching the given name.

func DeleteInstance

func DeleteInstance(ctx context.Context, tx *sql.Tx, project string, name string) error

DeleteInstance deletes the instance matching the given key parameters. generator: instance DeleteOne-by-Project-and-Name

func DeleteInstanceProfiles

func DeleteInstanceProfiles(ctx context.Context, tx *sql.Tx, instanceID int) error

DeleteInstanceProfiles deletes all instance profile associations for the given instance ID.

func DeleteInstanceSnapshot

func DeleteInstanceSnapshot(ctx context.Context, tx *sql.Tx, project string, instance string, name string) error

DeleteInstanceSnapshot deletes the instance_snapshot matching the given key parameters. generator: instance_snapshot DeleteOne-by-Project-and-Instance-and-Name

func DeleteNodesClusterGroupsByGroupID

func DeleteNodesClusterGroupsByGroupID(ctx context.Context, tx *sql.Tx, groupID int64) error

DeleteNodesClusterGroupsByGroupID deletes all node cluster group associations for the given group ID.

func DeleteOIDCSessionByUUID

func DeleteOIDCSessionByUUID(ctx context.Context, tx *sql.Tx, sessionID uuid.UUID) error

DeleteOIDCSessionByUUID deletes a session by UUID.

func DeleteOperation

func DeleteOperation(ctx context.Context, tx *sql.Tx, operationUUID string) error

DeleteOperation deletes an operation by UUID.

func DeleteProfile

func DeleteProfile(ctx context.Context, tx *sql.Tx, project string, name string) error

DeleteProfile deletes the profile matching the given key parameters. generator: profile DeleteOne-by-Project-and-Name

func DeleteProject

func DeleteProject(ctx context.Context, tx *sql.Tx, name string) error

DeleteProject deletes the project matching the given key parameters. generator: project DeleteOne-by-Name

func DeleteReplicator

func DeleteReplicator(ctx context.Context, tx *sql.Tx, name string, projectName string) error

DeleteReplicator deletes the replicator with the given name and project.

func DeleteWarning

func DeleteWarning(ctx context.Context, tx *sql.Tx, uuid string) error

DeleteWarning deletes the warning matching the given key parameters. generator: warning DeleteOne-by-UUID

func DeleteWarnings

func DeleteWarnings(ctx context.Context, tx *sql.Tx, entityType EntityType, entityID int) error

DeleteWarnings deletes the warning matching the given key parameters. generator: warning DeleteMany-by-EntityType-and-EntityID

func DevicesToAPI

func DevicesToAPI(devices map[string]Device) map[string]map[string]string

DevicesToAPI takes a map of devices and converts them to API format.

func EnsureSchema

func EnsureSchema(db *sql.DB, address string, dir string, serverUUID string) error

EnsureSchema applies all relevant schema updates to the cluster database.

Before actually doing anything, this function will make sure that all members in the cluster have a schema version and a number of API extensions that match our one. If it's not the case an api.StatusError with code http.StatusPreconditionFailed is returned, this indicates that this member should wait for them to become aligned.

func FreshSchema

func FreshSchema() string

FreshSchema returns the fresh schema definition of the global database.

func GetAllBearerIdentitySigningKeys

func GetAllBearerIdentitySigningKeys(ctx context.Context, tx *sql.Tx) (map[int64]AuthSecretValue, error)

GetAllBearerIdentitySigningKeys returns a map of identity ID to token signing keys. It should only be used to refresh the identity cache.

func GetAllIdentitiesByAuthGroupIDs

func GetAllIdentitiesByAuthGroupIDs(ctx context.Context, tx *sql.Tx) (map[int64][]IdentitiesRow, error)

GetAllIdentitiesByAuthGroupIDs returns a map of group IDs to the identities that are members of the group with that ID.

func GetAllIdentityProviderGroupsByGroupIDs

func GetAllIdentityProviderGroupsByGroupIDs(ctx context.Context, tx *sql.Tx) (map[int64][]IdentityProviderGroupsRow, error)

GetAllIdentityProviderGroupsByGroupIDs returns a map of group IDs to the IdentityProviderGroups that map to the group with that ID.

func GetAllProjectsConfig

func GetAllProjectsConfig(ctx context.Context, tx *sql.Tx) (map[string]map[string]string, error)

GetAllProjectsConfig returns a map of project name to config map.

func GetCertificateLegacyID

func GetCertificateLegacyID(ctx context.Context, tx *sql.Tx, fingerprint string) (int64, error)

GetCertificateLegacyID returns the ID of the certificate with the given fingerprint.

func GetCertificateLegacyProjects

func GetCertificateLegacyProjects(ctx context.Context, tx *sql.Tx, certificateID *int64) (map[int64][]string, error)

GetCertificateLegacyProjects returns a map of certificate (identity) ID to list of (alphabetically sorted) project names. The output map should only contain IDs of restricted legacy certificates. If the optional certificate ID is passed, the result will only contain the given ID.

func GetClusterGroupID

func GetClusterGroupID(ctx context.Context, tx *sql.Tx, name string) (int64, error)

GetClusterGroupID return the ID of the cluster_group with the given key. generator: cluster_group ID

func GetClusterLinksUsedBy

func GetClusterLinksUsedBy(ctx context.Context, tx *sql.Tx, clusterLinkName *string, firstOnly bool) (map[string][]string, error)

GetClusterLinksUsedBy returns a map of cluster link name to list of URLs of all entities that reference the cluster link via the 'cluster' config key. If clusterLinkName is non-nil, only references to that cluster link are returned. If firstOnly is true then the search stops after the first match overall (LIMIT 1 applied globally); only meaningful when clusterLinkName is non-nil.

func GetConfig

func GetConfig(ctx context.Context, tx *sql.Tx, parent string, filters ...ConfigFilter) (map[int]map[string]string, error)

GetConfig returns all available config. generator: config GetMany

func GetDevices

func GetDevices(ctx context.Context, tx *sql.Tx, parent string, filters ...DeviceFilter) (map[int][]Device, error)

GetDevices returns all available devices for the parent entity. generator: device GetMany

func GetDistinctAuthGroupNamesFromIDPGroupNames

func GetDistinctAuthGroupNamesFromIDPGroupNames(ctx context.Context, tx *sql.Tx, idpGroupNames []string) ([]string, error)

GetDistinctAuthGroupNamesFromIDPGroupNames returns all of the distinct group names that are mapped to from the given list of identity provider group names.

func GetEntityURL

func GetEntityURL(ctx context.Context, tx *sql.Tx, entityType entity.Type, entityID int) (*api.URL, error)

GetEntityURL returns the *api.URL of a single entity by its type and ID.

func GetEntityURLs

func GetEntityURLs(ctx context.Context, tx *sql.Tx, projectName string, filteringEntityTypes ...entity.Type) (map[entity.Type]map[int]*api.URL, error)

GetEntityURLs accepts a project name and a variadic of entity types and returns a map of entity.Type to map of entity ID, to *api.URL. This method combines the above queries into a single query using the UNION operator. If no entity types are given, this function will return URLs for all entity types. If no project name is given, this function will return URLs for all projects. This may result in stupendously large queries, so use with caution!

func GetGroupPermissions

func GetGroupPermissions(ctx context.Context, tx *sql.Tx) (map[string][]Permission, error)

GetGroupPermissions returns a map of group name to slice of permissions. This is used by the OpenFGADatastore implementation. It is pre-loaded into an openfga.RequestCache to reduce the total number of queries.

func GetIdentitiesPEMCertificates

func GetIdentitiesPEMCertificates(ctx context.Context, tx *sql.Tx, identityID *int64) (map[int64][]string, error)

GetIdentitiesPEMCertificates returns a map of identity ID to list of PEM encoded certificates for each identity. The optional identity ID field can be used to filter the output (in which case the output map will contain only one key). The slice of certificates for each identity is ordered with the most recent certificate first.

func GetIdentityAndSessionDetailsFromSessionID

func GetIdentityAndSessionDetailsFromSessionID(ctx context.Context, tx *sql.Tx, sessionID uuid.UUID) (*IdentitiesRow, *OIDCSession, error)

GetIdentityAndSessionDetailsFromSessionID gets both the IdentitiesRow and the OIDCSession from the given session ID.

func GetIdentityAuthGroupNames

func GetIdentityAuthGroupNames(ctx context.Context, tx *sql.Tx, identityID *int64, filter func(AuthGroupsRow) (bool, error)) (map[int64][]string, error)

GetIdentityAuthGroupNames returns a map of identity ID to slice of (alphabetically sorted) group names that the identity with that ID is a member of. A filter can be passed in, which should return false to omit entries and true to include them. This is useful for filtering out groups that the caller cannot view. If the filter function returns a non-nil error, this function will abort scanning of rows and return the error unmodified. The optional identity ID field can be used to get authorization group names for only one identity, in which case the output map contains only one key.

func GetImageSource

func GetImageSource(ctx context.Context, tx *sql.Tx, imageID int) (int, *api.ImageSource, error)

GetImageSource returns the image source with the given ID.

func GetInstanceConfig

func GetInstanceConfig(ctx context.Context, tx *sql.Tx, instanceID int, filters ...ConfigFilter) (map[string]string, error)

GetInstanceConfig returns all available Instance Config generator: instance GetMany

func GetInstanceDevices

func GetInstanceDevices(ctx context.Context, tx *sql.Tx, instanceID int, filters ...DeviceFilter) (map[string]Device, error)

GetInstanceDevices returns all available Instance Devices generator: instance GetMany

func GetInstanceID

func GetInstanceID(ctx context.Context, tx *sql.Tx, project string, name string) (int64, error)

GetInstanceID return the ID of the instance with the given key. generator: instance ID

func GetInstanceSnapshotConfig

func GetInstanceSnapshotConfig(ctx context.Context, tx *sql.Tx, instanceSnapshotID int, filters ...ConfigFilter) (map[string]string, error)

GetInstanceSnapshotConfig returns all available InstanceSnapshot Config generator: instance_snapshot GetMany

func GetInstanceSnapshotDevices

func GetInstanceSnapshotDevices(ctx context.Context, tx *sql.Tx, instanceSnapshotID int, filters ...DeviceFilter) (map[string]Device, error)

GetInstanceSnapshotDevices returns all available InstanceSnapshot Devices generator: instance_snapshot GetMany

func GetInstanceSnapshotID

func GetInstanceSnapshotID(ctx context.Context, tx *sql.Tx, project string, instance string, name string) (int64, error)

GetInstanceSnapshotID return the ID of the instance_snapshot with the given key. generator: instance_snapshot ID

func GetInstancesInPlacementGroup

func GetInstancesInPlacementGroup(ctx context.Context, tx *sql.Tx, name string, projectName string, nodeID *int64) (map[int64][]int64, error)

GetInstancesInPlacementGroup returns a map of member (node) ID to a slice of instance IDs for all instances that reference the given placement group either directly or indirectly via a profile. The target placement group is specified with the given name and project name. Instances located on the optional node ID are excluded if the node ID is not nil.

func GetOperationResources

func GetOperationResources(ctx context.Context, tx *sql.Tx, opID int64) (map[entity.Type][]api.URL, error)

GetOperationResources loads operation resources from the cluster db. The entity type is used as the key of the map, as the actual key is not stored in the DB.

func GetPlacementGroupUsedBy

func GetPlacementGroupUsedBy(ctx context.Context, tx *sql.Tx, projectName string, placementGroupName string, firstOnly bool) ([]string, error)

GetPlacementGroupUsedBy returns a list of URLs of entities that reference the placement group with the given name and project.

func GetPlacementGroupsUsedBy

func GetPlacementGroupsUsedBy(ctx context.Context, tx *sql.Tx, filter PlacementGroupFilter, firstOnly bool) (map[string]map[string][]string, error)

GetPlacementGroupsUsedBy returns a map of project name to map of placement group name (matching the given filter) to list of URLs of instances and profiles that reference the placement group.

func GetProfileConfig

func GetProfileConfig(ctx context.Context, tx *sql.Tx, profileID int, filters ...ConfigFilter) (map[string]string, error)

GetProfileConfig returns all available Profile Config generator: profile GetMany

func GetProfileDevices

func GetProfileDevices(ctx context.Context, tx *sql.Tx, profileID int, filters ...DeviceFilter) (map[string]Device, error)

GetProfileDevices returns all available Profile Devices generator: profile GetMany

func GetProfileID

func GetProfileID(ctx context.Context, tx *sql.Tx, project string, name string) (int64, error)

GetProfileID return the ID of the profile with the given key. generator: profile ID

func GetProfileIDsByProjectAndName

func GetProfileIDsByProjectAndName(ctx context.Context, tx *sql.Tx, projectNames []string, profileNames []string) ([]int64, error)

GetProfileIDsByProjectAndName finds profile IDs matching specific names within a specific list of projects.

func GetProjectConfig

func GetProjectConfig(ctx context.Context, tx *sql.Tx, projectName string) (map[string]string, error)

GetProjectConfig is a helper to return a config of a project.

func GetProjectID

func GetProjectID(ctx context.Context, tx *sql.Tx, name string) (int64, error)

GetProjectID return the ID of the project with the given key. generator: project ID

func GetProjectIDsToNames

func GetProjectIDsToNames(ctx context.Context, tx *sql.Tx) (map[int64]string, error)

GetProjectIDsToNames returns a map associating each project ID to its project name.

func GetProjectNames

func GetProjectNames(ctx context.Context, tx *sql.Tx) ([]string, error)

GetProjectNames returns the names of all available projects.

func GetProjectsSharingDefaultImages

func GetProjectsSharingDefaultImages(ctx context.Context, tx *sql.Tx) ([]string, error)

GetProjectsSharingDefaultImages returns the names of all projects using images stored in the "default" project. That is, it returns all projects with "features.images=false" and the "default" project itself.

func GetProjectsUsingRestrictedClusterGroups

func GetProjectsUsingRestrictedClusterGroups(ctx context.Context, tx *sql.Tx, groupName string) ([]string, error)

GetProjectsUsingRestrictedClusterGroups returns project URLs for all projects whose "restricted.cluster.groups" project configuration includes the specified groupName.

func GetWarningID

func GetWarningID(ctx context.Context, tx *sql.Tx, uuid string) (int64, error)

GetWarningID return the ID of the warning with the given key. generator: warning ID

func InitProjectWithoutImages

func InitProjectWithoutImages(ctx context.Context, tx *sql.Tx, project string) error

InitProjectWithoutImages populates the images_profiles table with all images from the default project when a project is created with features.images=false.

func Open

func Open(name string, store driver.NodeStore, options ...driver.Option) (*sql.DB, error)

Open the cluster database object.

The name argument is the name of the cluster database. It defaults to 'db.bin', but can be overwritten for testing.

The dialer argument is a function that returns a gRPC dialer that can be used to connect to a database node using the gRPC SQL package.

func PlacementGroupsConfigStore

func PlacementGroupsConfigStore() *query.EntityConfigStore

PlacementGroupsConfigStore returns a query.EntityConfigStore for placement groups.

func PopulateEntityReferencesFromURLs

func PopulateEntityReferencesFromURLs(ctx context.Context, tx *sql.Tx, entityURLMap map[*api.URL]*EntityRef) error

PopulateEntityReferencesFromURLs populates the values in the given map with entity references corresponding to the api.URL keys. It will return an error if any of the given URLs do not correspond to a LXD entity.

func PrepareStmts

func PrepareStmts(db *sql.DB, skipErrors bool) (map[int]*sql.Stmt, error)

PrepareStmts prepares all registered statements and returns an index from statement code to prepared statement object.

func ProjectHasImages

func ProjectHasImages(ctx context.Context, tx *sql.Tx, name string) (bool, error)

ProjectHasImages is a helper to check if a project has the images feature enabled.

func ProjectHasProfiles

func ProjectHasProfiles(ctx context.Context, tx *sql.Tx, name string) (bool, error)

ProjectHasProfiles is a helper to check if a project has the profiles feature enabled.

func RegisterStmt

func RegisterStmt(sql string) int

RegisterStmt register a SQL statement.

Registered statements will be prepared upfront and re-used, to speed up execution.

Return a unique registration code.

func RenameClusterGroup

func RenameClusterGroup(ctx context.Context, tx *sql.Tx, name string, to string) error

RenameClusterGroup renames the cluster_group matching the given key parameters. generator: cluster_group Rename

func RenameClusterLink(ctx context.Context, tx *sql.Tx, name string, to string) error

RenameClusterLink renames the cluster link with the given name.

func RenameIdentityProviderGroup

func RenameIdentityProviderGroup(ctx context.Context, tx *sql.Tx, name string, to string) error

RenameIdentityProviderGroup renames the identity provider group matching the given name.

func RenameInstance

func RenameInstance(ctx context.Context, tx *sql.Tx, project string, name string, to string) error

RenameInstance renames the instance matching the given key parameters. generator: instance Rename

func RenameInstanceSnapshot

func RenameInstanceSnapshot(ctx context.Context, tx *sql.Tx, project string, instance string, name string, to string) error

RenameInstanceSnapshot renames the instance_snapshot matching the given key parameters. generator: instance_snapshot Rename

func RenameProfile

func RenameProfile(ctx context.Context, tx *sql.Tx, project string, name string, to string) error

RenameProfile renames the profile matching the given key parameters. generator: profile Rename

func RenameProject

func RenameProject(ctx context.Context, tx *sql.Tx, name string, to string) error

RenameProject renames the project matching the given key parameters. generator: project Rename

func RenameReplicator

func RenameReplicator(ctx context.Context, tx *sql.Tx, name string, projectName string, newName string) error

RenameReplicator renames the replicator with the given name in the given project.

func ReplicatorsConfigStore

func ReplicatorsConfigStore() *query.EntityConfigStore

ReplicatorsConfigStore returns a query.EntityConfigStore for replicators.

func Schema

func Schema() *schema.Schema

Schema for the cluster database.

func SchemaDotGo

func SchemaDotGo() error

SchemaDotGo refreshes the schema.go file in this package, using the updates defined here.

func SetAuthGroupPermissions

func SetAuthGroupPermissions(ctx context.Context, tx *sql.Tx, groupID int64, authGroupPermissions []Permission) error

SetAuthGroupPermissions deletes all auth_group -> permission mappings from the `auth_group_permissions` table where the group ID is equal to the given value. Then it inserts a new row for each given permission ID.

func SetIdentityAuthGroups

func SetIdentityAuthGroups(ctx context.Context, tx *sql.Tx, identityID int64, groupNames []string) error

SetIdentityAuthGroups deletes all auth_group -> identity mappings from the `identities_auth_groups` table where the identity ID is equal to the given value. Then it inserts new associations into the table where the group IDs correspond to the given group names.

func SetIdentityProviderGroupMapping

func SetIdentityProviderGroupMapping(ctx context.Context, tx *sql.Tx, identityProviderGroupID int64, groupNames []string) error

SetIdentityProviderGroupMapping deletes all auth_group -> identity_provider_group mappings from the `auth_groups_identity_provider_groups` table where the identity provider group ID is equal to the given value. Then it inserts new associations into the table where the group IDs correspond to the given group names.

func Stmt

func Stmt(tx *sql.Tx, code int) (*sql.Stmt, error)

Stmt prepares the in-memory prepared statement for the transaction.

func StmtString

func StmtString(code int) (string, error)

StmtString returns the in-memory query string with the given code.

func UpdateCertificateLegacy

func UpdateCertificateLegacy(ctx context.Context, tx *sql.Tx, object CertificateLegacy) error

UpdateCertificateLegacy updates the certificate matching the given key parameters.

func UpdateCertificateLegacyProjects

func UpdateCertificateLegacyProjects(ctx context.Context, tx *sql.Tx, certificateID int64, projectNames []string) error

UpdateCertificateLegacyProjects deletes and replaces any certificate to project associations.

func UpdateClusterGroup

func UpdateClusterGroup(ctx context.Context, tx *sql.Tx, name string, object ClusterGroup) error

UpdateClusterGroup updates the cluster_group matching the given key parameters. generator: cluster_group Update

func UpdateClusterLink(ctx context.Context, tx *sql.Tx, object ClusterLinkRow) error

UpdateClusterLink updates the cluster link row by its ID.

func UpdateConfig

func UpdateConfig(ctx context.Context, tx *sql.Tx, parent string, referenceID int, config map[string]string) error

UpdateConfig updates the config matching the given key parameters. generator: config Update

func UpdateDevices

func UpdateDevices(ctx context.Context, tx *sql.Tx, parent string, referenceID int, devices map[string]Device) error

UpdateDevices updates the device matching the given key parameters. generator: device Update

func UpdateInstance

func UpdateInstance(ctx context.Context, tx *sql.Tx, project string, name string, object Instance) error

UpdateInstance updates the instance matching the given key parameters. generator: instance Update

func UpdateInstanceConfig

func UpdateInstanceConfig(ctx context.Context, tx *sql.Tx, instanceID int64, config map[string]string) error

UpdateInstanceConfig updates the instance Config matching the given key parameters. generator: instance Update

func UpdateInstanceDevices

func UpdateInstanceDevices(ctx context.Context, tx *sql.Tx, instanceID int64, devices map[string]Device) error

UpdateInstanceDevices updates the instance Device matching the given key parameters. generator: instance Update

func UpdateInstanceProfiles

func UpdateInstanceProfiles(ctx context.Context, tx *sql.Tx, instanceID int, projectName string, profiles []string) error

UpdateInstanceProfiles updates the profiles of an instance in the order they are given.

func UpdateOperation

func UpdateOperation(ctx context.Context, tx *sql.Tx, opUUID string, nodeID int64, updatedAt time.Time, newStatus api.StatusCode, metadata map[string]any, opErr string, opErrCode int64) error

UpdateOperation updates operation status, metadata and error (if set) in the cluster db. This is used to keep DB in sync with the current status of the operation when the operation changes its status, or when calls to commit metadata explicitly. The caller is expected to pass in the current node ID. This guards against modification of the operation by other cluster members.

func UpdateProfile

func UpdateProfile(ctx context.Context, tx *sql.Tx, project string, name string, object Profile) error

UpdateProfile updates the profile matching the given key parameters. generator: profile Update

func UpdateProfileConfig

func UpdateProfileConfig(ctx context.Context, tx *sql.Tx, profileID int64, config map[string]string) error

UpdateProfileConfig updates the profile Config matching the given key parameters. generator: profile Update

func UpdateProfileDevices

func UpdateProfileDevices(ctx context.Context, tx *sql.Tx, profileID int64, devices map[string]Device) error

UpdateProfileDevices updates the profile Device matching the given key parameters. generator: profile Update

func UpdateProject

func UpdateProject(ctx context.Context, tx *sql.Tx, name string, object api.ProjectPut) error

UpdateProject updates the project matching the given key parameters.

func UpdateProjectReplicaMode

func UpdateProjectReplicaMode(ctx context.Context, tx *sql.Tx, projectName string, replicaMode string) error

UpdateProjectReplicaMode updates the replica_mode field for the project with the given name.

func UpdateReplicator

func UpdateReplicator(ctx context.Context, tx *sql.Tx, object ReplicatorRow) error

UpdateReplicator updates the replicator by its ID.

func UpdateReplicatorLastRun

func UpdateReplicatorLastRun(ctx context.Context, tx *sql.Tx, id int64, date time.Time, status string) error

UpdateReplicatorLastRun updates the last_run_date and last_run_status fields of the replicator with the given ID.

func UpdateReplicatorLastRunStatus

func UpdateReplicatorLastRunStatus(ctx context.Context, tx *sql.Tx, id int64, status string) error

UpdateReplicatorLastRunStatus updates only the last_run_status field of the replicator with the given ID.

func UpdateTLSIdentity

func UpdateTLSIdentity(ctx context.Context, tx *sql.Tx, identity IdentitiesRow, fingerprint string, pemCert string) error

UpdateTLSIdentity updates the given IdentitiesRow (applying any prior modifications) by primary key. If the fingerprint and certificate are provided, the [IdentitiesRow.Identifier] is set to the fingerprint value, and a new CertificatesRow is added with any previous CertificatesRow entries associated with the identity deleted.

func WarningExists

func WarningExists(ctx context.Context, tx *sql.Tx, uuid string) (bool, error)

WarningExists checks if a warning with the given key exists. generator: warning Exists

Types

type AuthGroupsRow

type AuthGroupsRow struct {
	ID          int64  `db:"id"`
	Name        string `db:"name"`
	Description string `db:"description"`
}

AuthGroupsRow represents a single row of the auth_groups table. db:model auth_groups

func GetAuthGroup

func GetAuthGroup(ctx context.Context, tx *sql.Tx, groupName string) (*AuthGroupsRow, error)

GetAuthGroup gets a single AuthGroup by name.

func GetAuthGroupsAndURLs

func GetAuthGroupsAndURLs(ctx context.Context, tx *sql.Tx, filter func(group AuthGroupsRow) bool) ([]AuthGroupsRow, []string, error)

GetAuthGroupsAndURLs queries for all authorization groups and then applies the given filter to the result. This is useful when filtering by groups the caller is able to view. The filter must return true to include an entry, and false to reject an entry. A slice of (filtered) authorization group URLs is also returned for convenience.

func GetAuthGroupsByIdentityID

func GetAuthGroupsByIdentityID(ctx context.Context, tx *sql.Tx, identityID int64) ([]AuthGroupsRow, error)

GetAuthGroupsByIdentityID returns a slice of groups that the identity with the given ID is a member of.

func GetAuthGroupsByIdentityProviderGroupID

func GetAuthGroupsByIdentityProviderGroupID(ctx context.Context, tx *sql.Tx, idpGroupID int64) ([]AuthGroupsRow, error)

GetAuthGroupsByIdentityProviderGroupID returns a list of groups that the identity provider group with the given ID.

func (AuthGroupsRow) APIName

func (AuthGroupsRow) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (AuthGroupsRow) CreateStmt

func (a AuthGroupsRow) CreateStmt() string

CreateStmt returns a query that creates a AuthGroupsRow entity.

func (AuthGroupsRow) CreateValues

func (a AuthGroupsRow) CreateValues() []any

CreateValues returns a list of values from AuthGroupsRow entities matching the bind arguments in [CreateStmt].

func (AuthGroupsRow) Joins

func (a AuthGroupsRow) Joins() []string

Joins returns a slice of join expressions for AuthGroupsRow.

func (AuthGroupsRow) PKColumns

func (a AuthGroupsRow) PKColumns() []string

PKColumns returns the column names for the primary key of a AuthGroupsRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (AuthGroupsRow) PKValues

func (a AuthGroupsRow) PKValues() []any

PKValues returns the values for the primary key of a AuthGroupsRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (*AuthGroupsRow) ScanArgs

func (a *AuthGroupsRow) ScanArgs() []any

ScanArgs implements query.ScanArger for AuthGroupsRow. This returns references to struct fields in definition order.

func (AuthGroupsRow) SelectColumns

func (a AuthGroupsRow) SelectColumns() []string

SelectColumns returns a slice of column names for AuthGroupsRow entities.

func (AuthGroupsRow) TableName

func (a AuthGroupsRow) TableName() string

TableName returns the table name for AuthGroupsRow entities.

func (*AuthGroupsRow) ToAPI

func (g *AuthGroupsRow) ToAPI(ctx context.Context, tx *sql.Tx, canViewIdentity auth.PermissionChecker, canViewIDPGroup auth.PermissionChecker) (*api.AuthGroup, error)

ToAPI converts the Group to an api.AuthGroup, making extra database queries as necessary.

func (AuthGroupsRow) UpdateStmt

func (a AuthGroupsRow) UpdateStmt() string

UpdateStmt returns a query that updates a AuthGroupsRow by primary key.

func (AuthGroupsRow) UpdateValues

func (a AuthGroupsRow) UpdateValues() []any

UpdateValues returns a list of values from AuthGroupsRow entities matching the columns in [UpdateStmt].

type AuthMethod

type AuthMethod string

AuthMethod is a database representation of an authentication method.

AuthMethod is defined on string so that API constants can be converted by casting. The sql.Scanner and [driver.Valuer] interfaces are implemented on this type such that the string constants are converted into their int64 counterparts as they are written to the database, or converted back into an AuthMethod as they are read from the database. It is not possible to read/write an invalid authentication methods from/to the database when using this type.

func (*AuthMethod) Scan

func (a *AuthMethod) Scan(value any) error

Scan implements sql.Scanner for AuthMethod. This converts the integer value back into the correct API constant or returns an error.

func (*AuthMethod) ScanInteger

func (a *AuthMethod) ScanInteger(authMethodCode int64) error

ScanInteger implements query.IntegerScanner for AuthMethod. This simplifies the Scan implementation.

func (AuthMethod) Value

func (a AuthMethod) Value() (driver.Value, error)

Value implements [driver.Valuer] for AuthMethod. This converts the API constant into an integer or throws an error.

type AuthSecret

type AuthSecret struct {
	ID           int
	Value        AuthSecretValue
	CreationDate time.Time
}

AuthSecret contains an AuthSecretValue and a creation time.

func (AuthSecret) Validate

func (s AuthSecret) Validate(expiry string) error

Validate checks that the secret is of the correct length and has not expired.

type AuthSecretValue

type AuthSecretValue []byte

AuthSecretValue is used to store byte slice of length authSecretLength in a text column as a base64 encoded string.

func RotateBearerIdentitySigningKey

func RotateBearerIdentitySigningKey(ctx context.Context, tx *sql.Tx, identityID int64) (AuthSecretValue, error)

RotateBearerIdentitySigningKey deletes any existing signing keys for the identity and creates a new one.

func (*AuthSecretValue) Scan

func (s *AuthSecretValue) Scan(value any) error

Scan implements sql.Scanner for AuthSecretValue.

func (*AuthSecretValue) ScanText

func (s *AuthSecretValue) ScanText(str string) error

ScanText implements query.TextScanner for AuthSecretValue to simplify the sql.Scanner implementation.

Note: This method must have a pointer receiver so that e.g. `row.Scan(&secretVal)` will work, whereas the Value implementation does not require a pointer receiver. This is so that a non-pointer AuthSecretValue can be written to the database.

func (AuthSecretValue) String

func (s AuthSecretValue) String() string

String implements fmt.Stringer for AuthSecretValue so that a human-readable format can be easily displayed. Note however that this is likely to contain sensitive information, and should never be logged.

func (AuthSecretValue) Validate

func (s AuthSecretValue) Validate() error

Validate checks that the AuthSecretValue has length authSecretLength.

func (AuthSecretValue) Value

func (s AuthSecretValue) Value() (driver.Value, error)

Value implements [driver.Valuer] for AuthSecretValue.

type AuthSecrets

type AuthSecrets []AuthSecret

AuthSecrets is a concrete type for a slice of AuthSecret.

func GetCoreAuthSecrets

func GetCoreAuthSecrets(ctx context.Context, tx *sql.Tx) (AuthSecrets, error)

GetCoreAuthSecrets returns a slice of AuthSecrets.

func (AuthSecrets) Rotate

func (s AuthSecrets) Rotate(ctx context.Context, tx *sql.Tx) (AuthSecrets, error)

Rotate returns a new AuthSecrets, with a new AuthSecret prepended to the slice. The slice is always truncated to a maximum of two elements. The new AuthSecret is written to the database, and any AuthSecret values older than the new oldest in-memory value are deleted from the database.

func (AuthSecrets) Validate

func (s AuthSecrets) Validate(expiry string) error

Validate checks that there is at least one secret in the slice, and that the first (most recent) is valid and has not expired.

type CertificateLegacy

type CertificateLegacy struct {
	ID          int64
	Fingerprint string
	Type        certificate.Type
	Name        string
	Certificate string
	Restricted  bool
}

CertificateLegacy is the database representation of a legacy certificate in the /1.0/certificates API. There is no table directly representing these entities. They are a combination of data from the `identities` and `certificates` tables.

func GetCertificateLegacy

func GetCertificateLegacy(ctx context.Context, tx *sql.Tx, fingerprint string) (*CertificateLegacy, error)

GetCertificateLegacy returns the certificate with the given fingerprint.

func GetCertificateLegacyByFingerprintPrefix

func GetCertificateLegacyByFingerprintPrefix(ctx context.Context, tx *sql.Tx, fingerprintPrefix string) (*CertificateLegacy, error)

GetCertificateLegacyByFingerprintPrefix gets a CertificateLegacy from the database. The argument fingerprint will be queried with a LIKE query, means you can pass a shortform and will get the full fingerprint. There can never be more than one certificate with a given fingerprint, as it is enforced by a UNIQUE constraint in the schema.

func GetCertificatesAndURLsLegacy

func GetCertificatesAndURLsLegacy(ctx context.Context, tx *sql.Tx, filter func(legacy CertificateLegacy) bool) ([]CertificateLegacy, []string, error)

GetCertificatesAndURLsLegacy returns all available certificates and their URLs. An optional filter function can be passed to filter the output. It should return true to include a certificate and false to omit it.

func (*CertificateLegacy) ToAPI

func (cert *CertificateLegacy) ToAPI(certificateIDToProjects map[int64][]string) (*api.Certificate, error)

ToAPI converts the CertificateLegacy struct to an api.Certificate The certificateIDToProjects map must be provided and can be loaded via GetCertificateLegacyProjects.

func (*CertificateLegacy) ToAPIType

func (cert *CertificateLegacy) ToAPIType() string

ToAPIType returns the API equivalent type.

func (CertificateLegacy) ToIdentity

func (cert CertificateLegacy) ToIdentity() (*IdentitiesRow, error)

ToIdentity converts a CertificateLegacy to an IdentitiesRow.

func (*CertificateLegacy) ToIdentityType

func (cert *CertificateLegacy) ToIdentityType() (IdentityType, error)

ToIdentityType returns a suitable IdentityType for the certificate.

type CertificatesRow

type CertificatesRow struct {
	ID          int64  `db:"id"`
	Fingerprint string `db:"fingerprint"`
	Certificate string `db:"certificate"`

	// CreationDate has a default value of the current timestamp.
	// We want the database to set this, and we never want to update it.
	// Omit the fields from create and update statements/values via the omit directive.
	//
	// db:omit create update
	CreationDate time.Time `db:"creation_date"`
}

CertificatesRow represents a row of the certificates table. db:model certificates

func (CertificatesRow) APIName

func (CertificatesRow) APIName() string

APIName implements query.APINamer for clear API error messages.

func (CertificatesRow) CreateStmt

func (c CertificatesRow) CreateStmt() string

CreateStmt returns a query that creates a CertificatesRow entity.

func (CertificatesRow) CreateValues

func (c CertificatesRow) CreateValues() []any

CreateValues returns a list of values from CertificatesRow entities matching the bind arguments in [CreateStmt].

func (CertificatesRow) Joins

func (c CertificatesRow) Joins() []string

Joins returns a slice of join expressions for CertificatesRow.

func (CertificatesRow) PKColumns

func (c CertificatesRow) PKColumns() []string

PKColumns returns the column names for the primary key of a CertificatesRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (CertificatesRow) PKValues

func (c CertificatesRow) PKValues() []any

PKValues returns the values for the primary key of a CertificatesRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (*CertificatesRow) ScanArgs

func (c *CertificatesRow) ScanArgs() []any

ScanArgs implements query.ScanArger for CertificatesRow. This returns references to struct fields in definition order.

func (CertificatesRow) SelectColumns

func (c CertificatesRow) SelectColumns() []string

SelectColumns returns a slice of column names for CertificatesRow entities.

func (CertificatesRow) TableName

func (c CertificatesRow) TableName() string

TableName returns the table name for CertificatesRow entities.

func (CertificatesRow) UpdateStmt

func (c CertificatesRow) UpdateStmt() string

UpdateStmt returns a query that updates a CertificatesRow by primary key.

func (CertificatesRow) UpdateValues

func (c CertificatesRow) UpdateValues() []any

UpdateValues returns a list of values from CertificatesRow entities matching the columns in [UpdateStmt].

type ClusterGroup

type ClusterGroup struct {
	ID          int
	Name        string
	Description string   `db:"coalesce=''"`
	Nodes       []string `db:"ignore"`
}

ClusterGroup is a value object holding db-related details about a cluster group.

func GetClusterGroup

func GetClusterGroup(ctx context.Context, tx *sql.Tx, name string) (*ClusterGroup, error)

GetClusterGroup returns the cluster_group with the given key. generator: cluster_group GetOne

func GetClusterGroups

func GetClusterGroups(ctx context.Context, tx *sql.Tx, filters ...ClusterGroupFilter) ([]ClusterGroup, error)

GetClusterGroups returns all available cluster_groups. generator: cluster_group GetMany

func (*ClusterGroup) ToAPI

func (c *ClusterGroup) ToAPI(ctx context.Context, tx *sql.Tx) (*api.ClusterGroup, error)

ToAPI returns a LXD API entry.

type ClusterGroupFilter

type ClusterGroupFilter struct {
	ID   *int
	Name *string
}

ClusterGroupFilter specifies potential query parameter fields.

type ClusterGroupGenerated

type ClusterGroupGenerated interface {
	// GetClusterGroups returns all available cluster_groups.
	// generator: cluster_group GetMany
	GetClusterGroups(ctx context.Context, tx *sql.Tx, filters ...ClusterGroupFilter) ([]ClusterGroup, error)

	// GetClusterGroup returns the cluster_group with the given key.
	// generator: cluster_group GetOne
	GetClusterGroup(ctx context.Context, tx *sql.Tx, name string) (*ClusterGroup, error)

	// GetClusterGroupID return the ID of the cluster_group with the given key.
	// generator: cluster_group ID
	GetClusterGroupID(ctx context.Context, tx *sql.Tx, name string) (int64, error)

	// ClusterGroupExists checks if a cluster_group with the given key exists.
	// generator: cluster_group Exists
	ClusterGroupExists(ctx context.Context, tx *sql.Tx, name string) (bool, error)

	// RenameClusterGroup renames the cluster_group matching the given key parameters.
	// generator: cluster_group Rename
	RenameClusterGroup(ctx context.Context, tx *sql.Tx, name string, to string) error

	// CreateClusterGroup adds a new cluster_group to the database.
	// generator: cluster_group Create
	CreateClusterGroup(ctx context.Context, tx *sql.Tx, object ClusterGroup) (int64, error)

	// UpdateClusterGroup updates the cluster_group matching the given key parameters.
	// generator: cluster_group Update
	UpdateClusterGroup(ctx context.Context, tx *sql.Tx, name string, object ClusterGroup) error

	// DeleteClusterGroup deletes the cluster_group matching the given key parameters.
	// generator: cluster_group DeleteOne-by-Name
	DeleteClusterGroup(ctx context.Context, tx *sql.Tx, name string) error
}

ClusterGroupGenerated is an interface of generated methods for ClusterGroup.

type ClusterLinkRow

type ClusterLinkRow struct {
	ID          int64           `db:"id"`
	IdentityID  int64           `db:"identity_id"`
	Name        string          `db:"name"`
	Description string          `db:"description"`
	Type        ClusterLinkType `db:"type"`
}

ClusterLinkRow represents a single row of the cluster_links table. db:model cluster_links

func GetClusterLink(ctx context.Context, tx *sql.Tx, name string) (*ClusterLinkRow, error)

GetClusterLink returns the cluster link with the given name.

func GetClusterLinks(ctx context.Context, tx *sql.Tx) ([]ClusterLinkRow, error)

GetClusterLinks returns all cluster links.

func GetClusterLinksAndURLs

func GetClusterLinksAndURLs(ctx context.Context, tx *sql.Tx, filter func(link ClusterLinkRow) bool) ([]ClusterLinkRow, []string, error)

GetClusterLinksAndURLs returns all cluster links that pass the given filter, along with their entity URLs.

func (ClusterLinkRow) APIName

func (ClusterLinkRow) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (ClusterLinkRow) CreateStmt

func (c ClusterLinkRow) CreateStmt() string

CreateStmt returns a query that creates a ClusterLinkRow entity.

func (ClusterLinkRow) CreateValues

func (c ClusterLinkRow) CreateValues() []any

CreateValues returns a list of values from ClusterLinkRow entities matching the bind arguments in [CreateStmt].

func (ClusterLinkRow) Joins

func (c ClusterLinkRow) Joins() []string

Joins returns a slice of join expressions for ClusterLinkRow.

func (ClusterLinkRow) PKColumns

func (c ClusterLinkRow) PKColumns() []string

PKColumns returns the column names for the primary key of a ClusterLinkRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (ClusterLinkRow) PKValues

func (c ClusterLinkRow) PKValues() []any

PKValues returns the values for the primary key of a ClusterLinkRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (*ClusterLinkRow) ScanArgs

func (c *ClusterLinkRow) ScanArgs() []any

ScanArgs implements query.ScanArger for ClusterLinkRow. This returns references to struct fields in definition order.

func (ClusterLinkRow) SelectColumns

func (c ClusterLinkRow) SelectColumns() []string

SelectColumns returns a slice of column names for ClusterLinkRow entities.

func (ClusterLinkRow) TableName

func (c ClusterLinkRow) TableName() string

TableName returns the table name for ClusterLinkRow entities.

func (*ClusterLinkRow) ToAPI

func (r *ClusterLinkRow) ToAPI(allConfigs map[int64]map[string]string) *api.ClusterLink

ToAPI converts the database ClusterLinkRow struct to API type api.ClusterLink.

func (ClusterLinkRow) UpdateStmt

func (c ClusterLinkRow) UpdateStmt() string

UpdateStmt returns a query that updates a ClusterLinkRow by primary key.

func (ClusterLinkRow) UpdateValues

func (c ClusterLinkRow) UpdateValues() []any

UpdateValues returns a list of values from ClusterLinkRow entities matching the columns in [UpdateStmt].

type ClusterLinkType

type ClusterLinkType string

ClusterLinkType represents the type of a cluster link stored as a string in the database.

This type implements the sql.Scanner and [driver.Value] interfaces to automatically handle conversion between API constants and their int64 representation in the database. When reading from the database, int64 values are converted back to their constant type. When writing to the database, API constants are converted to their int64 representation.

func (*ClusterLinkType) Scan

func (c *ClusterLinkType) Scan(value any) error

Scan implements sql.Scanner for ClusterLinkType. This converts the database integer value back into the correct API constant or returns an error.

func (*ClusterLinkType) ScanInteger

func (c *ClusterLinkType) ScanInteger(clusterLinkTypeCode int64) error

ScanInteger implements query.IntegerScanner for ClusterLinkType.

func (ClusterLinkType) Value

func (c ClusterLinkType) Value() (driver.Value, error)

Value implements [driver.Value] for ClusterLinkType. This converts the API constant into its integer database representation or throws an error.

type Config

type Config struct {
	ID          int `db:"primary=yes"`
	ReferenceID int
	Key         string
	Value       string
}

Config is a reference struct representing one configuration entry of another entity.

type ConfigFilter

type ConfigFilter struct {
	Key   *string
	Value *string
}

ConfigFilter specifies potential query parameter fields.

type ConfigGenerated

type ConfigGenerated interface {
	// GetConfig returns all available config.
	// generator: config GetMany
	GetConfig(ctx context.Context, tx *sql.Tx, parent string, filters ...ConfigFilter) (map[int]map[string]string, error)

	// CreateConfig adds a new config to the database.
	// generator: config Create
	CreateConfig(ctx context.Context, tx *sql.Tx, parent string, object Config) error

	// UpdateConfig updates the config matching the given key parameters.
	// generator: config Update
	UpdateConfig(ctx context.Context, tx *sql.Tx, parent string, referenceID int, config map[string]string) error

	// DeleteConfig deletes the config matching the given key parameters.
	// generator: config DeleteMany
	DeleteConfig(ctx context.Context, tx *sql.Tx, parent string, referenceID int) error
}

ConfigGenerated is an interface of generated methods for Config.

type Device

type Device struct {
	ID          int
	ReferenceID int
	Name        string
	Type        DeviceType
	Config      map[string]string
}

Device is a reference struct representing another entity's device.

type DeviceFilter

type DeviceFilter struct {
	Name   *string
	Type   *DeviceType
	Config *ConfigFilter
}

DeviceFilter specifies potential query parameter fields.

type DeviceGenerated

type DeviceGenerated interface {
	// GetDevices returns all available devices for the parent entity.
	// generator: device GetMany
	GetDevices(ctx context.Context, tx *sql.Tx, parent string, filters ...DeviceFilter) (map[int][]Device, error)

	// CreateDevices adds a new device to the database.
	// generator: device Create
	CreateDevices(ctx context.Context, tx *sql.Tx, parent string, objects map[string]Device) error

	// UpdateDevices updates the device matching the given key parameters.
	// generator: device Update
	UpdateDevices(ctx context.Context, tx *sql.Tx, parent string, referenceID int, devices map[string]Device) error

	// DeleteDevices deletes the device matching the given key parameters.
	// generator: device DeleteMany
	DeleteDevices(ctx context.Context, tx *sql.Tx, parent string, referenceID int) error
}

DeviceGenerated is an interface of generated methods for Device.

type DeviceType

type DeviceType int

DeviceType represents the types of supported devices.

func NewDeviceType

func NewDeviceType(t string) (DeviceType, error)

NewDeviceType determines the device type from the given string, if supported.

func (DeviceType) String

func (t DeviceType) String() string

type EntityRef

type EntityRef struct {
	EntityType EntityType
	EntityID   int
	entity.Reference
}

EntityRef represents the expected format of entity URL queries.

func GetEntityReferenceFromURL

func GetEntityReferenceFromURL(ctx context.Context, tx *sql.Tx, entityURL *api.URL) (*EntityRef, error)

GetEntityReferenceFromURL gets a single EntityRef by parsing the given api.URL and finding the ID of the entity. It is used by the OpenFGA datastore implementation to find permissions for the entity with the given URL.

type EntityType

type EntityType string

EntityType is a database representation of an entity type.

EntityType is defined on string so that entity.Type constants can be converted by casting. The sql.Scanner and driver.Valuer interfaces are implemented on this type such that the string constants are converted into their int64 counterparts as they are written to the database, or converted back into an EntityType as they are read from the database. It is not possible to read/write invalid entity types from/to the database when using this type.

func (*EntityType) Scan

func (e *EntityType) Scan(value any) error

Scan implements sql.Scanner for EntityType. This converts the integer value back into the correct entity.Type constant or returns an error.

func (*EntityType) ScanInteger

func (e *EntityType) ScanInteger(entityTypeCode int64) error

ScanInteger implements query.IntegerScanner for EntityType. This simplifies the Scan implementation.

func (EntityType) Value

func (e EntityType) Value() (driver.Value, error)

Value implements driver.Valuer for EntityType. This converts the EntityType into an integer or throws an error.

type IdentitiesRow

type IdentitiesRow struct {
	ID         int64        `db:"id"`
	AuthMethod AuthMethod   `db:"auth_method"`
	Type       IdentityType `db:"type"`
	Identifier string       `db:"identifier"`
	Name       string       `db:"name"`
	Metadata   string       `db:"metadata"`
}

IdentitiesRow is a database representation of any authenticated party. db:model identities

func GetIdentitiesAndURLs

func GetIdentitiesAndURLs(ctx context.Context, tx *sql.Tx, authMethod *string, filter func(row IdentitiesRow) bool) ([]IdentitiesRow, []string, error)

GetIdentitiesAndURLs returns a list of identities and their URLs, filtered by optional authentication method and filter function. The filter function should return true to include the identity and false to omit it.

func GetIdentitiesByAuthGroupID

func GetIdentitiesByAuthGroupID(ctx context.Context, tx *sql.Tx, groupID int64) ([]IdentitiesRow, error)

GetIdentitiesByAuthGroupID returns the identities that are members of the group with the given ID.

func GetIdentityByAuthenticationMethodAndIdentifier

func GetIdentityByAuthenticationMethodAndIdentifier(ctx context.Context, tx *sql.Tx, authenticationMethod string, identifier string) (*IdentitiesRow, error)

GetIdentityByAuthenticationMethodAndIdentifier gets a single identity by authentication method and identifier.

func GetIdentityByID

func GetIdentityByID(ctx context.Context, tx *sql.Tx, id int64) (*IdentitiesRow, error)

GetIdentityByID gets a single identity with the given ID.

func GetIdentityByNameOrIdentifier

func GetIdentityByNameOrIdentifier(ctx context.Context, tx *sql.Tx, authenticationMethod string, nameOrID string) (*IdentitiesRow, error)

GetIdentityByNameOrIdentifier attempts to get an identity by the authentication method and identifier. If that fails it will try to use the nameOrID argument as a name and will return the result only if the query matches a single IdentitiesRow. It will return an api.StatusError with http.StatusNotFound if none are found or http.StatusBadRequest if multiple are found.

func GetPendingTLSIdentityByTokenSecret

func GetPendingTLSIdentityByTokenSecret(ctx context.Context, tx *sql.Tx, secret string) (*IdentitiesRow, error)

GetPendingTLSIdentityByTokenSecret gets a single identity of type [identityTypeCertificateClientPending] or [identityTypeCertificateClusterLinkPending] with the given secret in its metadata. If no pending identity is found, an api.StatusError is returned with http.StatusNotFound.

func (IdentitiesRow) APIName

func (IdentitiesRow) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (IdentitiesRow) APIPluralName

func (IdentitiesRow) APIPluralName() string

APIPluralName implements query.APIPluralNamer for IdentitiesRow to override default pluralisation behaviour for error messages (which simply appends an "s").

func (IdentitiesRow) CreateStmt

func (i IdentitiesRow) CreateStmt() string

CreateStmt returns a query that creates a IdentitiesRow entity.

func (IdentitiesRow) CreateValues

func (i IdentitiesRow) CreateValues() []any

CreateValues returns a list of values from IdentitiesRow entities matching the bind arguments in [CreateStmt].

func (IdentitiesRow) Joins

func (i IdentitiesRow) Joins() []string

Joins returns a slice of join expressions for IdentitiesRow.

func (IdentitiesRow) OIDCMetadata

func (i IdentitiesRow) OIDCMetadata() (*OIDCMetadata, error)

OIDCMetadata returns the identity metadata as OIDCMetadata. The AuthMethod of the IdentitiesRow must be api.AuthenticationMethodOIDC.

func (IdentitiesRow) PKColumns

func (i IdentitiesRow) PKColumns() []string

PKColumns returns the column names for the primary key of a IdentitiesRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (IdentitiesRow) PKValues

func (i IdentitiesRow) PKValues() []any

PKValues returns the values for the primary key of a IdentitiesRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (IdentitiesRow) PendingTLSMetadata

func (i IdentitiesRow) PendingTLSMetadata() (*PendingTLSMetadata, error)

PendingTLSMetadata returns the pending TLS identity metadata.

func (*IdentitiesRow) ScanArgs

func (i *IdentitiesRow) ScanArgs() []any

ScanArgs implements query.ScanArger for IdentitiesRow. This returns references to struct fields in definition order.

func (IdentitiesRow) SelectColumns

func (i IdentitiesRow) SelectColumns() []string

SelectColumns returns a slice of column names for IdentitiesRow entities.

func (IdentitiesRow) TableName

func (i IdentitiesRow) TableName() string

TableName returns the table name for IdentitiesRow entities.

func (*IdentitiesRow) ToAPI

func (i *IdentitiesRow) ToAPI(idToGroups map[int64][]string, idToCertificates map[int64][]string) (*api.Identity, error)

ToAPI converts an IdentitiesRow to an api.Identity, executing database queries as necessary.

func (IdentitiesRow) ToCertificate

func (i IdentitiesRow) ToCertificate(idToCert map[int64][]string) (*CertificateLegacy, error)

ToCertificate converts an IdentitiesRow to a CertificateLegacy.

func (IdentitiesRow) UpdateStmt

func (i IdentitiesRow) UpdateStmt() string

UpdateStmt returns a query that updates a IdentitiesRow by primary key.

func (IdentitiesRow) UpdateValues

func (i IdentitiesRow) UpdateValues() []any

UpdateValues returns a list of values from IdentitiesRow entities matching the columns in [UpdateStmt].

type IdentityCertificate

type IdentityCertificate struct {
	Row CertificatesRow

	// db:join JOIN identities_certificates ON certificates.id = identities_certificates.certificate_id
	IdentityID int64 `db:"identities_certificates.identity_id"`
}

IdentityCertificate represents a certificate that is associated with an IdentitiesRow. db:model certificates

func (IdentityCertificate) APIName

func (i IdentityCertificate) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (IdentityCertificate) Joins

func (i IdentityCertificate) Joins() []string

Joins returns a slice of join expressions for IdentityCertificate.

func (*IdentityCertificate) ScanArgs

func (i *IdentityCertificate) ScanArgs() []any

ScanArgs implements query.ScanArger for IdentityCertificate. This returns references to struct fields in definition order.

func (IdentityCertificate) SelectColumns

func (i IdentityCertificate) SelectColumns() []string

SelectColumns returns a slice of column names for IdentityCertificate entities.

func (IdentityCertificate) TableName

func (i IdentityCertificate) TableName() string

TableName returns the table name for IdentityCertificate entities.

type IdentityProviderGroupsRow

type IdentityProviderGroupsRow struct {
	ID   int64  `db:"id"`
	Name string `db:"name"`
}

IdentityProviderGroupsRow is the database representation of an identity provider group. db:model identity_provider_groups

func GetIdentityProviderGroup

func GetIdentityProviderGroup(ctx context.Context, tx *sql.Tx, name string) (*IdentityProviderGroupsRow, error)

GetIdentityProviderGroup returns the identity provider group with the given name.

func GetIdentityProviderGroups

func GetIdentityProviderGroups(ctx context.Context, tx *sql.Tx) ([]IdentityProviderGroupsRow, error)

GetIdentityProviderGroups returns all identity provider groups.

func GetIdentityProviderGroupsByGroupID

func GetIdentityProviderGroupsByGroupID(ctx context.Context, tx *sql.Tx, groupID int64) ([]IdentityProviderGroupsRow, error)

GetIdentityProviderGroupsByGroupID returns the identity provider groups that map to the group with the given ID.

func (IdentityProviderGroupsRow) APIName

func (i IdentityProviderGroupsRow) APIName() string

APIName returns a human-readable name for the entity.

func (IdentityProviderGroupsRow) CreateStmt

func (i IdentityProviderGroupsRow) CreateStmt() string

CreateStmt returns a query that creates a IdentityProviderGroupsRow entity.

func (IdentityProviderGroupsRow) CreateValues

func (i IdentityProviderGroupsRow) CreateValues() []any

CreateValues returns a list of values from IdentityProviderGroupsRow entities matching the bind arguments in [CreateStmt].

func (IdentityProviderGroupsRow) Joins

func (i IdentityProviderGroupsRow) Joins() []string

Joins returns a slice of join expressions for IdentityProviderGroupsRow.

func (IdentityProviderGroupsRow) PKColumns

func (i IdentityProviderGroupsRow) PKColumns() []string

PKColumns returns the column names for the primary key of a IdentityProviderGroupsRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (IdentityProviderGroupsRow) PKValues

func (i IdentityProviderGroupsRow) PKValues() []any

PKValues returns the values for the primary key of a IdentityProviderGroupsRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (*IdentityProviderGroupsRow) ScanArgs

func (i *IdentityProviderGroupsRow) ScanArgs() []any

ScanArgs implements query.ScanArger for IdentityProviderGroupsRow. This returns references to struct fields in definition order.

func (IdentityProviderGroupsRow) SelectColumns

func (i IdentityProviderGroupsRow) SelectColumns() []string

SelectColumns returns a slice of column names for IdentityProviderGroupsRow entities.

func (IdentityProviderGroupsRow) TableName

func (i IdentityProviderGroupsRow) TableName() string

TableName returns the table name for IdentityProviderGroupsRow entities.

func (*IdentityProviderGroupsRow) ToAPI

ToAPI converts the IdentityProviderGroupsRow to an api.IdentityProviderGroup, making more database calls as necessary.

func (IdentityProviderGroupsRow) UpdateStmt

func (i IdentityProviderGroupsRow) UpdateStmt() string

UpdateStmt returns a query that updates a IdentityProviderGroupsRow by primary key.

func (IdentityProviderGroupsRow) UpdateValues

func (i IdentityProviderGroupsRow) UpdateValues() []any

UpdateValues returns a list of values from IdentityProviderGroupsRow entities matching the columns in [UpdateStmt].

type IdentityType

type IdentityType string

IdentityType indicates the type of the identity.

IdentityType is defined on string so that API constants can be converted by casting. The sql.Scanner and [driver.Valuer] interfaces are implemented on this type such that the string constants are converted into their int64 counterparts as they are written to the database, or converted back into an IdentityType as they are read from the database. It is not possible to read/write an invalid identity types from/to the database when using this type.

func (IdentityType) ActiveType

func (i IdentityType) ActiveType() (IdentityType, error)

ActiveType returns the active version of the identity type.

func (*IdentityType) Scan

func (i *IdentityType) Scan(value any) error

Scan implements sql.Scanner for IdentityType. This converts the integer value back into the correct API constant or returns an error.

func (*IdentityType) ScanInteger

func (i *IdentityType) ScanInteger(identityTypeCode int64) error

ScanInteger implements query.IntegerScanner for IdentityType. This simplifies the Scan implementation.

func (IdentityType) Value

func (i IdentityType) Value() (driver.Value, error)

Value implements [driver.Valuer] for IdentityType. This converts the API constant into an integer or throws an error.

type Image

type Image struct {
	ID           int
	Project      string `db:"primary=yes&join=projects.name"`
	Fingerprint  string `db:"primary=yes"`
	Type         int
	Filename     string
	Size         int64
	Public       bool
	Architecture int
	CreationDate sql.NullTime
	ExpiryDate   sql.NullTime
	UploadDate   time.Time
	Cached       bool
	LastUseDate  sql.NullTime
	AutoUpdate   bool
}

Image is a value object holding db-related details about an image.

func GetImage

func GetImage(ctx context.Context, tx *sql.Tx, project string, fingerprint string) (*Image, error)

GetImage returns the image with the given key. generator: image GetOne

func GetImages

func GetImages(ctx context.Context, tx *sql.Tx, filters ...ImageFilter) ([]Image, error)

GetImages returns all available images. generator: image GetMany

func (*Image) ToAPI

func (img *Image) ToAPI(ctx context.Context, tx *sql.Tx, profileProject string) (*api.Image, error)

ToAPI converts the Image to an api.Image, making extra database queries as necessary. If the profileProject is non-empty then its used to populate the image's profiles using the effective profile project.

type ImageFilter

type ImageFilter struct {
	ID          *int
	Project     *string
	Fingerprint *string
	Public      *bool
	Cached      *bool
	AutoUpdate  *bool
}

ImageFilter can be used to filter results yielded by GetImages.

type ImageGenerated

type ImageGenerated interface {
	// GetImages returns all available images.
	// generator: image GetMany
	GetImages(ctx context.Context, tx *sql.Tx, filters ...ImageFilter) ([]Image, error)

	// GetImage returns the image with the given key.
	// generator: image GetOne
	GetImage(ctx context.Context, tx *sql.Tx, project string, fingerprint string) (*Image, error)
}

ImageGenerated is an interface of generated methods for Image.

type Instance

type Instance struct {
	ID           int
	Project      string `db:"primary=yes&join=projects.name"`
	Name         string `db:"primary=yes"`
	Node         string `db:"join=nodes.name"`
	Type         instancetype.Type
	Snapshot     bool `db:"ignore"`
	Architecture int
	Ephemeral    bool
	CreationDate time.Time
	Stateful     bool
	LastUseDate  sql.NullTime
	Description  string `db:"coalesce=''"`
	ExpiryDate   sql.NullTime
}

Instance is a value object holding db-related details about an instance.

func GetInstance

func GetInstance(ctx context.Context, tx *sql.Tx, project string, name string) (*Instance, error)

GetInstance returns the instance with the given key. generator: instance GetOne

func GetInstances

func GetInstances(ctx context.Context, tx *sql.Tx, filters ...InstanceFilter) ([]Instance, error)

GetInstances returns all available instances. generator: instance GetMany

func GetProfileInstances

func GetProfileInstances(ctx context.Context, tx *sql.Tx, profileID int) ([]Instance, error)

GetProfileInstances returns all available Instances for the Profile.

type InstanceFilter

type InstanceFilter struct {
	ID      *int
	Project *string
	Name    *string
	Node    *string
	Type    *instancetype.Type
}

InstanceFilter specifies potential query parameter fields.

type InstanceGenerated

type InstanceGenerated interface {
	// GetInstanceConfig returns all available Instance Config
	// generator: instance GetMany
	GetInstanceConfig(ctx context.Context, tx *sql.Tx, instanceID int, filters ...ConfigFilter) (map[string]string, error)

	// GetInstanceDevices returns all available Instance Devices
	// generator: instance GetMany
	GetInstanceDevices(ctx context.Context, tx *sql.Tx, instanceID int, filters ...DeviceFilter) (map[string]Device, error)

	// GetInstances returns all available instances.
	// generator: instance GetMany
	GetInstances(ctx context.Context, tx *sql.Tx, filters ...InstanceFilter) ([]Instance, error)

	// GetInstance returns the instance with the given key.
	// generator: instance GetOne
	GetInstance(ctx context.Context, tx *sql.Tx, project string, name string) (*Instance, error)

	// GetInstanceID return the ID of the instance with the given key.
	// generator: instance ID
	GetInstanceID(ctx context.Context, tx *sql.Tx, project string, name string) (int64, error)

	// CreateInstanceConfig adds new instance Config to the database.
	// generator: instance Create
	CreateInstanceConfig(ctx context.Context, tx *sql.Tx, instanceID int64, config map[string]string) error

	// CreateInstanceDevices adds new instance Devices to the database.
	// generator: instance Create
	CreateInstanceDevices(ctx context.Context, tx *sql.Tx, instanceID int64, devices map[string]Device) error

	// CreateInstance adds a new instance to the database.
	// generator: instance Create
	CreateInstance(ctx context.Context, tx *sql.Tx, object Instance) (int64, error)

	// RenameInstance renames the instance matching the given key parameters.
	// generator: instance Rename
	RenameInstance(ctx context.Context, tx *sql.Tx, project string, name string, to string) error

	// DeleteInstance deletes the instance matching the given key parameters.
	// generator: instance DeleteOne-by-Project-and-Name
	DeleteInstance(ctx context.Context, tx *sql.Tx, project string, name string) error

	// UpdateInstanceConfig updates the instance Config matching the given key parameters.
	// generator: instance Update
	UpdateInstanceConfig(ctx context.Context, tx *sql.Tx, instanceID int64, config map[string]string) error

	// UpdateInstanceDevices updates the instance Device matching the given key parameters.
	// generator: instance Update
	UpdateInstanceDevices(ctx context.Context, tx *sql.Tx, instanceID int64, devices map[string]Device) error

	// UpdateInstance updates the instance matching the given key parameters.
	// generator: instance Update
	UpdateInstance(ctx context.Context, tx *sql.Tx, project string, name string, object Instance) error
}

InstanceGenerated is an interface of generated methods for Instance.

type InstanceSnapshot

type InstanceSnapshot struct {
	ID           int
	Project      string `db:"primary=yes&join=projects.name&joinon=instances.project_id"`
	Instance     string `db:"primary=yes&join=instances.name"`
	Name         string `db:"primary=yes"`
	CreationDate time.Time
	Stateful     bool
	Description  string `db:"coalesce=''"`
	ExpiryDate   sql.NullTime
}

InstanceSnapshot is a value object holding db-related details about a snapshot.

func GetInstanceSnapshot

func GetInstanceSnapshot(ctx context.Context, tx *sql.Tx, project string, instance string, name string) (*InstanceSnapshot, error)

GetInstanceSnapshot returns the instance_snapshot with the given key. generator: instance_snapshot GetOne

func GetInstanceSnapshots

func GetInstanceSnapshots(ctx context.Context, tx *sql.Tx, filters ...InstanceSnapshotFilter) ([]InstanceSnapshot, error)

GetInstanceSnapshots returns all available instance_snapshots. generator: instance_snapshot GetMany

func (*InstanceSnapshot) ToInstance

func (s *InstanceSnapshot) ToInstance(parentName string, parentNode string, parentType instancetype.Type, parentArch int) Instance

ToInstance converts an instance snapshot to a database Instance, filling in extra fields from the parent instance.

type InstanceSnapshotFilter

type InstanceSnapshotFilter struct {
	ID       *int
	Project  *string
	Instance *string
	Name     *string
}

InstanceSnapshotFilter specifies potential query parameter fields.

type InstanceSnapshotGenerated

type InstanceSnapshotGenerated interface {
	// GetInstanceSnapshotConfig returns all available InstanceSnapshot Config
	// generator: instance_snapshot GetMany
	GetInstanceSnapshotConfig(ctx context.Context, tx *sql.Tx, instanceSnapshotID int, filters ...ConfigFilter) (map[string]string, error)

	// GetInstanceSnapshotDevices returns all available InstanceSnapshot Devices
	// generator: instance_snapshot GetMany
	GetInstanceSnapshotDevices(ctx context.Context, tx *sql.Tx, instanceSnapshotID int, filters ...DeviceFilter) (map[string]Device, error)

	// GetInstanceSnapshots returns all available instance_snapshots.
	// generator: instance_snapshot GetMany
	GetInstanceSnapshots(ctx context.Context, tx *sql.Tx, filters ...InstanceSnapshotFilter) ([]InstanceSnapshot, error)

	// GetInstanceSnapshot returns the instance_snapshot with the given key.
	// generator: instance_snapshot GetOne
	GetInstanceSnapshot(ctx context.Context, tx *sql.Tx, project string, instance string, name string) (*InstanceSnapshot, error)

	// GetInstanceSnapshotID return the ID of the instance_snapshot with the given key.
	// generator: instance_snapshot ID
	GetInstanceSnapshotID(ctx context.Context, tx *sql.Tx, project string, instance string, name string) (int64, error)

	// CreateInstanceSnapshotConfig adds new instance_snapshot Config to the database.
	// generator: instance_snapshot Create
	CreateInstanceSnapshotConfig(ctx context.Context, tx *sql.Tx, instanceSnapshotID int64, config map[string]string) error

	// CreateInstanceSnapshotDevices adds new instance_snapshot Devices to the database.
	// generator: instance_snapshot Create
	CreateInstanceSnapshotDevices(ctx context.Context, tx *sql.Tx, instanceSnapshotID int64, devices map[string]Device) error

	// CreateInstanceSnapshot adds a new instance_snapshot to the database.
	// generator: instance_snapshot Create
	CreateInstanceSnapshot(ctx context.Context, tx *sql.Tx, object InstanceSnapshot) (int64, error)

	// RenameInstanceSnapshot renames the instance_snapshot matching the given key parameters.
	// generator: instance_snapshot Rename
	RenameInstanceSnapshot(ctx context.Context, tx *sql.Tx, project string, instance string, name string, to string) error

	// DeleteInstanceSnapshot deletes the instance_snapshot matching the given key parameters.
	// generator: instance_snapshot DeleteOne-by-Project-and-Instance-and-Name
	DeleteInstanceSnapshot(ctx context.Context, tx *sql.Tx, project string, instance string, name string) error
}

InstanceSnapshotGenerated is an interface of generated methods for InstanceSnapshot.

type InstancesProfilesRow

type InstancesProfilesRow struct {
	ID         int64 `db:"id"`
	InstanceID int64 `db:"instance_id"`
	ProfileID  int64 `db:"profile_id"`
	ApplyOrder int64 `db:"apply_order"`
}

InstancesProfilesRow represents a single row of the instances_profiles table. db:model instances_profiles

func (InstancesProfilesRow) APIName

func (InstancesProfilesRow) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (InstancesProfilesRow) CreateStmt

func (i InstancesProfilesRow) CreateStmt() string

CreateStmt returns a query that creates a InstancesProfilesRow entity.

func (InstancesProfilesRow) CreateValues

func (i InstancesProfilesRow) CreateValues() []any

CreateValues returns a list of values from InstancesProfilesRow entities matching the bind arguments in [CreateStmt].

func (InstancesProfilesRow) Joins

func (i InstancesProfilesRow) Joins() []string

Joins returns a slice of join expressions for InstancesProfilesRow.

func (InstancesProfilesRow) PKColumns

func (i InstancesProfilesRow) PKColumns() []string

PKColumns returns the column names for the primary key of a InstancesProfilesRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (InstancesProfilesRow) PKValues

func (i InstancesProfilesRow) PKValues() []any

PKValues returns the values for the primary key of a InstancesProfilesRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (*InstancesProfilesRow) ScanArgs

func (i *InstancesProfilesRow) ScanArgs() []any

ScanArgs implements query.ScanArger for InstancesProfilesRow. This returns references to struct fields in definition order.

func (InstancesProfilesRow) SelectColumns

func (i InstancesProfilesRow) SelectColumns() []string

SelectColumns returns a slice of column names for InstancesProfilesRow entities.

func (InstancesProfilesRow) TableName

func (i InstancesProfilesRow) TableName() string

TableName returns the table name for InstancesProfilesRow entities.

func (InstancesProfilesRow) UpdateStmt

func (i InstancesProfilesRow) UpdateStmt() string

UpdateStmt returns a query that updates a InstancesProfilesRow by primary key.

func (InstancesProfilesRow) UpdateValues

func (i InstancesProfilesRow) UpdateValues() []any

UpdateValues returns a list of values from InstancesProfilesRow entities matching the columns in [UpdateStmt].

type Node

type Node struct {
	ID   int
	Name string
}

Node represents a LXD cluster node.

type NodeFilter

type NodeFilter struct {
	Name *string
}

NodeFilter specifies potential query parameter fields.

type NodesClusterGroups

type NodesClusterGroups struct {
	Row NodesClusterGroupsRow

	// db:join JOIN nodes ON nodes_cluster_groups.node_id = nodes.id
	NodeName string `db:"nodes.name"`
}

NodesClusterGroups contains NodesClusterGroupsRow with additional joins. db:model nodes_cluster_groups

func GetNodesClusterGroupsByGroupID

func GetNodesClusterGroupsByGroupID(ctx context.Context, tx *sql.Tx, groupID int64) ([]NodesClusterGroups, error)

GetNodesClusterGroupsByGroupID returns node cluster group associations for a given group ID.

func (NodesClusterGroups) APIName

func (n NodesClusterGroups) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (NodesClusterGroups) Joins

func (n NodesClusterGroups) Joins() []string

Joins returns a slice of join expressions for NodesClusterGroups.

func (*NodesClusterGroups) ScanArgs

func (n *NodesClusterGroups) ScanArgs() []any

ScanArgs implements query.ScanArger for NodesClusterGroups. This returns references to struct fields in definition order.

func (NodesClusterGroups) SelectColumns

func (n NodesClusterGroups) SelectColumns() []string

SelectColumns returns a slice of column names for NodesClusterGroups entities.

func (NodesClusterGroups) TableName

func (n NodesClusterGroups) TableName() string

TableName returns the table name for NodesClusterGroups entities.

type NodesClusterGroupsRow

type NodesClusterGroupsRow struct {
	ID      int64 `db:"id"`
	NodeID  int64 `db:"node_id"`
	GroupID int64 `db:"group_id"`
}

NodesClusterGroupsRow represents a single row of the nodes_cluster_groups table. db:model nodes_cluster_groups

func (NodesClusterGroupsRow) APIName

func (NodesClusterGroupsRow) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (NodesClusterGroupsRow) CreateStmt

func (n NodesClusterGroupsRow) CreateStmt() string

CreateStmt returns a query that creates a NodesClusterGroupsRow entity.

func (NodesClusterGroupsRow) CreateValues

func (n NodesClusterGroupsRow) CreateValues() []any

CreateValues returns a list of values from NodesClusterGroupsRow entities matching the bind arguments in [CreateStmt].

func (NodesClusterGroupsRow) Joins

func (n NodesClusterGroupsRow) Joins() []string

Joins returns a slice of join expressions for NodesClusterGroupsRow.

func (NodesClusterGroupsRow) PKColumns

func (n NodesClusterGroupsRow) PKColumns() []string

PKColumns returns the column names for the primary key of a NodesClusterGroupsRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (NodesClusterGroupsRow) PKValues

func (n NodesClusterGroupsRow) PKValues() []any

PKValues returns the values for the primary key of a NodesClusterGroupsRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (*NodesClusterGroupsRow) ScanArgs

func (n *NodesClusterGroupsRow) ScanArgs() []any

ScanArgs implements query.ScanArger for NodesClusterGroupsRow. This returns references to struct fields in definition order.

func (NodesClusterGroupsRow) SelectColumns

func (n NodesClusterGroupsRow) SelectColumns() []string

SelectColumns returns a slice of column names for NodesClusterGroupsRow entities.

func (NodesClusterGroupsRow) TableName

func (n NodesClusterGroupsRow) TableName() string

TableName returns the table name for NodesClusterGroupsRow entities.

func (NodesClusterGroupsRow) UpdateStmt

func (n NodesClusterGroupsRow) UpdateStmt() string

UpdateStmt returns a query that updates a NodesClusterGroupsRow by primary key.

func (NodesClusterGroupsRow) UpdateValues

func (n NodesClusterGroupsRow) UpdateValues() []any

UpdateValues returns a list of values from NodesClusterGroupsRow entities matching the columns in [UpdateStmt].

type OIDCMetadata

type OIDCMetadata struct {
	Subject                string   `json:"subject"`
	IdentityProviderGroups []string `json:"identity_provider_groups"`
}

OIDCMetadata contains metadata for OIDC identities.

func (OIDCMetadata) Equals

func (o OIDCMetadata) Equals(m OIDCMetadata) bool

Equals returns true if the given OIDCMetadata is equal to the receiver.

type OIDCSession

type OIDCSession struct {
	ID           int
	UUID         uuid.UUID
	IdentityID   int64
	Email        string
	Username     string
	IDToken      string
	AccessToken  string
	RefreshToken string
	IP           string
	UserAgent    string
	ExpiryDate   time.Time
}

OIDCSession represents an OIDC session.

func GetAllOIDCSessions

func GetAllOIDCSessions(ctx context.Context, tx *sql.Tx) ([]OIDCSession, error)

GetAllOIDCSessions gets all OIDC sessions.

func GetOIDCSessionByUUID

func GetOIDCSessionByUUID(ctx context.Context, tx *sql.Tx, uuid uuid.UUID) (*OIDCSession, error)

GetOIDCSessionByUUID gets a session by UUID.

func GetOIDCSessionsByEmail

func GetOIDCSessionsByEmail(ctx context.Context, tx *sql.Tx, email string) ([]OIDCSession, error)

GetOIDCSessionsByEmail gets all sessions for the identity with the given email.

func (OIDCSession) ToAPI

func (s OIDCSession) ToAPI() api.OIDCSession

ToAPI returns an api.OIDCSession from the OIDCSession.

type Operation

type Operation struct {
	Row OperationsRow

	// db:join LEFT JOIN projects ON operations.project_id = projects.id
	ProjectName string `db:"coalesce(projects.name, '')"`

	// db:join JOIN nodes ON operations.node_id = nodes.id
	NodeAddress string `db:"nodes.address"`
	NodeName    string `db:"nodes.name"`

	// db:join LEFT JOIN identities ON operations.requestor_identity_id = identities.id
	IdentityIdentifier string `db:"coalesce(identities.identifier, '')"`
}

Operation enriches an OperationsRow with project, node, and identity information. db:model operations

func GetOperation

func GetOperation(ctx context.Context, tx *sql.Tx, operationUUID string) (*Operation, error)

GetOperation gets an Operation by UUID.

func GetOperationsByNodeID

func GetOperationsByNodeID(ctx context.Context, tx *sql.Tx, nodeID int64) ([]Operation, error)

GetOperationsByNodeID gets all operations on the given node ID.

func GetOperationsByProjectAndType

func GetOperationsByProjectAndType(ctx context.Context, tx *sql.Tx, projectName string, opType operationtype.Type) ([]Operation, error)

GetOperationsByProjectAndType returns a slice of Operation with the given project and type.

func GetOperationsWithParent

func GetOperationsWithParent(ctx context.Context, tx *sql.Tx, parentID int64) ([]Operation, error)

GetOperationsWithParent gets all operations whose parent operation has the given ID.

func GetParentOperations

func GetParentOperations(ctx context.Context, tx *sql.Tx) ([]Operation, error)

GetParentOperations returns all parent operation, that is all operations that don't have a parent.

func (Operation) APIName

func (o Operation) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (Operation) Joins

func (o Operation) Joins() []string

Joins returns a slice of join expressions for Operation.

func (*Operation) ScanArgs

func (o *Operation) ScanArgs() []any

ScanArgs implements query.ScanArger for Operation. This returns references to struct fields in definition order.

func (Operation) SelectColumns

func (o Operation) SelectColumns() []string

SelectColumns returns a slice of column names for Operation entities.

func (Operation) TableName

func (o Operation) TableName() string

TableName returns the table name for Operation entities.

type OperationFilter

type OperationFilter struct {
	ID     *int64
	NodeID *int64
	UUID   *string
	Parent *int64
}

OperationFilter specifies potential query parameter fields.

type OperationsRow

type OperationsRow struct {
	ID int64 `db:"id"`

	// db:omit update
	UUID   string `db:"uuid"`
	NodeID int64  `db:"node_id"`

	// db:omit update
	Type operationtype.Type `db:"type"`

	// db:omit update
	ProjectID *int64 `db:"project_id"`

	// db:omit update
	RequestorProtocol *RequestorProtocol `db:"requestor_protocol"`

	// db:omit update
	RequestorIdentityID *int64 `db:"requestor_identity_id"`

	// db:omit update
	EntityID int64  `db:"entity_id"`
	Metadata string `db:"metadata"`

	// db:omit update
	Class int64 `db:"class"`

	// db:omit update
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`

	// db:omit update
	Inputs     string `db:"inputs"`
	StatusCode int64  `db:"status_code"`
	Error      string `db:"error"`

	// db:omit update
	ConflictReference string `db:"conflict_reference"`

	// db:omit update
	Parent *int64 `db:"parent"`

	// db:omit update
	Stage     int64 `db:"stage"`
	ErrorCode int64 `db:"error_code"`
}

OperationsRow is a row of the operations table. db:model operations

func (OperationsRow) APIName

func (OperationsRow) APIName() string

APIName implements query.APINamer for OperationsRow for API friendly error messages.

func (OperationsRow) CreateStmt

func (o OperationsRow) CreateStmt() string

CreateStmt returns a query that creates a OperationsRow entity.

func (OperationsRow) CreateValues

func (o OperationsRow) CreateValues() []any

CreateValues returns a list of values from OperationsRow entities matching the bind arguments in [CreateStmt].

func (OperationsRow) Joins

func (o OperationsRow) Joins() []string

Joins returns a slice of join expressions for OperationsRow.

func (OperationsRow) PKColumns

func (o OperationsRow) PKColumns() []string

PKColumns returns the column names for the primary key of a OperationsRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (OperationsRow) PKValues

func (o OperationsRow) PKValues() []any

PKValues returns the values for the primary key of a OperationsRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (*OperationsRow) ScanArgs

func (o *OperationsRow) ScanArgs() []any

ScanArgs implements query.ScanArger for OperationsRow. This returns references to struct fields in definition order.

func (OperationsRow) SelectColumns

func (o OperationsRow) SelectColumns() []string

SelectColumns returns a slice of column names for OperationsRow entities.

func (OperationsRow) TableName

func (o OperationsRow) TableName() string

TableName returns the table name for OperationsRow entities.

func (OperationsRow) UpdateStmt

func (o OperationsRow) UpdateStmt() string

UpdateStmt returns a query that updates a OperationsRow by primary key.

func (OperationsRow) UpdateValues

func (o OperationsRow) UpdateValues() []any

UpdateValues returns a list of values from OperationsRow entities matching the columns in [UpdateStmt].

type PendingTLSMetadata

type PendingTLSMetadata struct {
	Secret string    `json:"secret"`
	Expiry time.Time `json:"expiry"`
}

PendingTLSMetadata contains metadata for the pending TLS certificate identity type.

type Permission

type Permission struct {
	ID          int
	GroupID     int64
	Entitlement auth.Entitlement
	EntityType  EntityType
	EntityID    int
}

Permission is the database representation of an api.Permission.

func GetDistinctPermissionsByGroupNames

func GetDistinctPermissionsByGroupNames(ctx context.Context, tx *sql.Tx, groupNames []string) ([]Permission, error)

GetDistinctPermissionsByGroupNames gets all distinct permissions that the groups with the given names have been granted.

func GetPermissionEntityURLs

func GetPermissionEntityURLs(ctx context.Context, tx *sql.Tx, permissions []Permission) ([]Permission, map[entity.Type]map[int]*api.URL, error)

GetPermissionEntityURLs accepts a slice of Permission as input. The input Permission slice may include permissions that are no longer valid because the entity against which they are defined no longer exists. This method determines which permissions are valid and which are not valid by attempting to retrieve their entity URL. It uses as few queries as possible to do this. It returns a slice of valid permissions and a map of entity.Type, to entity ID, to api.URL. The returned map contains the URL of the entity of each returned valid permission. It is used for populating api.Permission. A warning is logged if any invalid permissions are found. And error is returned if any query returns unexpected error.

func GetPermissions

func GetPermissions(ctx context.Context, tx *sql.Tx) ([]Permission, error)

GetPermissions returns a map of group ID to the permissions that belong to the auth group with that ID.

func GetPermissionsByAuthGroupID

func GetPermissionsByAuthGroupID(ctx context.Context, tx *sql.Tx, groupID int64) ([]Permission, error)

GetPermissionsByAuthGroupID returns the permissions that belong to the group with the given ID.

type PlacementGroup

type PlacementGroup struct {
	Row PlacementGroupsRow

	// db:join JOIN projects ON placement_groups.project_id = projects.id
	ProjectName string `db:"projects.name"`
}

PlacementGroup contains PlacementGroupsRow with additional joins. db:model placement_groups

func GetPlacementGroup

func GetPlacementGroup(ctx context.Context, tx *sql.Tx, name string, projectName string) (*PlacementGroup, error)

GetPlacementGroup gets a PlacementGroup by name and project.

func GetPlacementGroupsAndURLs

func GetPlacementGroupsAndURLs(ctx context.Context, tx *sql.Tx, projectName *string, filter func(group PlacementGroup) bool) ([]PlacementGroup, []string, error)

GetPlacementGroupsAndURLs queries for all placement groups and then applies the given filter to the result. This is useful when filtering by groups the caller is able to view. The filter must return true to include an entry, and false to reject an entry. A slice of (filtered) placement group URLs is also returned for convenience. If the project name argument is non-nil, only placement groups in that project are returned. If the project name is nil, placement groups from all projects are returned.

func (PlacementGroup) APIName

func (p PlacementGroup) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (PlacementGroup) Joins

func (p PlacementGroup) Joins() []string

Joins returns a slice of join expressions for PlacementGroup.

func (*PlacementGroup) ScanArgs

func (p *PlacementGroup) ScanArgs() []any

ScanArgs implements query.ScanArger for PlacementGroup. This returns references to struct fields in definition order.

func (PlacementGroup) SelectColumns

func (p PlacementGroup) SelectColumns() []string

SelectColumns returns a slice of column names for PlacementGroup entities.

func (PlacementGroup) TableName

func (p PlacementGroup) TableName() string

TableName returns the table name for PlacementGroup entities.

func (*PlacementGroup) ToAPI

func (p *PlacementGroup) ToAPI(configs map[int64]map[string]string) *api.PlacementGroup

ToAPI converts the PlacementGroup to an api.PlacementGroup, querying for extra data as necessary.

type PlacementGroupFilter

type PlacementGroupFilter struct {
	Project *string
	Name    *string
}

PlacementGroupFilter contains fields that can be used to filter results when getting placement groups.

type PlacementGroupsRow

type PlacementGroupsRow struct {
	ID          int64  `db:"id"`
	Name        string `db:"name"`
	Description string `db:"description"`
	ProjectID   int64  `db:"project_id"`
}

PlacementGroupsRow represents a single row of the placement_groups table. db:model placement_groups

func (PlacementGroupsRow) APIName

func (PlacementGroupsRow) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (PlacementGroupsRow) CreateStmt

func (p PlacementGroupsRow) CreateStmt() string

CreateStmt returns a query that creates a PlacementGroupsRow entity.

func (PlacementGroupsRow) CreateValues

func (p PlacementGroupsRow) CreateValues() []any

CreateValues returns a list of values from PlacementGroupsRow entities matching the bind arguments in [CreateStmt].

func (PlacementGroupsRow) Joins

func (p PlacementGroupsRow) Joins() []string

Joins returns a slice of join expressions for PlacementGroupsRow.

func (PlacementGroupsRow) PKColumns

func (p PlacementGroupsRow) PKColumns() []string

PKColumns returns the column names for the primary key of a PlacementGroupsRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (PlacementGroupsRow) PKValues

func (p PlacementGroupsRow) PKValues() []any

PKValues returns the values for the primary key of a PlacementGroupsRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (*PlacementGroupsRow) ScanArgs

func (p *PlacementGroupsRow) ScanArgs() []any

ScanArgs implements query.ScanArger for PlacementGroupsRow. This returns references to struct fields in definition order.

func (PlacementGroupsRow) SelectColumns

func (p PlacementGroupsRow) SelectColumns() []string

SelectColumns returns a slice of column names for PlacementGroupsRow entities.

func (PlacementGroupsRow) TableName

func (p PlacementGroupsRow) TableName() string

TableName returns the table name for PlacementGroupsRow entities.

func (PlacementGroupsRow) UpdateStmt

func (p PlacementGroupsRow) UpdateStmt() string

UpdateStmt returns a query that updates a PlacementGroupsRow by primary key.

func (PlacementGroupsRow) UpdateValues

func (p PlacementGroupsRow) UpdateValues() []any

UpdateValues returns a list of values from PlacementGroupsRow entities matching the columns in [UpdateStmt].

type Profile

type Profile struct {
	ID          int
	ProjectID   int    `db:"omit=create,update"`
	Project     string `db:"primary=yes&join=projects.name"`
	Name        string `db:"primary=yes"`
	Description string `db:"coalesce=''"`
}

Profile is a value object holding db-related details about a profile.

func GetInstanceProfiles

func GetInstanceProfiles(ctx context.Context, tx *sql.Tx, instanceID int) ([]Profile, error)

GetInstanceProfiles returns all available Profiles for the Instance.

func GetProfile

func GetProfile(ctx context.Context, tx *sql.Tx, project string, name string) (*Profile, error)

GetProfile returns the profile with the given key. generator: profile GetOne

func GetProfiles

func GetProfiles(ctx context.Context, tx *sql.Tx, filters ...ProfileFilter) ([]Profile, error)

GetProfiles returns all available profiles. generator: profile GetMany

func GetProfilesIfEnabled

func GetProfilesIfEnabled(ctx context.Context, tx *sql.Tx, projectName string, names []string) ([]Profile, error)

GetProfilesIfEnabled returns the profiles from the given project, or the default project if "features.profiles" is not set.

func (*Profile) ToAPI

func (p *Profile) ToAPI(ctx context.Context, tx *sql.Tx, profileConfigs map[int]map[string]string, profileDevices map[int][]Device) (*api.Profile, error)

ToAPI returns a cluster Profile as an API struct.

type ProfileFilter

type ProfileFilter struct {
	ID      *int
	Project *string
	Name    *string
}

ProfileFilter specifies potential query parameter fields.

type ProfileGenerated

type ProfileGenerated interface {
	// GetProfileID return the ID of the profile with the given key.
	// generator: profile ID
	GetProfileID(ctx context.Context, tx *sql.Tx, project string, name string) (int64, error)

	// GetProfileConfig returns all available Profile Config
	// generator: profile GetMany
	GetProfileConfig(ctx context.Context, tx *sql.Tx, profileID int, filters ...ConfigFilter) (map[string]string, error)

	// GetProfileDevices returns all available Profile Devices
	// generator: profile GetMany
	GetProfileDevices(ctx context.Context, tx *sql.Tx, profileID int, filters ...DeviceFilter) (map[string]Device, error)

	// GetProfiles returns all available profiles.
	// generator: profile GetMany
	GetProfiles(ctx context.Context, tx *sql.Tx, filters ...ProfileFilter) ([]Profile, error)

	// GetProfile returns the profile with the given key.
	// generator: profile GetOne
	GetProfile(ctx context.Context, tx *sql.Tx, project string, name string) (*Profile, error)

	// CreateProfileConfig adds new profile Config to the database.
	// generator: profile Create
	CreateProfileConfig(ctx context.Context, tx *sql.Tx, profileID int64, config map[string]string) error

	// CreateProfileDevices adds new profile Devices to the database.
	// generator: profile Create
	CreateProfileDevices(ctx context.Context, tx *sql.Tx, profileID int64, devices map[string]Device) error

	// CreateProfile adds a new profile to the database.
	// generator: profile Create
	CreateProfile(ctx context.Context, tx *sql.Tx, object Profile) (int64, error)

	// RenameProfile renames the profile matching the given key parameters.
	// generator: profile Rename
	RenameProfile(ctx context.Context, tx *sql.Tx, project string, name string, to string) error

	// UpdateProfileConfig updates the profile Config matching the given key parameters.
	// generator: profile Update
	UpdateProfileConfig(ctx context.Context, tx *sql.Tx, profileID int64, config map[string]string) error

	// UpdateProfileDevices updates the profile Device matching the given key parameters.
	// generator: profile Update
	UpdateProfileDevices(ctx context.Context, tx *sql.Tx, profileID int64, devices map[string]Device) error

	// UpdateProfile updates the profile matching the given key parameters.
	// generator: profile Update
	UpdateProfile(ctx context.Context, tx *sql.Tx, project string, name string, object Profile) error

	// DeleteProfile deletes the profile matching the given key parameters.
	// generator: profile DeleteOne-by-Project-and-Name
	DeleteProfile(ctx context.Context, tx *sql.Tx, project string, name string) error
}

ProfileGenerated is an interface of generated methods for Profile.

type Project

type Project struct {
	ID          int
	Description string
	Name        string             `db:"omit=update"`
	ReplicaMode ProjectReplicaMode `db:"omit=update"`
}

Project represents a LXD project.

func GetProject

func GetProject(ctx context.Context, tx *sql.Tx, name string) (*Project, error)

GetProject returns the project with the given key. generator: project GetOne

func GetProjectByID

func GetProjectByID(ctx context.Context, tx *sql.Tx, id int) (*Project, error)

GetProjectByID returns the project with the given ID.

func GetProjects

func GetProjects(ctx context.Context, tx *sql.Tx, filters ...ProjectFilter) ([]Project, error)

GetProjects returns all available projects. generator: project GetMany

func (*Project) ToAPI

func (p *Project) ToAPI(ctx context.Context, tx *sql.Tx) (*api.Project, error)

ToAPI converts the database Project struct to an api.Project entry.

type ProjectFeature

type ProjectFeature struct {
	// DefaultEnabled
	// Whether the feature should be enabled by default on new projects.
	DefaultEnabled bool

	// CanEnableNonEmpty
	// Whether or not the feature can be changed to enabled on a non-empty project.
	CanEnableNonEmpty bool
}

ProjectFeature indicates the behaviour of a project feature.

type ProjectFilter

type ProjectFilter struct {
	ID   *int
	Name *string `db:"omit=update"` // If non-empty, return only the project with this name.
}

ProjectFilter specifies potential query parameter fields.

type ProjectGenerated

type ProjectGenerated interface {
	// GetProjects returns all available projects.
	// generator: project GetMany
	GetProjects(ctx context.Context, tx *sql.Tx, filters ...ProjectFilter) ([]Project, error)

	// GetProject returns the project with the given key.
	// generator: project GetOne
	GetProject(ctx context.Context, tx *sql.Tx, name string) (*Project, error)

	// CreateProjectConfig adds new project Config to the database.
	// generator: project Create
	CreateProjectConfig(ctx context.Context, tx *sql.Tx, projectID int64, config map[string]string) error

	// CreateProject adds a new project to the database.
	// generator: project Create
	CreateProject(ctx context.Context, tx *sql.Tx, object Project) (int64, error)

	// GetProjectID return the ID of the project with the given key.
	// generator: project ID
	GetProjectID(ctx context.Context, tx *sql.Tx, name string) (int64, error)

	// RenameProject renames the project matching the given key parameters.
	// generator: project Rename
	RenameProject(ctx context.Context, tx *sql.Tx, name string, to string) error

	// DeleteProject deletes the project matching the given key parameters.
	// generator: project DeleteOne-by-Name
	DeleteProject(ctx context.Context, tx *sql.Tx, name string) error
}

ProjectGenerated is an interface of generated methods for Project.

type ProjectReplicaMode

type ProjectReplicaMode string

ProjectReplicaMode represents the replica mode of a project stored as an integer in the database.

This type implements the sql.Scanner and [driver.Valuer] interfaces to automatically handle conversion between API constants and their int64 representation in the database. When reading from the database, int64 values are converted back to their API constant. When writing to the database, API constants are converted to their int64 representation.

func (*ProjectReplicaMode) Scan

func (p *ProjectReplicaMode) Scan(value any) error

Scan implements sql.Scanner for ProjectReplicaMode. This converts the database integer value back into the correct API constant or returns an error.

func (*ProjectReplicaMode) ScanInteger

func (p *ProjectReplicaMode) ScanInteger(code int64) error

ScanInteger implements query.IntegerScanner for ProjectReplicaMode.

func (ProjectReplicaMode) Value

func (p ProjectReplicaMode) Value() (driver.Value, error)

Value implements [driver.Valuer] for ProjectReplicaMode. This converts the API constant into its integer database representation or returns an error.

type Replicator

type Replicator struct {
	Row ReplicatorRow

	// db:join JOIN projects ON replicators.project_id = projects.id
	ProjectName string `db:"projects.name"`
}

Replicator contains ReplicatorRow with additional joins. db:model replicators

func GetReplicator

func GetReplicator(ctx context.Context, tx *sql.Tx, name string, projectName string) (*Replicator, error)

GetReplicator returns the replicator with the given name and project.

func GetReplicatorsAndURLs

func GetReplicatorsAndURLs(ctx context.Context, tx *sql.Tx, projectName *string, filter func(replicator Replicator) bool) ([]Replicator, []string, error)

GetReplicatorsAndURLs returns all replicators that pass the given filter, along with their entity URLs.

func (Replicator) APIName

func (r Replicator) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (Replicator) Joins

func (r Replicator) Joins() []string

Joins returns a slice of join expressions for Replicator.

func (*Replicator) ScanArgs

func (r *Replicator) ScanArgs() []any

ScanArgs implements query.ScanArger for Replicator. This returns references to struct fields in definition order.

func (Replicator) SelectColumns

func (r Replicator) SelectColumns() []string

SelectColumns returns a slice of column names for Replicator entities.

func (Replicator) TableName

func (r Replicator) TableName() string

TableName returns the table name for Replicator entities.

func (*Replicator) ToAPI

func (r *Replicator) ToAPI(allConfigs map[int64]map[string]string) *api.Replicator

ToAPI converts the Replicator to an api.Replicator.

type ReplicatorRow

type ReplicatorRow struct {
	ID            int64        `db:"id"`
	Name          string       `db:"name"`
	ProjectID     int64        `db:"project_id"`
	Description   string       `db:"description"`
	LastRunDate   sql.NullTime `db:"last_run_date"`
	LastRunStatus string       `db:"last_run_status"`
}

ReplicatorRow represents a single row of the replicators table. db:model replicators

func (ReplicatorRow) APIName

func (ReplicatorRow) APIName() string

APIName implements query.APINamer for API friendly error messages.

func (ReplicatorRow) CreateStmt

func (r ReplicatorRow) CreateStmt() string

CreateStmt returns a query that creates a ReplicatorRow entity.

func (ReplicatorRow) CreateValues

func (r ReplicatorRow) CreateValues() []any

CreateValues returns a list of values from ReplicatorRow entities matching the bind arguments in [CreateStmt].

func (ReplicatorRow) Joins

func (r ReplicatorRow) Joins() []string

Joins returns a slice of join expressions for ReplicatorRow.

func (ReplicatorRow) PKColumns

func (r ReplicatorRow) PKColumns() []string

PKColumns returns the column names for the primary key of a ReplicatorRow entity used during an update. The returned slice must have the same number of elements as PKValues.

func (ReplicatorRow) PKValues

func (r ReplicatorRow) PKValues() []any

PKValues returns the values for the primary key of a ReplicatorRow entity used during an update. The returned slice must have the same number of elements as PKColumns.

func (*ReplicatorRow) ScanArgs

func (r *ReplicatorRow) ScanArgs() []any

ScanArgs implements query.ScanArger for ReplicatorRow. This returns references to struct fields in definition order.

func (ReplicatorRow) SelectColumns

func (r ReplicatorRow) SelectColumns() []string

SelectColumns returns a slice of column names for ReplicatorRow entities.

func (ReplicatorRow) TableName

func (r ReplicatorRow) TableName() string

TableName returns the table name for ReplicatorRow entities.

func (ReplicatorRow) UpdateStmt

func (r ReplicatorRow) UpdateStmt() string

UpdateStmt returns a query that updates a ReplicatorRow by primary key.

func (ReplicatorRow) UpdateValues

func (r ReplicatorRow) UpdateValues() []any

UpdateValues returns a list of values from ReplicatorRow entities matching the columns in [UpdateStmt].

type RequestorProtocol

type RequestorProtocol string

RequestorProtocol is the database representation of the Requestor Protocol.

RequestorProtocol is defined on string so that constants can be converted by casting. The sql.Scanner and [driver.Valuer] interfaces are implemented on this type such that the string constants are converted into their int64 counterparts as they are written to the database, or converted back into an RequestorProtocol as they are read from the database. It is not possible to read/write an invalid requestor protocol from/to the database when using this type.

func (*RequestorProtocol) Scan

func (r *RequestorProtocol) Scan(value any) error

Scan implements sql.Scanner for RequestorProtocol. This converts the integer value back into the correct constant or returns an error.

func (*RequestorProtocol) ScanInteger

func (r *RequestorProtocol) ScanInteger(requestorProtocolCode int64) error

ScanInteger implements query.IntegerScanner for RequestorProtocol. This simplifies the Scan implementation.

func (*RequestorProtocol) Value

func (r *RequestorProtocol) Value() (driver.Value, error)

Value implements [driver.Valuer] for RequestorProtocol. This converts the API constant into an integer or throws an error.

type SecretType

type SecretType string

SecretType represents the "type" column in the secrets table.

const (
	// SecretTypeCoreAuth is the SecretType for core auth secrets.
	SecretTypeCoreAuth SecretType = "core_auth"

	// SecretTypeBearerSigningKey is the SecretType for bearer identity signing keys.
	SecretTypeBearerSigningKey SecretType = "bearer_signing_key"
)

func (*SecretType) Scan

func (s *SecretType) Scan(value any) error

Scan implements sql.Scanner for SecretType.

Note: This method must have a pointer receiver because only a pointer to a SecretType implements query.IntegerScanner. The Value implementation does not require a pointer receiver. This is so that a non-pointer SecretType can be written to the database.

func (*SecretType) ScanInteger

func (s *SecretType) ScanInteger(code int64) error

ScanInteger implements query.IntegerScanner for SecretType to simplify the sql.Scanner implementation.

func (SecretType) Value

func (s SecretType) Value() (driver.Value, error)

Value implements [driver.Valuer] for SecretType.

type StoragePoolVolumeContentType

type StoragePoolVolumeContentType int

StoragePoolVolumeContentType records a volume's content-type in the database.

# Type Safety Funtions using this type should assume that a StoragePoolVolumeContentType is always a valid value; i.e. that it is type safe. Use the parsing methods below when converting to StoragePoolVolumeContentType.

const (
	StoragePoolVolumeContentTypeFS StoragePoolVolumeContentType = iota
	StoragePoolVolumeContentTypeBlock
	StoragePoolVolumeContentTypeISO
)

Content types.

func StoragePoolVolumeContentTypeFromInt

func StoragePoolVolumeContentTypeFromInt(contentType int) (StoragePoolVolumeContentType, error)

StoragePoolVolumeContentTypeFromInt is a checked conversion to StoragePoolVolumeContentType.

func StoragePoolVolumeContentTypeFromName

func StoragePoolVolumeContentTypeFromName(contentTypeName string) (StoragePoolVolumeContentType, error)

StoragePoolVolumeContentTypeFromName is a checked conversion to StoragePoolVolumeContentType.

func (StoragePoolVolumeContentType) String

String gives the name of a StoragePoolVolumeContentType.

# Safety This function assumes that `t` is one of the StoragePoolVolumeContentType enums defined above.

type StoragePoolVolumeType

type StoragePoolVolumeType int

StoragePoolVolumeType records a volume's type in the database.

# Type Safety Funtions using this type should assume that a StoragePoolVolumeType is always a valid value; i.e. that it is type safe. Use the parsing methods below when converting to StoragePoolVolumeType.

const (
	StoragePoolVolumeTypeContainer StoragePoolVolumeType = iota
	StoragePoolVolumeTypeImage
	StoragePoolVolumeTypeCustom
	StoragePoolVolumeTypeVM
)

XXX: this was extracted from lxd/storage_volume_utils.go, we find a way to factor it independently from both the db and main packages.

func StoragePoolVolumeTypeFromInt

func StoragePoolVolumeTypeFromInt(volType int) (StoragePoolVolumeType, error)

StoragePoolVolumeTypeFromInt is a checked conversion to StoragePoolVolumeType.

func StoragePoolVolumeTypeFromName

func StoragePoolVolumeTypeFromName(volTypeName string) (StoragePoolVolumeType, error)

StoragePoolVolumeTypeFromName is a checked conversion to StoragePoolVolumeType.

func (StoragePoolVolumeType) String

func (t StoragePoolVolumeType) String() string

String gives the name of a StoragePoolVolumeType.

# Safety This function assumes that `t` is one of the StoragePoolVolumeType enums defined above.

type Warning

type Warning struct {
	ID            int
	Node          string     `db:"coalesce=''&leftjoin=nodes.name"`
	Project       string     `db:"coalesce=''&leftjoin=projects.name"`
	EntityType    EntityType `db:"coalesce=-1&sql=warnings.entity_type_code"`
	EntityID      int        `db:"coalesce=-1"`
	UUID          string     `db:"primary=yes"`
	TypeCode      warningtype.Type
	Status        warningtype.Status
	FirstSeenDate time.Time
	LastSeenDate  time.Time
	UpdatedDate   time.Time
	LastMessage   string
	Count         int
}

Warning is a value object holding db-related details about a warning.

func GetWarning

func GetWarning(ctx context.Context, tx *sql.Tx, uuid string) (*Warning, error)

GetWarning returns the warning with the given key. generator: warning GetOne-by-UUID

func GetWarnings

func GetWarnings(ctx context.Context, tx *sql.Tx, filters ...WarningFilter) ([]Warning, error)

GetWarnings returns all available warnings. generator: warning GetMany

func (Warning) ToAPI

func (w Warning) ToAPI() api.Warning

ToAPI returns a LXD API entry.

type WarningFilter

type WarningFilter struct {
	ID         *int
	UUID       *string
	Project    *string
	Node       *string
	TypeCode   *warningtype.Type
	EntityType *EntityType
	EntityID   *int
	Status     *warningtype.Status
}

WarningFilter specifies potential query parameter fields.

type WarningGenerated

type WarningGenerated interface {
	// GetWarnings returns all available warnings.
	// generator: warning GetMany
	GetWarnings(ctx context.Context, tx *sql.Tx, filters ...WarningFilter) ([]Warning, error)

	// GetWarning returns the warning with the given key.
	// generator: warning GetOne-by-UUID
	GetWarning(ctx context.Context, tx *sql.Tx, uuid string) (*Warning, error)

	// DeleteWarning deletes the warning matching the given key parameters.
	// generator: warning DeleteOne-by-UUID
	DeleteWarning(ctx context.Context, tx *sql.Tx, uuid string) error

	// DeleteWarnings deletes the warning matching the given key parameters.
	// generator: warning DeleteMany-by-EntityType-and-EntityID
	DeleteWarnings(ctx context.Context, tx *sql.Tx, entityType EntityType, entityID int) error

	// GetWarningID return the ID of the warning with the given key.
	// generator: warning ID
	GetWarningID(ctx context.Context, tx *sql.Tx, uuid string) (int64, error)

	// WarningExists checks if a warning with the given key exists.
	// generator: warning Exists
	WarningExists(ctx context.Context, tx *sql.Tx, uuid string) (bool, error)
}

WarningGenerated is an interface of generated methods for Warning.

Source Files

Jump to

Keyboard shortcuts

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