Documentation
¶
Overview ¶
Package db provides database access and management for the k8Shell Provisioner service. It provides persistence for org-scoped blueprint definitions, layered on top of the file-based blueprints loaded by internal/blueprint.
Index ¶
- Variables
- type DB
- func (d *DB) CreateBlueprint(org, name, description string, yaml []byte, isTemplate bool) (*models.OrgBlueprint, error)
- func (d *DB) DeleteBlueprint(org, name string) error
- func (d *DB) GetBlueprint(org, name string) (*models.OrgBlueprint, error)
- func (d *DB) ListAllBlueprints() ([]*models.OrgBlueprint, error)
- func (d *DB) ListBlueprints(org string) ([]*models.OrgBlueprint, error)
- func (d *DB) LookupBlueprint(org, name string) (*models.OrgBlueprint, error)
- func (d *DB) UpdateBlueprint(org, name string, description *string, yaml []byte, isTemplate bool, ...) (*models.OrgBlueprint, error)
Constants ¶
This section is empty.
Variables ¶
var ErrBlueprintConflict = errors.New("org blueprint was modified concurrently")
ErrBlueprintConflict is returned by UpdateBlueprint when the stored blueprint no longer matches the content the caller based its update on.
var ErrBlueprintExists = errors.New("org blueprint already exists")
ErrBlueprintExists is returned by CreateBlueprint when a blueprint with the same (org, name) already exists.
var ErrBlueprintNotFound = errors.New("org blueprint not found")
ErrBlueprintNotFound is returned by GetBlueprint/UpdateBlueprint/ DeleteBlueprint when no blueprint with the given (org, name) exists.
var ErrOrgNotFound = errors.New("organization not found")
ErrOrgNotFound is returned by CreateBlueprint when org does not exist in identity.organizations (see the FK on org_blueprints.org).
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB wraps the shared database implementation for the provisioner service.
func (*DB) CreateBlueprint ¶
func (d *DB) CreateBlueprint(org, name, description string, yaml []byte, isTemplate bool) (*models.OrgBlueprint, error)
CreateBlueprint registers a new org-scoped blueprint.
func (*DB) DeleteBlueprint ¶
DeleteBlueprint removes an org blueprint from the registry. Returns ErrBlueprintNotFound when no blueprint with that (org, name) exists.
func (*DB) GetBlueprint ¶
func (d *DB) GetBlueprint(org, name string) (*models.OrgBlueprint, error)
GetBlueprint retrieves a single org blueprint by org and name. Returns ErrBlueprintNotFound when no blueprint with that (org, name) exists.
func (*DB) ListAllBlueprints ¶
func (d *DB) ListAllBlueprints() ([]*models.OrgBlueprint, error)
ListAllBlueprints returns every org blueprint across every org, ordered by org then name. Used by the blueprint manager to build its merged, file-plus-database view on load and on every reload.
func (*DB) ListBlueprints ¶
func (d *DB) ListBlueprints(org string) ([]*models.OrgBlueprint, error)
ListBlueprints returns every blueprint stored for a single org, ordered by name.
func (*DB) LookupBlueprint ¶
func (d *DB) LookupBlueprint(org, name string) (*models.OrgBlueprint, error)
LookupBlueprint behaves like GetBlueprint but returns (nil, nil) instead of ErrBlueprintNotFound when no row with that (org, name) exists, for callers that treat "absent" as a normal outcome rather than an error.
func (*DB) UpdateBlueprint ¶
func (d *DB) UpdateBlueprint(org, name string, description *string, yaml []byte, isTemplate bool, expectedYAML []byte) (*models.OrgBlueprint, error)
UpdateBlueprint replaces an existing org blueprint's yaml content, its is_template flag, and optionally its description. name and org together identify the blueprint and are immutable; pass a nil description to leave it unchanged. A non-nil expectedYAML makes the update a compare-and-swap: it is applied only if the stored yaml still equals expectedYAML, and ErrBlueprintConflict is returned otherwise. Returns ErrBlueprintNotFound when no blueprint with that (org, name) exists.