statestore

package
v0.0.17 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	KeyDelimiter       = "||"
	SuffixMetadata     = "metadata"
	SuffixCustomStatus = "customStatus"
	HistoryPrefix      = "history-"
)

Variables

View Source
var ErrUnsupported = errors.New("unsupported state store type")

ErrUnsupported is returned by New when the component type is not one of the four supported backends (state.redis, state.sqlite, state.postgresql/postgres, state.mongodb).

Functions

func AllInstanceMetaPattern

func AllInstanceMetaPattern(namespace string) string

AllInstanceMetaPattern is a KeysLike LIKE pattern matching every instance's metadata key across ALL app-ids in the namespace ("%" matches both the leading app-id segment and the app-id inside the actor type).

func ConnInfo

func ConnInfo(c Component) string

ConnInfo returns a short, human-readable connection summary for a component, suitable for display in the UI. It NEVER includes credentials (passwords or user info). Returns "" when no usable, non-secret metadata is present.

func InstanceKeyPattern

func InstanceKeyPattern(namespace, appID, instanceID string) string

InstanceKeyPattern matches every state key belonging to one instance.

func InstanceMetaPattern

func InstanceMetaPattern(namespace, appID string) string

InstanceMetaPattern is a KeysLike LIKE pattern matching every instance's metadata key for an app ("%" matches the instance-id segment).

func InstancePrefix

func InstancePrefix(namespace, appID, instanceID string) string

InstancePrefix is the "<appId>||<actorType>||<instanceID>||" prefix.

func ParseAppID

func ParseAppID(key string) (string, bool)

ParseAppID returns the app-id segment (segment[0]) of a "||"-joined workflow key. Returns ok=false for a malformed key (fewer than three segments or an empty app-id segment).

func ParseInstanceID

func ParseInstanceID(key string) (string, bool)

ParseInstanceID returns the instance-id segment of a "||"-joined workflow key.

func ResolveSecrets

func ResolveSecrets(c Component, stores []SecretStore) (resolved map[string]string, unresolved []string)

ResolveSecrets returns a copy of c.Metadata with each secretKeyRef entry resolved using the secret store named by c.SecretStore. Metadata keys that cannot be resolved are returned in unresolved and left out of the map.

func SeedForTest

func SeedForTest(ctx context.Context, s Store, key string, value []byte) error

SeedForTest is a helper for integration tests that upserts a raw byte value through the public Store interface.

func SetVerbose added in v0.0.8

func SetVerbose(v bool)

SetVerbose lets the backend state stores emit informational logs; wire it to the dashboard's --verbose flag.

func WorkflowActorType

func WorkflowActorType(namespace, appID string) string

WorkflowActorType builds the Dapr workflow actor type for an app.

Types

type Component

type Component struct {
	Name        string               // metadata.name
	Type        string               // spec.type, e.g. "state.redis"
	Version     string               // spec.version
	Metadata    map[string]string    // spec.metadata name->value (inline only)
	SecretRefs  map[string]SecretRef // spec.metadata name->secretKeyRef (no inline value)
	SecretStore string               // auth.secretStore
	Path        string               // source file path (for display / disambiguation)
}

Component is the parsed subset of a Dapr state-store component YAML we need.

func Detect

func Detect(paths []string) ([]Component, error)

Detect finds state-store components under the given files or directories.

func Translate

func Translate(c Component, hosts HostLookup, paths PathLookup) Component

Translate rewrites c's connection metadata for access from the host: state.redis redisHost, state.postgresql/postgres connection strings (URL or key=value DSN), and state.sqlite file paths. Only exact lookup hits are rewritten — foreign hostnames pass through so a connection failure stays honest. Copy-on-write: c is never mutated; the returned Component carries a fresh Metadata map only when something changed.

type HostLookup

type HostLookup func(host string, port int) (string, bool)

HostLookup resolves a compose-network hostname + port to a host-reachable "host:port". ok=false leaves the original address untouched.

type PathLookup

type PathLookup func(containerPath string) (string, bool)

PathLookup resolves a container-internal file path to a host path.

type SecretRef

type SecretRef struct {
	Name string // secretKeyRef.name (the secret's name)
	Key  string // secretKeyRef.key (the key within that secret)
}

SecretRef is a Dapr secretKeyRef: the secret name and the key within it.

type SecretStore

type SecretStore struct {
	Name            string
	Type            string // "secretstores.local.file" | "secretstores.local.env"
	SecretsFile     string // local.file only: resolved absolute path to the JSON file
	NestedSeparator string // local.file only: default ":"
}

SecretStore is a detected local Dapr secret-store component. Only the two local dev types are represented: secretstores.local.file and secretstores.local.env.

func DetectSecretStores

func DetectSecretStores(paths []string) ([]SecretStore, error)

DetectSecretStores finds local secret-store components (local.file / local.env) under the given files or directories. Other secret-store types are ignored.

type Store

type Store interface {
	// Keys lists keys matching a LIKE pattern, with opaque cursor paging.
	Keys(ctx context.Context, pattern string, token string, pageSize int) (keys []string, next string, err error)
	Get(ctx context.Context, key string) ([]byte, error)
	BulkGet(ctx context.Context, keys []string) (map[string][]byte, error)
	Delete(ctx context.Context, key string) error
	// Set upserts a raw byte value at key. Used by integration tests to seed state.
	Set(ctx context.Context, key string, value []byte) error
	Close() error
}

Store is the read + write + delete surface the workflow service needs.

func New

func New(ctx context.Context, c Component) (Store, error)

New builds and initialises a components-contrib state store from a component spec. Supports state.redis, state.sqlite, state.postgresql / state.postgres, and state.mongodb. Returns ErrUnsupported for any other type.

Jump to

Keyboard shortcuts

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