state

package
v0.0.0-...-b9bb202 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type State

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

State represents database interactions dealing with storage pools.

func NewState

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

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

func (State) AllRemoteSecrets

func (st State) AllRemoteSecrets(ctx context.Context) ([]domainsecret.RemoteSecretInfo, error)

AllRemoteSecrets returns consumer info for secrets stored in an external model.

func (State) AllSecretConsumers

func (st State) AllSecretConsumers(ctx context.Context) (map[string][]domainsecret.ConsumerInfo, error)

AllSecretConsumers loads all local secret consumers keyed by secret id.

func (State) AllSecretGrants

func (st State) AllSecretGrants(ctx context.Context) (map[string][]domainsecret.GrantParams, error)

AllSecretGrants returns access details for all local secrets, keyed on secret id.

func (State) AllSecretRemoteConsumers

func (st State) AllSecretRemoteConsumers(ctx context.Context) (map[string][]domainsecret.ConsumerInfo, error)

AllSecretRemoteConsumers loads all secret remote consumers keyed by secret id.

func (State) ChangeSecretBackend

func (st State) ChangeSecretBackend(
	ctx context.Context, revisionID uuid.UUID,
	valueRef *coresecrets.ValueRef, data coresecrets.SecretData,
) (err error)

ChangeSecretBackend changes the secret backend for the specified secret.

func (State) CheckApplicationSecretLabelExists

func (st State) CheckApplicationSecretLabelExists(ctx domain.AtomicContext, appUUID coreapplication.ID, label string) (bool, error)

CheckApplicationSecretLabelExists checks if a charm application secret with the given label already exists.

func (State) CheckUnitSecretLabelExists

func (st State) CheckUnitSecretLabelExists(ctx domain.AtomicContext, unitUUID coreunit.UUID, label string) (bool, error)

CheckUnitSecretLabelExists checks if a charm unit secret with the given label already exists.

func (State) CheckUserSecretLabelExists

func (st State) CheckUserSecretLabelExists(ctx domain.AtomicContext, label string) (bool, error)

CheckUserSecretLabelExists checks if a user secret with the given label already exists.

func (State) CreateCharmApplicationSecret

func (st State) CreateCharmApplicationSecret(
	ctx domain.AtomicContext, version int, uri *coresecrets.URI, appUUID coreapplication.ID, secret domainsecret.UpsertSecretParams,
) error

CreateCharmApplicationSecret creates a secret onwed by the specified application, returning an error satisfying secreterrors.SecretAlreadyExists if a secretowned by the same application with the same label already exists. It also returns an error satisfying applicationerrors.ApplicationNotFound ifthe application does not exist.

func (State) CreateCharmUnitSecret

func (st State) CreateCharmUnitSecret(
	ctx domain.AtomicContext, version int, uri *coresecrets.URI, unitUUID coreunit.UUID, secret domainsecret.UpsertSecretParams,
) error

CreateCharmUnitSecret creates a secret onwed by the specified unit, returning an error satisfying secreterrors.SecretAlreadyExists if a secret owned by the same unit with the same label already exists. It also returns an error satisfying applicationerrors.UnitNotFound if the unit does not exist.

func (State) CreateUserSecret

func (st State) CreateUserSecret(
	ctx domain.AtomicContext, version int, uri *coresecrets.URI, secret domainsecret.UpsertSecretParams,
) error

CreateUserSecret creates a user secret, returning an error satisfying secreterrors.SecretAlreadyExists if a user secret with the same label already exists.

func (State) DeleteObsoleteUserSecretRevisions

func (st State) DeleteObsoleteUserSecretRevisions(ctx context.Context) ([]string, error)

DeleteObsoleteUserSecretRevisions deletes the obsolete user secret revisions. It returns the string format UUID of the deleted revisions.

func (State) DeleteSecret

func (st State) DeleteSecret(ctx domain.AtomicContext, uri *coresecrets.URI, revs []int) error

DeleteSecret deletes the specified secret revisions. If revisions is nil the last remaining revisions are removed.

func (State) GetApplicationUUID

func (st State) GetApplicationUUID(ctx domain.AtomicContext, appName string) (coreapplication.ID, error)

GetApplicationUUID returns the UUID of the application with the given name, returning an error satisfying applicationerrors.ApplicationNotFound if the application does not exist.

func (State) GetConsumedRemoteSecretURIsWithChanges

func (st State) GetConsumedRemoteSecretURIsWithChanges(
	ctx context.Context, unitName string, secretIDs ...string,
) ([]string, error)

GetConsumedRemoteSecretURIsWithChanges returns the URIs of the secrets consumed by the specified unit that have new revisions and are hosted on a different model.

func (State) GetConsumedSecretURIsWithChanges

func (st State) GetConsumedSecretURIsWithChanges(
	ctx context.Context, unitName string, revisionIDs ...string,
) ([]string, error)

GetConsumedSecretURIsWithChanges returns the URIs of the secrets consumed by the specified unit that has new revisions.

func (State) GetLatestRevision

func (st State) GetLatestRevision(ctx context.Context, uri *coresecrets.URI) (int, error)

GetLatestRevision returns the latest revision number for the specified secret, returning an error satisfying secreterrors.SecretNotFound if the secret does not exist.

func (State) GetModelUUID

func (st State) GetModelUUID(ctx context.Context) (string, error)

GetModelUUID returns the uuid of the model, or an error satisfying modelerrors.NotFound

func (State) GetObsoleteUserSecretRevisionsReadyToPrune

func (st State) GetObsoleteUserSecretRevisionsReadyToPrune(ctx context.Context) ([]string, error)

GetObsoleteUserSecretRevisionReadyToPrune returns the specified user secret revision with secret ID if it is ready to prune.

func (State) GetRemoteConsumedSecretURIsWithChangesFromOfferingSide

func (st State) GetRemoteConsumedSecretURIsWithChangesFromOfferingSide(
	ctx context.Context, appName string, revUUIDs ...string,
) ([]string, error)

GetRemoteConsumedSecretURIsWithChangesFromOfferingSide returns the URIs of the secrets consumed by the specified remote application that has new revisions.

func (State) GetRevisionIDsForObsolete

func (st State) GetRevisionIDsForObsolete(
	ctx context.Context,
	appOwners domainsecret.ApplicationOwners,
	unitOwners domainsecret.UnitOwners,
	revisionUUIDs ...string,
) ([]string, error)

GetRevisionIDsForObsolete filters the revision IDs that are obsolete and owned by the specified owners.Either revisionUUIDs, appOwners, or unitOwners must be specified.

func (State) GetRotatePolicy

func (st State) GetRotatePolicy(ctx context.Context, uri *coresecrets.URI) (coresecrets.RotatePolicy, error)

GetRotatePolicy returns the rotate policy for the specified secret.

func (State) GetRotationExpiryInfo

func (st State) GetRotationExpiryInfo(ctx context.Context, uri *coresecrets.URI) (*domainsecret.RotationExpiryInfo, error)

GetRotationExpiryInfo returns the rotation expiry information for the specified secret.

func (State) GetSecret

func (st State) GetSecret(ctx context.Context, uri *coresecrets.URI) (*coresecrets.SecretMetadata, error)

GetSecret returns the secret with the given URI, returning an error satisfying secreterrors.SecretNotFound if the secret does not exist.

func (State) GetSecretAccess

func (st State) GetSecretAccess(
	ctx context.Context, uri *coresecrets.URI, params domainsecret.AccessParams,
) (string, error)

GetSecretAccess returns the access to the secret for the specified accessor. It returns an error satisfying secreterrors.SecretNotFound if the secret is not found.

func (State) GetSecretAccessScope

func (st State) GetSecretAccessScope(
	ctx context.Context, uri *coresecrets.URI, params domainsecret.AccessParams,
) (*domainsecret.AccessScope, error)

GetSecretAccessScope returns the access scope for the specified accessor's permission on the secret.It returns an error satisfying secreterrors.SecretNotFound if the secret is not found.

func (State) GetSecretConsumer

func (st State) GetSecretConsumer(
	ctx context.Context, uri *coresecrets.URI, unitName string,
) (*coresecrets.SecretConsumerMetadata, int, error)

GetSecretConsumer returns the secret consumer info for the specified unit and secret, along withthe latest revision for the secret. If the unit does not exist, an error satisfying applicationerrors.UnitNotFound is returned.If the secret does not exist, an error satisfying secreterrors.SecretNotFound is returned. If there's not currently a consumer record for the secret, the latest revision is still returned,along with an error satisfying secreterrors.SecretConsumerNotFound.

func (State) GetSecretGrants

func (st State) GetSecretGrants(
	ctx context.Context, uri *coresecrets.URI, role coresecrets.SecretRole,
) ([]domainsecret.GrantParams, error)

GetSecretGrants returns the subjects which have the specified access to the secret. It returns an error satisfying secreterrors.SecretNotFound if the secret is not found.

func (State) GetSecretOwner

func (st State) GetSecretOwner(ctx domain.AtomicContext, uri *coresecrets.URI) (domainsecret.Owner, error)

GetSecretOwner returns the owner of the secret with the given URI, returning an error satisfying secreterrors.SecretNotFound if the secret does not exist.

func (State) GetSecretRemoteConsumer

func (st State) GetSecretRemoteConsumer(
	ctx context.Context, uri *coresecrets.URI, unitName string,
) (*coresecrets.SecretConsumerMetadata, int, error)

GetSecretRemoteConsumer returns the secret consumer info from a cross model consumer for the specified unit and secret. If the secret does not exist, an error satisfying secreterrors.SecretNotFound is returned. If there's not currently a consumer record for the secret, the latest revision is still returned, along with an error satisfying secreterrors.SecretConsumerNotFound.

func (State) GetSecretRevisionID

func (st State) GetSecretRevisionID(ctx context.Context, uri *coresecrets.URI, revision int) (string, error)

GetSecretRevisionID returns the revision UUID for the specified secret URI and revision, or an error satisfying secreterrors.SecretRevisionNotFound if the revision is not found.

func (State) GetSecretValue

func (st State) GetSecretValue(
	ctx context.Context, uri *coresecrets.URI, revision int) (coresecrets.SecretData, *coresecrets.ValueRef, error,
)

GetSecretValue returns the contents - either data or value reference - of a given secret revision, returning an error satisfying secreterrors.SecretRevisionNotFound if the secret revision does not exist.

func (State) GetSecretsForOwners

func (st State) GetSecretsForOwners(
	ctx domain.AtomicContext, appOwners domainsecret.ApplicationOwners, unitOwners domainsecret.UnitOwners,
) ([]*coresecrets.URI, error)

GetSecretsForOwners returns the secrets owned by the specified apps and/or units.

func (State) GetSecretsRevisionExpiryChanges

func (st State) GetSecretsRevisionExpiryChanges(
	ctx context.Context, appOwners domainsecret.ApplicationOwners, unitOwners domainsecret.UnitOwners, revisionUUIDs ...string,
) ([]domainsecret.ExpiryInfo, error)

GetSecretsRevisionExpiryChanges returns the expiry changes for the owners' secret revisions.

func (State) GetSecretsRotationChanges

func (st State) GetSecretsRotationChanges(
	ctx context.Context, appOwners domainsecret.ApplicationOwners, unitOwners domainsecret.UnitOwners, secretIDs ...string,
) ([]domainsecret.RotationInfo, error)

GetSecretsRotationChanges returns the rotation changes for the owners' secrets.

func (State) GetURIByConsumerLabel

func (st State) GetURIByConsumerLabel(ctx context.Context, label string, unitName string) (*coresecrets.URI, error)

GetURIByConsumerLabel looks up the secret URI using the label previously registered by the specified unit,returning an error satisfying secreterrors.SecretNotFound if there's no corresponding URI. If the unit does not exist, an error satisfying applicationerrors.UnitNotFound is returned.

func (State) GetUnitUUID

func (st State) GetUnitUUID(ctx domain.AtomicContext, unitName string) (coreunit.UUID, error)

GetUnitUUID returns the UUID of the unit with the given name, returning an error satisfying applicationerrors.UnitNotFound if the unit does not exist.

func (State) GetUserSecretURIByLabel

func (st State) GetUserSecretURIByLabel(ctx context.Context, label string) (*coresecrets.URI, error)

GetUserSecretURIByLabel returns the URI for the user secret with the specified label, or an error satisfying secreterrors.SecretNotFound if there's no corresponding URI.

func (State) GrantAccess

func (st State) GrantAccess(ctx context.Context, uri *coresecrets.URI, params domainsecret.GrantParams) error

GrantAccess grants access to the secret for the specified subject with the specified scope. It returns an error satisfying secreterrors.SecretNotFound if the secret is not found. If an attempt is made to change an existing permission's scope or subject type, an error satisfying secreterrors.InvalidSecretPermissionChange is returned.

func (State) InitialWatchStatementForConsumedRemoteSecretsChange

func (st State) InitialWatchStatementForConsumedRemoteSecretsChange(unitName string) (string, eventsource.NamespaceQuery)

InitialWatchStatementForConsumedRemoteSecretsChange returns the initial watch statement and the table name for watching consumed secrets hosted in a different model.

func (State) InitialWatchStatementForConsumedSecretsChange

func (st State) InitialWatchStatementForConsumedSecretsChange(unitName string) (string, eventsource.NamespaceQuery)

InitialWatchStatementForConsumedSecretsChange returns the initial watch statement and the table name for watching consumed secrets.

func (State) InitialWatchStatementForObsoleteRevision

func (st State) InitialWatchStatementForObsoleteRevision(
	appOwners domainsecret.ApplicationOwners, unitOwners domainsecret.UnitOwners,
) (string, eventsource.NamespaceQuery)

InitialWatchStatementForObsoleteRevision returns the initial watch statement and the table name for watching obsolete revisions.

func (State) InitialWatchStatementForRemoteConsumedSecretsChangesFromOfferingSide

func (st State) InitialWatchStatementForRemoteConsumedSecretsChangesFromOfferingSide(
	appName string,
) (string, eventsource.NamespaceQuery)

InitialWatchStatementForRemoteConsumedSecretsChangesFromOfferingSide returns the initial watch statement and the table name for watching remote consumed secrets.

func (State) InitialWatchStatementForSecretsRevisionExpiryChanges

func (st State) InitialWatchStatementForSecretsRevisionExpiryChanges(
	appOwners domainsecret.ApplicationOwners, unitOwners domainsecret.UnitOwners,
) (string, eventsource.NamespaceQuery)

InitialWatchStatementForSecretsRevisionExpiryChanges returns the initial watch statement and the table name for watching secret revision expiry changes.

func (State) InitialWatchStatementForSecretsRotationChanges

func (st State) InitialWatchStatementForSecretsRotationChanges(
	appOwners domainsecret.ApplicationOwners, unitOwners domainsecret.UnitOwners,
) (string, eventsource.NamespaceQuery)

InitialWatchStatementForSecretsRotationChanges returns the initial watch statement and the table name for watching rotations.

func (State) ListCharmSecrets

ListCharmSecrets returns charm secrets owned by the specified applications and/or units. At least one owner must be specified.

func (State) ListCharmSecretsToDrain

func (st State) ListCharmSecretsToDrain(
	ctx context.Context,
	appOwners domainsecret.ApplicationOwners, unitOwners domainsecret.UnitOwners,
) ([]*coresecrets.SecretMetadataForDrain, error)

ListCharmSecretsToDrain returns secret drain revision info for the secrets owned by the specified apps and units.

func (State) ListGrantedSecretsForBackend

func (st State) ListGrantedSecretsForBackend(
	ctx context.Context, backendID string, accessors []domainsecret.AccessParams, role coresecrets.SecretRole,
) ([]*coresecrets.SecretRevisionRef, error)

ListGrantedSecretsForBackend returns the secret revision info for any secrets from the specified backend for which the specified consumers have been granted the specified access.

func (State) ListSecrets

func (st State) ListSecrets(ctx context.Context, uri *coresecrets.URI,
	revision *int,

	labels domainsecret.Labels,
) ([]*coresecrets.SecretMetadata, [][]*coresecrets.SecretRevisionMetadata, error)

ListSecrets returns the secrets matching the specified criteria. If all terms are empty, then all secrets are returned.

func (State) ListUserSecretsToDrain

func (st State) ListUserSecretsToDrain(ctx context.Context) ([]*coresecrets.SecretMetadataForDrain, error)

ListUserSecretsToDrain returns secret drain revision info for any user secrets.

func (State) RevokeAccess

func (st State) RevokeAccess(ctx context.Context, uri *coresecrets.URI, params domainsecret.AccessParams) error

RevokeAccess revokes access to the secret for the specified subject. It returns an error satisfying secreterrors.SecretNotFound if the secret is not found.

func (State) SaveSecretConsumer

func (st State) SaveSecretConsumer(
	ctx context.Context, uri *coresecrets.URI, unitName string, md *coresecrets.SecretConsumerMetadata,
) error

SaveSecretConsumer saves the consumer metadata for the given secret and unit. If the unit does not exist, an error satisfying applicationerrors.UnitNotFound is returned. If the secret does not exist, an error satisfying secreterrors.SecretNotFound is returned.

func (State) SaveSecretRemoteConsumer

func (st State) SaveSecretRemoteConsumer(
	ctx context.Context, uri *coresecrets.URI, unitName string, md *coresecrets.SecretConsumerMetadata,
) error

SaveSecretRemoteConsumer saves the consumer metadata for the given secret and unit. If the secret does not exist, an error satisfying secreterrors.SecretNotFound is returned.

func (State) SecretRotated

func (st State) SecretRotated(ctx context.Context, uri *coresecrets.URI, next time.Time) error

SecretRotated updates the next rotation time for the specified secret.

func (State) UpdateRemoteSecretRevision

func (st State) UpdateRemoteSecretRevision(ctx context.Context, uri *coresecrets.URI, latestRevision int) error

UpdateRemoteSecretRevision records the latest revision of the specified cross model secret.

func (State) UpdateSecret

func (st State) UpdateSecret(
	ctx domain.AtomicContext, uri *coresecrets.URI, secret domainsecret.UpsertSecretParams,
) error

UpdateSecret creates a secret with the specified parameters, returning an error satisfying secreterrors.SecretNotFound if the secret does not exist. It also returns an error satisfying secreterrors.SecretLabelAlreadyExists if the secret owner already has a secret with the same label.

Jump to

Keyboard shortcuts

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