Documentation
¶
Overview ¶
Package session provides access to session registry.
Index ¶
- Constants
- type Registry
- func (r *Registry) AddCursor(ctx context.Context, userID UserID, sessionID uuid.UUID, cursorID int64)
- func (r *Registry) Collect(ch chan<- prometheus.Metric)
- func (r *Registry) CreateOrUpdateByLSID(ctx context.Context, spec wirebson.AnyDocument) (UserID, uuid.UUID, error)
- func (r *Registry) CreateOrUpdateSessions(ctx context.Context, sessionIDs []uuid.UUID)
- func (r *Registry) DeleteAllSessions() []int64
- func (r *Registry) DeleteCursor(userID UserID, cursorID int64, db string) error
- func (r *Registry) DeleteExpired() []int64
- func (r *Registry) DeleteSessionsByIDs(userID UserID, sessionIDs []uuid.UUID) []int64
- func (r *Registry) DeleteSessionsByUserIDs(userIDs []UserID) []int64
- func (r *Registry) Describe(ch chan<- *prometheus.Desc)
- func (r *Registry) EndSessions(ctx context.Context, sessionIDs []uuid.UUID)
- func (r *Registry) NewSession(ctx context.Context) uuid.UUID
- func (r *Registry) Stop()
- func (r *Registry) ValidateCursor(userID UserID, sessionID uuid.UUID, cursorID int64) error
- type UserID
Constants ¶
const LogicalSessionTimeoutMinutes = int32(30)
LogicalSessionTimeoutMinutes is the session timeout in minutes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores sessions.
func NewRegistry ¶
NewRegistry returns a new registry.
func (*Registry) AddCursor ¶
func (r *Registry) AddCursor(ctx context.Context, userID UserID, sessionID uuid.UUID, cursorID int64)
AddCursor adds the cursor with its user ID and session ID. If the session does not exist, a new session is created implicitly.
func (*Registry) Collect ¶
func (r *Registry) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector.
func (*Registry) CreateOrUpdateByLSID ¶
func (r *Registry) CreateOrUpdateByLSID(ctx context.Context, spec wirebson.AnyDocument) (UserID, uuid.UUID, error)
CreateOrUpdateByLSID fetches `lsid` field from spec and updates the last used time of that session. If the `lsid` is not a valid UUID, it returns an error. If a session does not exist, a new session is created implicitly. If `lsid` field is not present, a session is created with an empty session ID.
It returns the user ID and the session ID.
func (*Registry) CreateOrUpdateSessions ¶
CreateOrUpdateSessions updates the last used time of the sessions. If a session does not exist, a new session is created implicitly.
func (*Registry) DeleteAllSessions ¶
DeleteAllSessions removes all sessions of all users and returns all cursors of removed sessions.
func (*Registry) DeleteCursor ¶
DeleteCursor removes the cursor. If the cursor does not exist, it does nothing. It returns an error if the cursor was not created by the same user.
func (*Registry) DeleteExpired ¶
DeleteExpired removes ended sessions and expired session from the registry and returns cursors of the deleted sessions.
func (*Registry) DeleteSessionsByIDs ¶
DeleteSessionsByIDs removes sessions and returns cursors of the deleted sessions. If a session does not exist, it does nothing.
func (*Registry) DeleteSessionsByUserIDs ¶
DeleteSessionsByUserIDs removes sessions of the specified user IDs and returns cursors of deleted sessions. If a user ID does not exist, it does nothing.
func (*Registry) Describe ¶
func (r *Registry) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector.
func (*Registry) EndSessions ¶
EndSessions marks sessions as ended. If a session does not exist, it does nothing.
func (*Registry) NewSession ¶
NewSession creates a new session and adds it to the registry.
type UserID ¶
UserID is the output computed by SHA256 function.
func GetUIDFromUsername ¶
GetUIDFromUsername returns the hash of <username>@<database>. If the username is empty, it returns a hash of an empty string.