state

package
v0.0.0-...-0a82276 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Count

type Count struct {
	// Num is the number of rows.
	Num int `db:"num"`
}

Count is a helper struct to count the number of rows.

type ModelCloudCredentialRow

type ModelCloudCredentialRow struct {
	// CloudName is the name of the cloud.
	CloudName string `db:"cloud_name"`
	// CloudCredentialName is the name of the cloud credential.
	CloudCredentialName string `db:"cloud_credential_name"`
	// OwnerName is the name of the credential owner.
	OwnerName string `db:"owner_name"`
}

ModelCloudCredentialRow represents a single subset of cloud and credential related data from the v_model view.

type ModelSecretBackend

type ModelSecretBackend struct {
	// ControllerUUID is the UUID of the controller.
	ControllerUUID string `db:"controller_uuid"`
	// ModelID is the unique identifier for the model.
	ModelID coremodel.UUID `db:"uuid"`
	// ModelName is the name of the model.
	ModelName string `db:"name"`
	// ModelType is the type of the model.
	ModelType coremodel.ModelType `db:"model_type"`
	// SecretBackendID is the unique identifier for the secret backend configured for the model.
	SecretBackendID string `db:"secret_backend_uuid"`
	// SecretBackendName is the name of the secret backend configured for the model.
	SecretBackendName string `db:"secret_backend_name"`
}

ModelSecretBackend represents a set of data about a model and its current secret backend config.

type SecretBackend

type SecretBackend struct {
	// ID is the unique identifier for the secret backend.
	ID string `db:"uuid"`
	// Name is the name of the secret backend.
	Name string `db:"name"`
	// BackendType is the id of the secret backend type.
	BackendTypeID secretbackend.BackendType `db:"backend_type_id"`
	// TokenRotateInterval is the interval at which the token for the secret backend should be rotated.
	TokenRotateInterval database.NullDuration `db:"token_rotate_interval"`
}

SecretBackend represents a single row from the state database's secret_backend table.

type SecretBackendConfig

type SecretBackendConfig struct {
	// ID is the unique identifier for the secret backend.
	ID string `db:"backend_uuid"`
	// Name is the name of one record of the secret backend config.
	Name string `db:"name"`
	// Content is the content of the secret backend config.
	Content string `db:"content"`
}

SecretBackendConfig represents a single row from the state database's secret_backend_config table.

type SecretBackendReference

type SecretBackendReference struct {
	// BackendID is the unique identifier for the secret backend.
	BackendID string `db:"secret_backend_uuid"`
	// ModelID is the unique identifier for the model.
	ModelID coremodel.UUID `db:"model_uuid"`
	// SecretRevisionID is the unique identifier for the secret revision.
	SecretRevisionID string `db:"secret_revision_uuid"`
}

SecretBackendReference represents a single row from the state database's secret_backend_reference table.

type SecretBackendRotation

type SecretBackendRotation struct {
	// ID is the unique identifier for the secret backend.
	ID string `db:"backend_uuid"`
	// NextRotationTime is the time at which the token for the secret backend
	// should be rotated next.
	NextRotationTime sql.NullTime `db:"next_rotation_time"`
}

SecretBackendRotation represents a single row from the state database's secret_backend_rotation table.

type SecretBackendRotationRow

type SecretBackendRotationRow struct {
	// ID is the unique identifier for the secret backend.
	ID string `db:"uuid"`
	// Name is the name of the secret backend.
	Name string `db:"name"`
	// NextRotationTime is the time at which the token for the secret backend
	// should be rotated next.
	NextRotationTime sql.NullTime `db:"next_rotation_time"`
}

SecretBackendRotationRow represents a single joined result from secret_backend and secret_backend_rotation tables.

type SecretBackendRotationRows

type SecretBackendRotationRows []SecretBackendRotationRow

type SecretBackendRow

type SecretBackendRow struct {
	// ID is the unique identifier for the secret backend.
	ID string `db:"uuid"`
	// Name is the name of the secret backend.
	Name string `db:"name"`
	// BackendType is the type of the secret backend.
	BackendType string `db:"backend_type"`
	// TokenRotateInterval is the interval at which the token for the secret
	// backend should be rotated.
	TokenRotateInterval database.NullDuration `db:"token_rotate_interval"`
	// ConfigName is the name of one record of the secret backend config.
	ConfigName string `db:"config_name"`
	// ConfigContent is the content of the secret backend config.
	ConfigContent string `db:"config_content"`
	// NumSecrets is the number of secrets stored in the secret backend.
	NumSecrets int `db:"num_secrets"`
}

SecretBackendRow represents a single joined result from secret_backend and secret_backend_config tables.

type State

type State struct {
	*domain.StateBase
	// contains filtered or unexported fields
}

State represents database interactions dealing with secret backends.

func NewState

func NewState(factory coredatabase.TxnRunnerFactory, logger logger.Logger) *State

NewState returns a new secret backend state based on the input database factory method.

func (*State) AddSecretBackendReference

func (s *State) AddSecretBackendReference(
	ctx context.Context, valueRef *secrets.ValueRef, modelID coremodel.UUID, revisionID string,
) (func() error, error)

AddSecretBackendReference adds a reference to the secret backend for the given secret revision, returning an error satisfying secretbackenderrors.NotFound if the secret backend does not exist, or modelerrors.NotFound if the model does not exist, or secretbackenderrors.RefCountAlreadyExists if the reference already exists. If the ValueRef is nil, the internal controller backend is used. It returns a rollback function which can be used to revert the changes.

func (*State) CreateSecretBackend

func (s *State) CreateSecretBackend(ctx context.Context, params secretbackend.CreateSecretBackendParams) (string, error)

CreateSecretBackend creates a new secret backend.

func (*State) DeleteSecretBackend

func (s *State) DeleteSecretBackend(ctx context.Context, identifier secretbackend.BackendIdentifier, deleteInUse bool) error

DeleteSecretBackend deletes the secret backend for the given backend ID.

func (*State) GetInternalAndActiveBackendUUIDs

func (s *State) GetInternalAndActiveBackendUUIDs(ctx context.Context, modelUUID coremodel.UUID) (string, string, error)

GetInternalAndActiveBackendUUIDs returns the UUIDs for the internal and active secret backends.

func (*State) GetModelSecretBackendDetails

func (s *State) GetModelSecretBackendDetails(ctx context.Context, uuid coremodel.UUID) (secretbackend.ModelSecretBackend, error)

GetModelSecretBackendDetails is responsible for returning the backend details for a given model uuid, returning an error satisfying modelerrors.NotFound if the model provided does not exist.

func (*State) GetModelType

func (s *State) GetModelType(ctx context.Context, modelUUID coremodel.UUID) (coremodel.ModelType, error)

GetModelType returns the model type for the given model UUID.

func (*State) GetSecretBackend

GetSecretBackend returns the secret backend for the given backend ID or Name.

func (*State) GetSecretBackendReferenceCount

func (s *State) GetSecretBackendReferenceCount(ctx context.Context, backendID string) (int, error)

GetSecretBackendReferenceCount returns the number of references to the secret backend. It returns 0 if there are no references for the provided secret backend ID.

func (*State) GetSecretBackendRotateChanges

func (s *State) GetSecretBackendRotateChanges(ctx context.Context, backendIDs ...string) ([]watcher.SecretBackendRotateChange, error)

GetSecretBackendRotateChanges returns the secret backend rotation changes for the given backend IDs for the Watcher.

func (*State) InitialWatchStatementForSecretBackendRotationChanges

func (s *State) InitialWatchStatementForSecretBackendRotationChanges() (string, string)

InitialWatchStatementForSecretBackendRotationChanges returns the initial watch statement and the table name to watch for secret backend rotation changes.

func (*State) ListSecretBackendIDs

func (s *State) ListSecretBackendIDs(ctx context.Context) ([]string, error)

ListSecretBackendIDs returns a list of all secret backend ids.

func (*State) ListSecretBackends

func (s *State) ListSecretBackends(ctx context.Context) ([]*secretbackend.SecretBackend, error)

ListSecretBackends returns a list of all secret backends which contain secrets.

func (*State) ListSecretBackendsForModel

func (s *State) ListSecretBackendsForModel(ctx context.Context, modelUUID coremodel.UUID, includeEmpty bool) ([]*secretbackend.SecretBackend, error)

ListSecretBackendsForModel returns a list of all secret backends which contain secrets for the specified model, unless includeEmpty is true in which case all backends are returned.

func (*State) RemoveSecretBackendReference

func (s *State) RemoveSecretBackendReference(ctx context.Context, revisionIDs ...string) error

RemoveSecretBackendReference removes the reference to the secret backend for the given secret revisions.

func (*State) SecretBackendRotated

func (s *State) SecretBackendRotated(ctx context.Context, backendID string, next time.Time) error

SecretBackendRotated updates the next rotation time for the secret backend.

func (*State) SetModelSecretBackend

func (s *State) SetModelSecretBackend(ctx context.Context, modelUUID coremodel.UUID, secretBackendName string) error

SetModelSecretBackend sets the secret backend for the given model, returning an error satisfying secretbackenderrors.NotFound if the backend provided does not exist, returning an error satisfying modelerrors.NotFound if the model provided does not exist.

func (*State) UpdateSecretBackend

func (s *State) UpdateSecretBackend(ctx context.Context, params secretbackend.UpdateSecretBackendParams) (string, error)

UpdateSecretBackend updates the secret backend.

func (*State) UpdateSecretBackendReference

func (s *State) UpdateSecretBackendReference(
	ctx context.Context, valueRef *secrets.ValueRef, modelID coremodel.UUID, revisionID string,
) (func() error, error)

UpdateSecretBackendReference updates the reference to the secret backend for the given secret revision, returning an error satisfying secretbackenderrors.RefCountNotFound if no existing refcount was found. It returns a rollback function which can be used to revert the changes.

Jump to

Keyboard shortcuts

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