store

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnabledAppsOnly = FilterOpt(false)
	AllApps         = FilterOpt(true)
)
View Source
const (
	// KVAppPrefix is the Apps global namespace.
	KVAppPrefix = ".k"

	// KVUserPrefix is the global namespace used to store user
	// records.
	KVUserPrefix = ".u"

	// KVUserPrefix is the key to store OAuth2 user
	// records.
	KVUserKey = "oauth2_user"

	// KVOAuth2StatePrefix is the global namespace used to store OAuth2
	// ephemeral state data.
	KVOAuth2StatePrefix = ".o"

	// KVSubPrefix is used for keys storing subscriptions.
	KVSubPrefix = "sub."

	// KVInstalledAppPrefix is used to store App records.
	KVInstalledAppPrefix = "app."

	// KVLocalManifestPrefix is used to store locally-listed manifests.
	KVLocalManifestPrefix = "man."

	KVTokenPrefix = ".t"

	KVDebugPrefix = ".debug."

	// KVCallOnceKey and KVClusterMutexKey are used for invoking App Calls once,
	// usually upon a Mattermost instance startup.
	KVCallOnceKey     = "CallOnce"
	KVClusterMutexKey = "Cluster_Mutex"
)

KV namespace

Keys starting with a '.' are reserved for app-specific keys in the "hashkey" format. Hashkeys have the following format (see service_test.go#TestHashkey for examples):

  • global prefix of ".X" where X is exactly 1 byte (2 bytes)
  • bot user ID (26 bytes)
  • app-specific prefix, limited to 2 non-space ASCII characters, right-filled with ' ' to 2 bytes.
  • app-specific key hash: 16 bytes, ascii85 (20 bytes)

All other keys must start with an ASCII letter. '.' is usually used as the terminator since it is not used in the base64 representation.

View Source
const (
	ListKeysPerPage = 1000
)

Variables

This section is empty.

Functions

func Hashkey added in v1.0.0

func Hashkey(globalNamespace string, appID apps.AppID, userID, appNamespace, key string) (string, error)

func ParseHashkey added in v1.0.0

func ParseHashkey(key string) (globalNamespace string, appID apps.AppID, userID, appNamespace, idhash string, err error)

func WithAppID added in v1.2.0

func WithAppID(appID apps.AppID) func(string, apps.AppID, string, string, string) bool

func WithNamespace added in v1.2.0

func WithNamespace(namespace string) func(string, apps.AppID, string, string, string) bool

func WithPrefix added in v1.2.0

func WithPrefix(prefix string) func(string, apps.AppID, string, string, string) bool

func WithUserID added in v1.2.0

func WithUserID(userID string) func(string, apps.AppID, string, string, string) bool

Types

type AppKVStore added in v0.3.0

type AppKVStore interface {
	Set(_ *incoming.Request, prefix, id string, data []byte) (bool, error)
	Get(_ *incoming.Request, prefix, id string) ([]byte, error)
	Delete(_ *incoming.Request, prefix, id string) error
	List(_ *incoming.Request, namespace string, processf func(key string) error) error
}

type AppStore

type AppStore interface {
	config.Configurable

	InitBuiltin(...apps.App)

	Get(apps.AppID) (*apps.App, error)
	AsList(FilterOpt) []apps.App
	AsMap(FilterOpt) map[apps.AppID]apps.App
	Save(*incoming.Request, apps.App) error
	Delete(*incoming.Request, apps.AppID) error
}

type FilterOpt added in v1.2.0

type FilterOpt bool

type KVDebugAppInfo added in v1.2.0

type KVDebugAppInfo struct {
	AppKVCount            int
	AppKVCountByNamespace map[string]int
	AppKVCountByUserID    map[string]int
	TokenCount            int
	UserCount             int
}

func (KVDebugAppInfo) Total added in v1.2.0

func (i KVDebugAppInfo) Total() int

type KVDebugInfo added in v1.2.0

type KVDebugInfo struct {
	InstalledAppCount int
	Apps              map[apps.AppID]*KVDebugAppInfo
	AppsTotal         int
	ManifestCount     int
	OAuth2StateCount  int
	Other             int
	SubscriptionCount int
	Total             int
	Debug             int
}

type ManifestStore

type ManifestStore interface {
	config.Configurable

	StoreLocal(*incoming.Request, apps.Manifest) error
	Get(apps.AppID) (*apps.Manifest, error)
	GetFromS3(appID apps.AppID, version apps.AppVersion) (*apps.Manifest, error)
	AsMap() map[apps.AppID]apps.Manifest
	DeleteLocal(*incoming.Request, apps.AppID) error
}

type OAuth2Store added in v0.3.0

type OAuth2Store interface {
	CreateState(actingUserID string) (string, error)
	ValidateStateOnce(urlState, actingUserID string) error
	SaveUser(appID apps.AppID, actingUserID string, data []byte) error
	GetUser(appID apps.AppID, actingUserID string) ([]byte, error)
}

type Service

type Service struct {
	App          AppStore
	Subscription SubscriptionStore
	Manifest     ManifestStore
	AppKV        AppKVStore
	OAuth2       OAuth2Store
	Session      SessionStore
	// contains filtered or unexported fields
}

func MakeService added in v1.0.0

func MakeService(confService config.Service, httpOut httpout.Service) (*Service, error)

func (*Service) GetDebugKVInfo added in v1.2.0

func (s *Service) GetDebugKVInfo(log utils.Logger) (*KVDebugInfo, error)

func (*Service) ListHashKeys added in v1.2.0

func (s *Service) ListHashKeys(
	r *incoming.Request,
	processf func(key string) error,
	matchf ...func(prefix string, _ apps.AppID, userID, namespace, idhash string) bool,
) error

func (*Service) RemoveAllKVAndUserDataForApp added in v1.2.0

func (s *Service) RemoveAllKVAndUserDataForApp(r *incoming.Request, appID apps.AppID) error

type SessionStore added in v1.0.0

type SessionStore interface {
	Get(_ apps.AppID, userID string) (*model.Session, error)
	ListForApp(apps.AppID) ([]*model.Session, error)
	ListForUser(_ *incoming.Request, userID string) ([]*model.Session, error)
	Save(_ apps.AppID, userID string, session *model.Session) error
	Delete(_ apps.AppID, userID string) error
	DeleteAllForApp(*incoming.Request, apps.AppID) error
	DeleteAllForUser(_ *incoming.Request, userID string) error
}

type StoredSubscriptions added in v1.2.0

type StoredSubscriptions struct {
	Event         apps.Event
	Subscriptions []Subscription
}

type Subscription added in v1.2.0

type Subscription struct {
	Call        apps.Call
	AppID       apps.AppID `json:"app_id"`
	OwnerUserID string     `json:"user_id"`
}

type SubscriptionStore

type SubscriptionStore interface {
	Get(apps.Event) ([]Subscription, error)
	List() ([]StoredSubscriptions, error)
	Save(apps.Event, []Subscription) error
}

SubscriptionStore stores the complete (for all apps) list of subscriptions for each "scope", everything in apps.Subscription, but the Call - the subject, and the optional team/channel IDs.

Jump to

Keyboard shortcuts

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