store

package
v0.17.6-rc1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: GPL-3.0 Imports: 10 Imported by: 63

Documentation

Overview

Package store provides methods for registering and accessing database adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeUid added in v0.14.2

func DecodeUid(uid types.Uid) int64

DecodeUid takes an XTEA encrypted Uid and decrypts it into an int64. This is needed for sql compatibility. Tte original int64 values are generated by snowflake which ensures that the top bit is unset.

func EncodeUid added in v0.14.2

func EncodeUid(id int64) types.Uid

EncodeUid applies XTEA encryption to an int64 value. It's the inverse of DecodeUid.

func InitAuthLogicalNames added in v0.15.7

func InitAuthLogicalNames(config json.RawMessage) error

InitAuthLogicalNames initializes authentication mapping "logical handler name":"actual handler name". Logical name must not be empty, actual name could be an empty string.

func RegisterAdapter added in v0.14.2

func RegisterAdapter(a adapter.Adapter)

RegisterAdapter makes a persistence adapter available. If Register is called twice or if the adapter is nil, it panics.

func RegisterAuthScheme

func RegisterAuthScheme(name string, handler auth.AuthHandler)

RegisterAuthScheme registers an authentication scheme handler. The 'name' must be the hardcoded name, NOT the logical name.

func RegisterMediaHandler added in v0.15.2

func RegisterMediaHandler(name string, mh media.Handler)

RegisterMediaHandler saves reference to a media handler (file upload-download handler).

func RegisterValidator added in v0.14.4

func RegisterValidator(name string, v validate.Validator)

RegisterValidator registers validation scheme.

Types

type DeviceMapper

type DeviceMapper struct{}

func (DeviceMapper) Delete

func (DeviceMapper) Delete(uid types.Uid, deviceID string) error

Delete deletes device record for a given user.

func (DeviceMapper) GetAll

func (DeviceMapper) GetAll(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 (DeviceMapper) Update

func (DeviceMapper) Update(uid types.Uid, oldDeviceID string, dev *types.DeviceDef) error

Update updates a device record.

type DeviceMapperInterface added in v0.17.0

type DeviceMapperInterface interface {
	Update(uid types.Uid, oldDeviceID string, dev *types.DeviceDef) error
	GetAll(uid ...types.Uid) (map[types.Uid][]types.DeviceDef, int, error)
	Delete(uid types.Uid, deviceID string) error
}

DeviceMapper is a struct to map methods used for handling device IDs, used to generate push notifications.

var Devices DeviceMapperInterface

Devices is an instance of DeviceMapper to map methods to.

type FileMapper added in v0.15.2

type FileMapper struct{}

func (FileMapper) DeleteUnused added in v0.15.2

func (FileMapper) DeleteUnused(olderThan time.Time, limit int) error

DeleteUnused removes unused attachments.

func (FileMapper) FinishUpload added in v0.15.2

func (FileMapper) FinishUpload(fid string, success bool, size int64) (*types.FileDef, error)

FinishUpload marks started upload as successfully finished.

func (FileMapper) Get added in v0.15.2

func (FileMapper) Get(fid string) (*types.FileDef, error)

Get fetches a file record for a unique file id.

func (FileMapper) StartUpload added in v0.15.2

func (FileMapper) StartUpload(fd *types.FileDef) error

StartUpload records that the given user initiated a file upload

type FileMapperInterface added in v0.17.0

type FileMapperInterface interface {
	StartUpload(fd *types.FileDef) error
	FinishUpload(fid string, success bool, size int64) (*types.FileDef, error)
	Get(fid string) (*types.FileDef, error)
	DeleteUnused(olderThan time.Time, limit int) error
}

FileMapper is a struct to map methods used for file handling.

Files is an instance of FileMapper to be used for handling file uploads.

type MessagesObjMapper

type MessagesObjMapper struct{}

func (MessagesObjMapper) DeleteList

func (MessagesObjMapper) DeleteList(topic string, delID int, forUser types.Uid, ranges []types.Range) error

DeleteList deletes multiple messages defined by a list of ranges.

func (MessagesObjMapper) GetAll

func (MessagesObjMapper) GetAll(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Message, error)

GetAll returns multiple messages.

func (MessagesObjMapper) GetDeleted added in v0.14.2

func (MessagesObjMapper) GetDeleted(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 (MessagesObjMapper) Save

func (MessagesObjMapper) Save(msg *types.Message, readBySender bool) error

Save message

type MessagesObjMapperInterface added in v0.17.0

type MessagesObjMapperInterface interface {
	Save(msg *types.Message, readBySender bool) error
	DeleteList(topic string, delID int, forUser types.Uid, ranges []types.Range) error
	GetAll(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Message, error)
	GetDeleted(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Range, int, error)
}

MessagesObjMapper is a struct to hold methods for persistence mapping for the Message object.

Messages is an instance of MessagesObjMapper to map methods to.

type PersistentStorageInterface added in v0.17.0

type PersistentStorageInterface interface {
	Open(workerId int, jsonconf json.RawMessage) error
	Close() error
	IsOpen() bool
	GetAdapterName() string
	GetAdapterVersion() int
	GetDbVersion() int
	InitDb(jsonconf json.RawMessage, reset bool) error
	UpgradeDb(jsonconf json.RawMessage) error
	GetUid() types.Uid
	GetUidString() string
	DbStats() func() interface{}
	GetAuthNames() []string
	GetAuthHandler(name string) auth.AuthHandler
	GetLogicalAuthHandler(name string) auth.AuthHandler
	GetValidator(name string) validate.Validator
	GetMediaHandler() media.Handler
	UseMediaHandler(name, config string) error
}

PersistentStorage defines methods used for interation with persistent storage.

Store is the main object for interacting with persistent storage.

type SubsObjMapper

type SubsObjMapper struct{}

func (SubsObjMapper) Create

func (SubsObjMapper) Create(subs ...*types.Subscription) error

Create creates multiple subscriptions

func (SubsObjMapper) Delete

func (SubsObjMapper) Delete(topic string, user types.Uid) error

Delete deletes a subscription

func (SubsObjMapper) Get

func (SubsObjMapper) Get(topic string, user types.Uid) (*types.Subscription, error)

Get given subscription

func (SubsObjMapper) Update

func (SubsObjMapper) Update(topic string, user types.Uid, update map[string]interface{}) error

Update values of topic's subscriptions.

type SubsObjMapperInterface added in v0.17.0

type SubsObjMapperInterface interface {
	Create(subs ...*types.Subscription) error
	Get(topic string, user types.Uid) (*types.Subscription, error)
	Update(topic string, user types.Uid, update map[string]interface{}) error
	Delete(topic string, user types.Uid) error
}

SubsObjMapper is A struct to hold methods for persistence mapping for the Subscription object.

Subs is an instance of SubsObjMapper to map methods to.

type TopicsObjMapper

type TopicsObjMapper struct{}

func (TopicsObjMapper) Create

func (TopicsObjMapper) Create(topic *types.Topic, owner types.Uid, private interface{}) error

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

func (TopicsObjMapper) CreateP2P

func (TopicsObjMapper) CreateP2P(initiator, invited *types.Subscription) error

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

func (TopicsObjMapper) Delete

func (TopicsObjMapper) Delete(topic string, hard bool) error

Delete deletes topic, messages, attachments, and subscriptions.

func (TopicsObjMapper) Get

func (TopicsObjMapper) Get(topic string) (*types.Topic, error)

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

func (TopicsObjMapper) GetSubs

func (TopicsObjMapper) GetSubs(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

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

func (TopicsObjMapper) GetSubsAny added in v0.15.11

func (TopicsObjMapper) GetSubsAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

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

func (TopicsObjMapper) GetUsers

func (TopicsObjMapper) GetUsers(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

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

func (TopicsObjMapper) GetUsersAny

func (TopicsObjMapper) GetUsersAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)

GetUsersAny loads subscriptions for topic plus loads user.Public. It's the same as GetUsers, except it loads deleted subscriptions too.

func (TopicsObjMapper) OwnerChange added in v0.15.11

func (TopicsObjMapper) OwnerChange(topic string, newOwner types.Uid) error

OwnerChange replaces the old topic owner with the new owner.

func (TopicsObjMapper) Update

func (TopicsObjMapper) Update(topic string, update map[string]interface{}) error

Update is a generic topic update.

type TopicsObjMapperInterface added in v0.17.0

type TopicsObjMapperInterface interface {
	Create(topic *types.Topic, owner types.Uid, private interface{}) error
	CreateP2P(initiator, invited *types.Subscription) error
	Get(topic string) (*types.Topic, error)
	GetUsers(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
	GetUsersAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
	GetSubs(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
	GetSubsAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
	Update(topic string, update map[string]interface{}) error
	OwnerChange(topic string, newOwner types.Uid) error
	Delete(topic string, hard bool) error
}

TopicsObjMapper is a struct to hold methods for persistence mapping for the topic object.

Topics is an instance of TopicsObjMapper to map methods to.

type UsersObjMapper

type UsersObjMapper struct{}

func (UsersObjMapper) AddAuthRecord

func (UsersObjMapper) AddAuthRecord(uid types.Uid, authLvl auth.Level, scheme, unique string, secret []byte,
	expires time.Time) error

AddAuthRecord creates a new authentication record for the given user.

func (UsersObjMapper) ConfirmCred added in v0.14.4

func (UsersObjMapper) ConfirmCred(id types.Uid, method string) error

ConfirmCred marks credential method as confirmed.

func (UsersObjMapper) Create

func (UsersObjMapper) Create(user *types.User, private interface{}) (*types.User, error)

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

func (UsersObjMapper) DelAuthRecords added in v0.14.4

func (UsersObjMapper) DelAuthRecords(uid types.Uid, scheme string) error

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

func (UsersObjMapper) DelCred added in v0.15.11

func (UsersObjMapper) DelCred(id types.Uid, method, value string) error

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

func (UsersObjMapper) Delete

func (UsersObjMapper) Delete(id types.Uid, hard bool) error

Delete deletes user records.

func (UsersObjMapper) FailCred added in v0.14.4

func (UsersObjMapper) FailCred(id types.Uid, method string) error

FailCred increments fail count for the given credential method.

func (UsersObjMapper) FindSubs

func (UsersObjMapper) FindSubs(id types.Uid, required [][]string, optional []string) ([]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 (UsersObjMapper) Get

func (UsersObjMapper) Get(uid types.Uid) (*types.User, error)

Get returns a user object for the given user id

func (UsersObjMapper) GetActiveCred added in v0.16.0

func (UsersObjMapper) GetActiveCred(id types.Uid, method string) (*types.Credential, error)

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

func (UsersObjMapper) GetAll

func (UsersObjMapper) GetAll(uid ...types.Uid) ([]types.User, error)

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

func (UsersObjMapper) GetAllCreds added in v0.16.0

func (UsersObjMapper) GetAllCreds(id types.Uid, method string, validatedOnly bool) ([]types.Credential, error)

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

func (UsersObjMapper) GetAuthRecord

func (UsersObjMapper) GetAuthRecord(user types.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 (UsersObjMapper) GetAuthUniqueRecord added in v0.14.6

func (UsersObjMapper) GetAuthUniqueRecord(scheme, unique string) (types.Uid, auth.Level, []byte, time.Time, error)

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

func (UsersObjMapper) GetByCred added in v0.15.7

func (UsersObjMapper) GetByCred(method, value string) (types.Uid, error)

GetByCred returns user ID for the given validated credential.

func (UsersObjMapper) GetChannels added in v0.17.0

func (UsersObjMapper) GetChannels(id types.Uid) ([]string, error)

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

func (UsersObjMapper) GetOwnTopics added in v0.15.11

func (UsersObjMapper) GetOwnTopics(id types.Uid) ([]string, error)

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

func (UsersObjMapper) GetSubs

func (UsersObjMapper) GetSubs(id types.Uid) ([]types.Subscription, error)

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

func (UsersObjMapper) GetTopics

func (UsersObjMapper) GetTopics(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)

GetTopics load a list of user's subscriptions with Public field copied to subscription

func (UsersObjMapper) GetTopicsAny

func (UsersObjMapper) GetTopicsAny(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)

GetTopicsAny load a list of user's subscriptions with Public field copied to subscription. Deleted topics are returned too.

func (UsersObjMapper) GetUnreadCount added in v0.16.0

func (UsersObjMapper) GetUnreadCount(id types.Uid) (int, error)

GetUnreadCount returs user's total count of unread messages in all topics with the R permissions

func (UsersObjMapper) Update

func (UsersObjMapper) Update(uid types.Uid, update map[string]interface{}) error

Update is a general-purpose update of user data.

func (UsersObjMapper) UpdateAuthRecord

func (UsersObjMapper) UpdateAuthRecord(uid types.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 (UsersObjMapper) UpdateLastSeen

func (UsersObjMapper) UpdateLastSeen(uid types.Uid, userAgent string, when time.Time) error

UpdateLastSeen updates LastSeen and UserAgent.

func (UsersObjMapper) UpdateState added in v0.16.4

func (UsersObjMapper) UpdateState(uid types.Uid, state types.ObjState) error

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

func (UsersObjMapper) UpdateTags added in v0.14.2

func (UsersObjMapper) UpdateTags(uid types.Uid, add, remove, reset []string) ([]string, error)

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

func (UsersObjMapper) UpsertCred added in v0.16.0

func (UsersObjMapper) UpsertCred(cred *types.Credential) (bool, error)

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

type UsersObjMapperInterface added in v0.17.0

type UsersObjMapperInterface interface {
	Create(user *types.User, private interface{}) (*types.User, error)
	GetAuthRecord(user types.Uid, scheme string) (string, auth.Level, []byte, time.Time, error)
	GetAuthUniqueRecord(scheme, unique string) (types.Uid, auth.Level, []byte, time.Time, error)
	AddAuthRecord(uid types.Uid, authLvl auth.Level, scheme, unique string, secret []byte, expires time.Time) error
	UpdateAuthRecord(uid types.Uid, authLvl auth.Level, scheme, unique string, secret []byte, expires time.Time) error
	DelAuthRecords(uid types.Uid, scheme string) error
	Get(uid types.Uid) (*types.User, error)
	GetAll(uid ...types.Uid) ([]types.User, error)
	GetByCred(method, value string) (types.Uid, error)
	Delete(id types.Uid, hard bool) error
	UpdateLastSeen(uid types.Uid, userAgent string, when time.Time) error
	Update(uid types.Uid, update map[string]interface{}) error
	UpdateTags(uid types.Uid, add, remove, reset []string) ([]string, error)
	UpdateState(uid types.Uid, state types.ObjState) error
	GetSubs(id types.Uid) ([]types.Subscription, error)
	FindSubs(id types.Uid, required [][]string, optional []string) ([]types.Subscription, error)
	GetTopics(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
	GetTopicsAny(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
	GetOwnTopics(id types.Uid) ([]string, error)
	GetChannels(id types.Uid) ([]string, error)
	UpsertCred(cred *types.Credential) (bool, error)
	ConfirmCred(id types.Uid, method string) error
	FailCred(id types.Uid, method string) error
	GetActiveCred(id types.Uid, method string) (*types.Credential, error)
	GetAllCreds(id types.Uid, method string, validatedOnly bool) ([]types.Credential, error)
	DelCred(id types.Uid, method, value string) error
	GetUnreadCount(id types.Uid) (int, error)
}

UsersObjMapper is a users struct to hold methods for persistence mapping for the User object.

Users is the ancor for storing/retrieving User objects

Directories

Path Synopsis
Package mock_store is a generated GoMock package.
Package mock_store is a generated GoMock package.
Package types provides data types for persisting objects in the databases.
Package types provides data types for persisting objects in the databases.

Jump to

Keyboard shortcuts

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