store

package
v0.0.0-...-b289748 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package store provides methods for registering and accessing database adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	UidGen *st.UidGenerator
	// contains filtered or unexported fields
}

func NewStore

func NewStore(a StoreArgs) (*Store, error)

NewStore() configure the selected db adapter (AdapterName), and opens the db connection TODO: register the available auth methods from the auth pkg

func (*Store) AddAuthRecord

func (s *Store) AddAuthRecord(uid st.Uid, authLvl auth.Level, scheme, unique string, secret []byte, expires time.Time) error

AddAuthRecord creates a new authentication record for the given user.

func (Store) Adp

func (s Store) Adp() types.Adapter

func (*Store) AuthGetAuthNames

func (s *Store) AuthGetAuthNames() []string

AuthGetAuthNames returns all addressable auth handler names, logical

and hardcoded excluding those which are disabled like "basic:".

func (*Store) AuthGetLogicalAuthHandler

func (s *Store) AuthGetLogicalAuthHandler(name string) types.AuthHandler

AuthGetLogicalAuthHandler returns an auth handler by logical name. If there is no

handler by that logical name it tries to find one by the hardcoded name.

func (*Store) AuthGetUniqueRecord

func (s *Store) AuthGetUniqueRecord(scheme, unique string) (st.Uid, auth.Level, []byte, time.Time, error)

GetAuthUniqueRecord takes a unique identifier and a authentication scheme name, fetches user ID and authentication secret.

func (*Store) CredConfirm

func (s *Store) CredConfirm(id types.Uid, method string) error

ConfirmCred marks credential method as confirmed.

func (*Store) CredDel

func (s *Store) CredDel(id types.Uid, method, value string) error

DelCred deletes user's credentials. If method is "", all credentials are deleted.

func (*Store) CredFail

func (s *Store) CredFail(id types.Uid, method string) error

FailCred increments fail count for the given credential method.

func (*Store) CredGetActive

func (s *Store) CredGetActive(id types.Uid, method string) (*types.Credential, error)

GetActiveCred gets a the currently active credential for the given user and method.

func (*Store) CredGetAllCreds

func (s *Store) CredGetAllCreds(id types.Uid, method string, validatedOnly bool) ([]types.Credential, error)

GetAllCreds returns credentials of the given user, all or validated only.

func (*Store) CredUpsert

func (s *Store) CredUpsert(cred *types.Credential) (bool, error)

UpsertCred adds or updates a credential validation request. Return true if the record was inserted, false if updated.

func (*Store) DBClose

func (s *Store) DBClose() error

func (*Store) DBGetAdapterName

func (s *Store) DBGetAdapterName() string

func (*Store) DBGetAdapterVersion

func (s *Store) DBGetAdapterVersion() int

func (*Store) DBStats

func (s *Store) DBStats() func() interface{}

DBStats() returns a callback returning db connection stats object.

func (*Store) DelAuthRecords

func (s *Store) DelAuthRecords(uid st.Uid, scheme string) error

DelAuthRecords deletes user's auth records of the given scheme.

func (*Store) DevDelete

func (s *Store) DevDelete(uid types.Uid, deviceID string) error

Delete deletes device record for a given user.

func (*Store) DevGetAll

func (s *Store) DevGetAll(uid ...types.Uid) (map[types.Uid][]types.DeviceDef, int, error)

GetAll returns all known device IDs for a given list of user IDs. The second return parameter is the count of found device IDs.

func (*Store) DevUpdate

func (s *Store) DevUpdate(uid types.Uid, oldDeviceID string, dev *types.DeviceDef) error

Update updates a device record.

func (*Store) FilesDeleteUnused

func (s *Store) FilesDeleteUnused(olderThan time.Time, limit int) error

DeleteUnused removes unused attachments and avatars.

func (*Store) FilesFinishUpload

func (s *Store) FilesFinishUpload(fd *types.FileDef, success bool, size int64) (*types.FileDef, error)

FinishUpload marks started upload as successfully finished or failed.

func (*Store) FilesGet

func (s *Store) FilesGet(fid string) (*types.FileDef, error)

Get fetches a file record for a unique file id.

func (*Store) FilesLinkAttachments

func (s *Store) FilesLinkAttachments(topic string, msgId types.Uid, attachments []string) error

LinkAttachments connects earlier uploaded attachments to a

message or topic to prevent it from being garbage collected.

func (*Store) FilesStartUpload

func (s *Store) FilesStartUpload(fd *types.FileDef) error

StartUpload records that the given user initiated a file upload

func (*Store) GetAuthHandler

func (s *Store) GetAuthHandler(name string) types.AuthHandler

func (*Store) GetAuthRecord

func (s *Store) GetAuthRecord(user st.Uid, scheme string) (string, auth.Level, []byte, time.Time, error)

GetAuthRecord takes a user ID and a authentication scheme name,

fetches unique scheme-dependent identifier and authentication secret.

func (*Store) GetMediaHandler

func (s *Store) GetMediaHandler() types.Handler

GetMediaHandler returns default media handler.

func (*Store) GetValidator

func (s *Store) GetValidator(name string) validate.Validator

GetValidator returns registered validator by name.

func (*Store) InitAuthLogicalNames

func (s *Store) InitAuthLogicalNames(ln []string) error

InitAuthLogicalNames() initializes authentication mapping "logical handler name":"actual handler name".

Logical name must not be empty, actual name could be an empty string.

Registered authentication handlers (what are currently supported)

func (*Store) MsgDeleteList

func (s *Store) MsgDeleteList(topic string, delID int, forUser types.Uid, ranges []types.Range) error

DeleteList deletes multiple messages defined by a list of ranges.

func (*Store) MsgGetAll

func (s *Store) MsgGetAll(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Message, error)

GetAll returns multiple messages.

func (*Store) MsgGetDeleted

func (s *Store) MsgGetDeleted(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Range, int, error)

GetDeleted returns the ranges of deleted messages and the largest DelId reported in the list.

func (*Store) MsgSave

func (s *Store) MsgSave(msg *types.Message, attachmentURLs []string, readBySender bool) (error, bool)

func (*Store) SetDefaultMediaHandler

func (s *Store) SetDefaultMediaHandler(name string, cfg interface{}) error

UseMediaHandler sets specified media handler as default.

func (*Store) SubsCreate

func (s *Store) SubsCreate(subs ...*types.Subscription) error

Create creates multiple subscriptions

func (*Store) SubsDelete

func (s *Store) SubsDelete(topic string, user types.Uid) error

Delete deletes a subscription

func (*Store) SubsGetSubs

func (s *Store) SubsGetSubs(topic string, user types.Uid, keepDeleted bool) (*types.Subscription, error)

SubsGetSubs loads *all* subscriptions for the given user.

Does not load Public/Trusted or Private, does not load deleted subscriptions.

func (*Store) SubsUpdate

func (s *Store) SubsUpdate(topic string, user types.Uid, update map[string]interface{}) error

Update values of topic's subscriptions.

func (*Store) TopCreate

func (s *Store) TopCreate(topic *types.Topic, owner types.Uid, private interface{}) error

Create creates a topic and owner's subscription to it.

func (*Store) TopCreateP2P

func (s *Store) TopCreateP2P(initiator, invited *types.Subscription) error

CreateP2P creates a P2P topic by generating two user's subsciptions to each other.

func (*Store) TopDelete

func (s *Store) TopDelete(topic string, isChan, hard bool) error

Delete deletes topic, messages, attachments, and subscriptions.

func (*Store) TopGet

func (s *Store) TopGet(topic string) (*types.Topic, error)

Get a single topic with a list of relevant users de-normalized into it

func (*Store) TopGetSubs

func (s *Store) TopGetSubs(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

GetSubs loads a list of subscriptions to the given topic, user.Public+Trusted and deleted subscriptions are not loaded. Suspended subscriptions are loaded.

func (*Store) TopGetSubsAny

func (s *Store) TopGetSubsAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

GetSubsAny loads a list of subscriptions to the given topic including deleted subscription. user.Public/Trusted are not loaded

func (*Store) TopGetTopicSubs

func (s *Store) TopGetTopicSubs(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

TopGetTopicSubs loads a list of subscriptions to the given topic, user.Public+Trusted

and deleted subscriptions are not loaded. Suspended subscriptions are loaded.

func (*Store) TopGetTopicSubsAny

func (s *Store) TopGetTopicSubsAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

TopGetTopicSubsAny loads a list of subscriptions to the given topic including

deleted subscription. user.Public/Trusted are not loaded

func (*Store) TopGetUsers

func (s *Store) TopGetUsers(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

GetUsers loads subscriptions for topic plus loads user.Public+Trusted. Deleted subscriptions are not loaded.

func (*Store) TopGetUsersAny

func (s *Store) TopGetUsersAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

GetUsersAny loads subscriptions for topic plus loads user.Public+Trusted.

It's the same as GetUsers, except it loads deleted subscriptions too.

func (*Store) TopOwnerChange

func (s *Store) TopOwnerChange(topic string, newOwner types.Uid) error

OwnerChange replaces the old topic owner with the new owner.

func (*Store) TopUpdate

func (s *Store) TopUpdate(topic string, update map[string]interface{}) error

Update is a generic topic update.

func (*Store) UpdateAuthRecord

func (s *Store) UpdateAuthRecord(uid st.Uid, authLvl auth.Level, scheme, unique string, secret []byte, expires time.Time) error

UpdateAuthRecord updates authentication record with a new secret and expiration time.

func (*Store) UsersCreate

func (s *Store) UsersCreate(user *types.User, private interface{}) (*types.User, error)

Create inserts User object into a database, updates creation time and assigns UID

func (*Store) UsersDelete

func (s *Store) UsersDelete(id types.Uid, hard bool) error

Delete deletes user records.

func (*Store) UsersFindSubs

func (s *Store) UsersFindSubs(id types.Uid, required [][]string, optional []string, activeOnly bool) ([]types.Subscription, error)

FindSubs find a list of users and topics for the given tags. Results are formatted as subscriptions.

`required` specifies an AND of ORs for required terms:

at least one element of every sublist in `required` must be present in the object's tags list.

`optional` specifies a list of optional terms.

func (*Store) UsersGet

func (s *Store) UsersGet(uid types.Uid) (*types.User, error)

Get returns a user object for the given user id

func (*Store) UsersGetAll

func (s *Store) UsersGetAll(uid ...types.Uid) ([]types.User, error)

GetAll returns a slice of user objects for the given user ids

func (*Store) UsersGetAllCreds

func (s *Store) UsersGetAllCreds(id types.Uid, method string, validatedOnly bool) ([]types.Credential, error)

GetAllCreds returns credentials of the given user, all or validated only.

func (*Store) UsersGetByCred

func (s *Store) UsersGetByCred(method, value string) (types.Uid, error)

GetByCred returns user ID for the given validated credential.

func (*Store) UsersGetChannels

func (s *Store) UsersGetChannels(id types.Uid) ([]string, error)

GetChannels returns a slice of group topic names where the user is a channel reader.

func (*Store) UsersGetOwnTopics

func (s *Store) UsersGetOwnTopics(id types.Uid) ([]string, error)

GetOwnTopics returns a slice of group topic names where the user is the owner.

func (*Store) UsersGetSubs

func (s *Store) UsersGetSubs(id types.Uid) ([]types.Subscription, error)

GetSubs loads *all* subscriptions for the given user. Does not load Public/Trusted or Private, does not load deleted subscriptions.

func (*Store) UsersGetTopics

func (s *Store) UsersGetTopics(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)

GetTopics load a list of user's subscriptions with Public+Trusted fields copied to subscription

func (*Store) UsersGetTopicsAny

func (s *Store) UsersGetTopicsAny(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)

GetTopicsAny load a list of user's subscriptions with Public+Trusted

fields copied to subscription. Deleted topics are returned too.

func (*Store) UsersGetUnreadCount

func (s *Store) UsersGetUnreadCount(ids ...types.Uid) (map[types.Uid]int, error)

GetUnreadCount returs users' total count of unread messages in all topics with the R permissions.

func (*Store) UsersGetUnvalidated

func (s *Store) UsersGetUnvalidated(lastUpdatedBefore time.Time, limit int) ([]types.Uid, error)

GetUnvalidated returns a list of stale user ids which have unvalidated credentials,

their auth levels and a comma-separated list of these credential names.

func (*Store) UsersUpdate

func (s *Store) UsersUpdate(uid types.Uid, update map[string]interface{}) error

Update is a general-purpose update of user data.

func (*Store) UsersUpdateLastSeen

func (s *Store) UsersUpdateLastSeen(uid types.Uid, userAgent string, when time.Time) error

UpdateLastSeen updates LastSeen and UserAgent.

func (*Store) UsersUpdateState

func (s *Store) UsersUpdateState(uid types.Uid, state types.ObjState) error

UpdateState changes user's state and state of some topics associated with the user.

func (*Store) UsersUpdateTags

func (s *Store) UsersUpdateTags(uid types.Uid, add, remove, reset []string) ([]string, error)

UpdateTags either adds, removes, or resets tags to the given slices.

type StoreArgs

type StoreArgs struct {
	Cfg      *config.Config
	Logger   *logger.Logger
	WorkerID uint
}

Directories

Path Synopsis
Package mock_store is a generated GoMock package.
Package mock_store is a generated GoMock package.

Jump to

Keyboard shortcuts

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