memstore

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package memstore is a reference in-memory implementation of every interface in the store package. It is safe for concurrent use. It exists so authit is usable and testable with zero external dependencies; host applications that need durability implement the same interfaces against their own database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountStore added in v0.4.0

type AccountStore struct {
	// contains filtered or unexported fields
}

AccountStore is an in-memory store.AccountStore.

func NewAccountStore added in v0.4.0

func NewAccountStore() *AccountStore

func (*AccountStore) CreateAccount added in v0.4.0

func (s *AccountStore) CreateAccount(_ context.Context, a *store.Account) error

func (*AccountStore) DeleteAccount added in v0.4.0

func (s *AccountStore) DeleteAccount(_ context.Context, id string) error

func (*AccountStore) GetAccount added in v0.4.0

func (s *AccountStore) GetAccount(_ context.Context, id string) (*store.Account, error)

func (*AccountStore) GetAccountByProvider added in v0.4.0

func (s *AccountStore) GetAccountByProvider(_ context.Context, provider, providerAccountID string) (*store.Account, error)

func (*AccountStore) ListAccountsByUser added in v0.4.0

func (s *AccountStore) ListAccountsByUser(_ context.Context, userID string) ([]*store.Account, error)

func (*AccountStore) UpdateAccount added in v0.4.0

func (s *AccountStore) UpdateAccount(_ context.Context, a *store.Account) error

type DeviceAuthorizationStore

type DeviceAuthorizationStore struct {
	// contains filtered or unexported fields
}

DeviceAuthorizationStore is an in-memory store.DeviceAuthorizationStore.

func NewDeviceAuthorizationStore

func NewDeviceAuthorizationStore() *DeviceAuthorizationStore

func (*DeviceAuthorizationStore) CreateDeviceAuthorization

func (s *DeviceAuthorizationStore) CreateDeviceAuthorization(_ context.Context, d *store.DeviceAuthorization) error

func (*DeviceAuthorizationStore) DeleteDeviceAuthorization

func (s *DeviceAuthorizationStore) DeleteDeviceAuthorization(_ context.Context, id string) error

func (*DeviceAuthorizationStore) GetDeviceAuthorizationByDeviceCodeHash

func (s *DeviceAuthorizationStore) GetDeviceAuthorizationByDeviceCodeHash(_ context.Context, hash string) (*store.DeviceAuthorization, error)

func (*DeviceAuthorizationStore) GetDeviceAuthorizationByUserCode

func (s *DeviceAuthorizationStore) GetDeviceAuthorizationByUserCode(_ context.Context, userCode string) (*store.DeviceAuthorization, error)

func (*DeviceAuthorizationStore) UpdateDeviceAuthorization

func (s *DeviceAuthorizationStore) UpdateDeviceAuthorization(_ context.Context, d *store.DeviceAuthorization) error

type EmailLoginStore added in v0.4.0

type EmailLoginStore struct {
	// contains filtered or unexported fields
}

EmailLoginStore is an in-memory store.EmailLoginStore.

func NewEmailLoginStore added in v0.4.0

func NewEmailLoginStore() *EmailLoginStore

func (*EmailLoginStore) CreateEmailLoginToken added in v0.4.0

func (s *EmailLoginStore) CreateEmailLoginToken(_ context.Context, t *store.EmailLoginToken) error

func (*EmailLoginStore) DeleteEmailLoginTokens added in v0.4.0

func (s *EmailLoginStore) DeleteEmailLoginTokens(_ context.Context, email string, kind store.EmailLoginKind) error

func (*EmailLoginStore) GetEmailLoginTokenByEmail added in v0.4.0

func (s *EmailLoginStore) GetEmailLoginTokenByEmail(_ context.Context, email string, kind store.EmailLoginKind) (*store.EmailLoginToken, error)

func (*EmailLoginStore) GetEmailLoginTokenByHash added in v0.4.0

func (s *EmailLoginStore) GetEmailLoginTokenByHash(_ context.Context, hash string) (*store.EmailLoginToken, error)

func (*EmailLoginStore) IncrementEmailLoginTokenAttempts added in v0.4.0

func (s *EmailLoginStore) IncrementEmailLoginTokenAttempts(_ context.Context, id string) (int, error)

func (*EmailLoginStore) MarkEmailLoginTokenUsed added in v0.4.0

func (s *EmailLoginStore) MarkEmailLoginTokenUsed(_ context.Context, id string, usedAt time.Time) error

MarkEmailLoginTokenUsed marks used under one lock, and refuses a token already marked. Both halves happen without releasing the lock, which is what makes it a compare-and-set rather than a read followed by a write.

type EmailVerificationStore

type EmailVerificationStore struct {
	// contains filtered or unexported fields
}

EmailVerificationStore is an in-memory store.EmailVerificationStore.

func NewEmailVerificationStore

func NewEmailVerificationStore() *EmailVerificationStore

func (*EmailVerificationStore) CreateEmailVerificationToken

func (s *EmailVerificationStore) CreateEmailVerificationToken(_ context.Context, t *store.EmailVerificationToken) error

func (*EmailVerificationStore) DeleteUserEmailVerificationTokens

func (s *EmailVerificationStore) DeleteUserEmailVerificationTokens(_ context.Context, userID string) error

func (*EmailVerificationStore) GetEmailVerificationTokenByHash

func (s *EmailVerificationStore) GetEmailVerificationTokenByHash(_ context.Context, hash string) (*store.EmailVerificationToken, error)

func (*EmailVerificationStore) MarkEmailVerificationTokenUsed

func (s *EmailVerificationStore) MarkEmailVerificationTokenUsed(_ context.Context, id string) error

type InvitationStore

type InvitationStore struct {
	// contains filtered or unexported fields
}

InvitationStore is an in-memory store.InvitationStore.

func NewInvitationStore

func NewInvitationStore() *InvitationStore

func (*InvitationStore) CreateInvitation

func (s *InvitationStore) CreateInvitation(_ context.Context, i *store.Invitation) error

func (*InvitationStore) GetInvitation

func (s *InvitationStore) GetInvitation(_ context.Context, id string) (*store.Invitation, error)

func (*InvitationStore) GetInvitationByTokenHash

func (s *InvitationStore) GetInvitationByTokenHash(_ context.Context, hash string) (*store.Invitation, error)

func (*InvitationStore) ListInvitationsByTeam

func (s *InvitationStore) ListInvitationsByTeam(_ context.Context, teamID string) ([]*store.Invitation, error)

func (*InvitationStore) UpdateInvitation

func (s *InvitationStore) UpdateInvitation(_ context.Context, i *store.Invitation) error

type LockoutStore

type LockoutStore struct {
	// contains filtered or unexported fields
}

LockoutStore is an in-memory store.LockoutStore, shared by the user and superuser planes (they key lockouts by their own IDs/emails, which never collide across planes in practice since a host application uses separate instances per plane).

func NewLockoutStore

func NewLockoutStore() *LockoutStore

func (*LockoutStore) ClearFailedLoginAttempts

func (s *LockoutStore) ClearFailedLoginAttempts(_ context.Context, email string) error

func (*LockoutStore) CountRecentFailedLoginAttempts

func (s *LockoutStore) CountRecentFailedLoginAttempts(_ context.Context, email string, since time.Time) (int, error)

func (*LockoutStore) IsAccountLocked

func (s *LockoutStore) IsAccountLocked(_ context.Context, userID string) (bool, error)

func (*LockoutStore) LockAccount

func (s *LockoutStore) LockAccount(_ context.Context, userID string) error

func (*LockoutStore) RecordFailedLoginAttempt

func (s *LockoutStore) RecordFailedLoginAttempt(_ context.Context, a *store.FailedLoginAttempt) error

func (*LockoutStore) UnlockAccount

func (s *LockoutStore) UnlockAccount(_ context.Context, userID string) error

type MemberStore

type MemberStore struct {
	// contains filtered or unexported fields
}

MemberStore is an in-memory store.MemberStore.

func NewMemberStore

func NewMemberStore() *MemberStore

func (*MemberStore) CreateMember

func (s *MemberStore) CreateMember(_ context.Context, m *store.Member) error

func (*MemberStore) DeleteMember

func (s *MemberStore) DeleteMember(_ context.Context, id string) error

func (*MemberStore) GetMember

func (s *MemberStore) GetMember(_ context.Context, id string) (*store.Member, error)

func (*MemberStore) GetMemberByUserAndTeam

func (s *MemberStore) GetMemberByUserAndTeam(_ context.Context, userID, teamID string) (*store.Member, error)

func (*MemberStore) ListMembersByTeam

func (s *MemberStore) ListMembersByTeam(_ context.Context, teamID string) ([]*store.Member, error)

func (*MemberStore) ListMembershipsByUser

func (s *MemberStore) ListMembershipsByUser(_ context.Context, userID string) ([]*store.Member, error)

func (*MemberStore) UpdateMember

func (s *MemberStore) UpdateMember(_ context.Context, m *store.Member) error

type PasswordResetStore

type PasswordResetStore struct {
	// contains filtered or unexported fields
}

PasswordResetStore is an in-memory store.PasswordResetStore.

func NewPasswordResetStore

func NewPasswordResetStore() *PasswordResetStore

func (*PasswordResetStore) CreatePasswordResetToken

func (s *PasswordResetStore) CreatePasswordResetToken(_ context.Context, t *store.PasswordResetToken) error

func (*PasswordResetStore) DeleteUserPasswordResetTokens

func (s *PasswordResetStore) DeleteUserPasswordResetTokens(_ context.Context, userID string) error

func (*PasswordResetStore) GetPasswordResetTokenByHash

func (s *PasswordResetStore) GetPasswordResetTokenByHash(_ context.Context, hash string) (*store.PasswordResetToken, error)

func (*PasswordResetStore) MarkPasswordResetTokenUsed

func (s *PasswordResetStore) MarkPasswordResetTokenUsed(_ context.Context, id string) error

type PendingTwoFactorStore

type PendingTwoFactorStore struct {
	// contains filtered or unexported fields
}

PendingTwoFactorStore is an in-memory store.PendingTwoFactorStore.

func NewPendingTwoFactorStore

func NewPendingTwoFactorStore() *PendingTwoFactorStore

func (*PendingTwoFactorStore) CreatePendingTwoFactorSession

func (s *PendingTwoFactorStore) CreatePendingTwoFactorSession(_ context.Context, sess *store.PendingTwoFactorSession) error

func (*PendingTwoFactorStore) DeletePendingTwoFactorSession

func (s *PendingTwoFactorStore) DeletePendingTwoFactorSession(_ context.Context, id string) error

func (*PendingTwoFactorStore) GetPendingTwoFactorSessionByHash

func (s *PendingTwoFactorStore) GetPendingTwoFactorSessionByHash(_ context.Context, hash string) (*store.PendingTwoFactorSession, error)

type PersonalAccessTokenStore

type PersonalAccessTokenStore struct {
	// contains filtered or unexported fields
}

PersonalAccessTokenStore is an in-memory store.PersonalAccessTokenStore.

func NewPersonalAccessTokenStore

func NewPersonalAccessTokenStore() *PersonalAccessTokenStore

func (*PersonalAccessTokenStore) CreatePersonalAccessToken

func (s *PersonalAccessTokenStore) CreatePersonalAccessToken(_ context.Context, t *store.PersonalAccessToken) error

func (*PersonalAccessTokenStore) GetPersonalAccessToken

func (s *PersonalAccessTokenStore) GetPersonalAccessToken(_ context.Context, id string) (*store.PersonalAccessToken, error)

func (*PersonalAccessTokenStore) GetPersonalAccessTokenByHash

func (s *PersonalAccessTokenStore) GetPersonalAccessTokenByHash(_ context.Context, hash string) (*store.PersonalAccessToken, error)

func (*PersonalAccessTokenStore) ListPersonalAccessTokensByUser

func (s *PersonalAccessTokenStore) ListPersonalAccessTokensByUser(_ context.Context, userID string) ([]*store.PersonalAccessToken, error)

func (*PersonalAccessTokenStore) UpdatePersonalAccessToken

func (s *PersonalAccessTokenStore) UpdatePersonalAccessToken(_ context.Context, t *store.PersonalAccessToken) error

type RefreshTokenStore

type RefreshTokenStore struct {
	// contains filtered or unexported fields
}

RefreshTokenStore is an in-memory store.RefreshTokenStore.

func NewRefreshTokenStore

func NewRefreshTokenStore() *RefreshTokenStore

func (*RefreshTokenStore) CreateRefreshToken

func (s *RefreshTokenStore) CreateRefreshToken(_ context.Context, t *store.RefreshToken) error

func (*RefreshTokenStore) GetRefreshTokenByHash

func (s *RefreshTokenStore) GetRefreshTokenByHash(_ context.Context, hash string) (*store.RefreshToken, error)

func (*RefreshTokenStore) ListActiveRefreshTokens

func (s *RefreshTokenStore) ListActiveRefreshTokens(_ context.Context, userID string) ([]*store.RefreshToken, error)

func (*RefreshTokenStore) RevokeAllUserRefreshTokens

func (s *RefreshTokenStore) RevokeAllUserRefreshTokens(_ context.Context, userID string) error

func (*RefreshTokenStore) RevokeRefreshToken

func (s *RefreshTokenStore) RevokeRefreshToken(_ context.Context, id string) error

func (*RefreshTokenStore) TouchRefreshToken added in v0.4.0

func (s *RefreshTokenStore) TouchRefreshToken(_ context.Context, id string, expiresAt time.Time) error

TouchRefreshToken extends a live token, and refuses a revoked one under the same lock that reads it -- otherwise a session revoked between a request's lookup and its extension would come back with a fresh lifetime.

type SuperuserRefreshTokenStore

type SuperuserRefreshTokenStore struct {
	// contains filtered or unexported fields
}

SuperuserRefreshTokenStore is an in-memory store.SuperuserRefreshTokenStore.

func NewSuperuserRefreshTokenStore

func NewSuperuserRefreshTokenStore() *SuperuserRefreshTokenStore

func (*SuperuserRefreshTokenStore) CreateSuperuserRefreshToken

func (s *SuperuserRefreshTokenStore) CreateSuperuserRefreshToken(_ context.Context, t *store.SuperuserRefreshToken) error

func (*SuperuserRefreshTokenStore) GetSuperuserRefreshTokenByHash

func (s *SuperuserRefreshTokenStore) GetSuperuserRefreshTokenByHash(_ context.Context, hash string) (*store.SuperuserRefreshToken, error)

func (*SuperuserRefreshTokenStore) ListActiveSuperuserRefreshTokens added in v0.4.0

func (s *SuperuserRefreshTokenStore) ListActiveSuperuserRefreshTokens(_ context.Context, superuserID string) ([]*store.SuperuserRefreshToken, error)

func (*SuperuserRefreshTokenStore) RevokeAllSuperuserRefreshTokens

func (s *SuperuserRefreshTokenStore) RevokeAllSuperuserRefreshTokens(_ context.Context, superuserID string) error

func (*SuperuserRefreshTokenStore) RevokeSuperuserRefreshToken

func (s *SuperuserRefreshTokenStore) RevokeSuperuserRefreshToken(_ context.Context, id string) error

type SuperuserStore

type SuperuserStore struct {
	// contains filtered or unexported fields
}

SuperuserStore is an in-memory store.SuperuserStore.

func NewSuperuserStore

func NewSuperuserStore() *SuperuserStore

func (*SuperuserStore) CountSuperusers

func (s *SuperuserStore) CountSuperusers(_ context.Context) (int, error)

func (*SuperuserStore) CreateSuperuser

func (s *SuperuserStore) CreateSuperuser(_ context.Context, su *store.Superuser) error

func (*SuperuserStore) GetSuperuserByEmail

func (s *SuperuserStore) GetSuperuserByEmail(_ context.Context, email string) (*store.Superuser, error)

func (*SuperuserStore) GetSuperuserByID

func (s *SuperuserStore) GetSuperuserByID(_ context.Context, id string) (*store.Superuser, error)

func (*SuperuserStore) ListSuperusers

func (s *SuperuserStore) ListSuperusers(_ context.Context) ([]*store.Superuser, error)

func (*SuperuserStore) UpdateSuperuser

func (s *SuperuserStore) UpdateSuperuser(_ context.Context, su *store.Superuser) error

type SuperuserTwoFactorStore added in v0.4.0

type SuperuserTwoFactorStore struct {
	// contains filtered or unexported fields
}

SuperuserTwoFactorStore is an in-memory store.SuperuserTwoFactorStore. The rows are the user plane's shapes, so it delegates to those stores; the separate instance is what keeps the two planes' rows apart.

func NewSuperuserTwoFactorStore added in v0.4.0

func NewSuperuserTwoFactorStore() *SuperuserTwoFactorStore

func (*SuperuserTwoFactorStore) CreateSuperuserPendingTwoFactorSession added in v0.4.0

func (s *SuperuserTwoFactorStore) CreateSuperuserPendingTwoFactorSession(ctx context.Context, p *store.PendingTwoFactorSession) error

func (*SuperuserTwoFactorStore) CreateSuperuserTOTPSettings added in v0.4.0

func (s *SuperuserTwoFactorStore) CreateSuperuserTOTPSettings(ctx context.Context, t *store.TOTPSettings) error

func (*SuperuserTwoFactorStore) DeleteSuperuserPendingTwoFactorSession added in v0.4.0

func (s *SuperuserTwoFactorStore) DeleteSuperuserPendingTwoFactorSession(ctx context.Context, id string) error

func (*SuperuserTwoFactorStore) DeleteSuperuserTOTPSettings added in v0.4.0

func (s *SuperuserTwoFactorStore) DeleteSuperuserTOTPSettings(ctx context.Context, superuserID string) error

func (*SuperuserTwoFactorStore) GetSuperuserPendingTwoFactorSessionByHash added in v0.4.0

func (s *SuperuserTwoFactorStore) GetSuperuserPendingTwoFactorSessionByHash(ctx context.Context, hash string) (*store.PendingTwoFactorSession, error)

func (*SuperuserTwoFactorStore) GetSuperuserTOTPSettings added in v0.4.0

func (s *SuperuserTwoFactorStore) GetSuperuserTOTPSettings(ctx context.Context, superuserID string) (*store.TOTPSettings, error)

func (*SuperuserTwoFactorStore) UpdateSuperuserTOTPSettings added in v0.4.0

func (s *SuperuserTwoFactorStore) UpdateSuperuserTOTPSettings(ctx context.Context, t *store.TOTPSettings) error

type TOTPStore

type TOTPStore struct {
	// contains filtered or unexported fields
}

TOTPStore is an in-memory store.TOTPStore.

func NewTOTPStore

func NewTOTPStore() *TOTPStore

func (*TOTPStore) CreateTOTPSettings

func (s *TOTPStore) CreateTOTPSettings(_ context.Context, t *store.TOTPSettings) error

func (*TOTPStore) DeleteTOTPSettings

func (s *TOTPStore) DeleteTOTPSettings(_ context.Context, userID string) error

func (*TOTPStore) GetTOTPSettingsByUserID

func (s *TOTPStore) GetTOTPSettingsByUserID(_ context.Context, userID string) (*store.TOTPSettings, error)

func (*TOTPStore) UpdateTOTPSettings

func (s *TOTPStore) UpdateTOTPSettings(_ context.Context, t *store.TOTPSettings) error

type TeamStore

type TeamStore struct {
	// contains filtered or unexported fields
}

TeamStore is an in-memory store.TeamStore.

func NewTeamStore

func NewTeamStore() *TeamStore

func (*TeamStore) CreateTeam

func (s *TeamStore) CreateTeam(_ context.Context, t *store.Team) error

func (*TeamStore) DeleteTeam

func (s *TeamStore) DeleteTeam(_ context.Context, id string) error

func (*TeamStore) GetTeam

func (s *TeamStore) GetTeam(_ context.Context, id string) (*store.Team, error)

func (*TeamStore) GetTeamBySlug

func (s *TeamStore) GetTeamBySlug(_ context.Context, slug string) (*store.Team, error)

func (*TeamStore) UpdateTeam

func (s *TeamStore) UpdateTeam(_ context.Context, t *store.Team) error

type UserStore

type UserStore struct {
	// contains filtered or unexported fields
}

UserStore is an in-memory store.UserStore.

func NewUserStore

func NewUserStore() *UserStore

NewUserStore constructs an empty UserStore.

func (*UserStore) CreateUser

func (s *UserStore) CreateUser(_ context.Context, u *store.User) error

func (*UserStore) GetUserByEmail

func (s *UserStore) GetUserByEmail(_ context.Context, email string) (*store.User, error)

func (*UserStore) GetUserByID

func (s *UserStore) GetUserByID(_ context.Context, id string) (*store.User, error)

func (*UserStore) UpdateUser

func (s *UserStore) UpdateUser(_ context.Context, u *store.User) error

type WebAuthnChallengeStore added in v0.4.0

type WebAuthnChallengeStore struct {
	// contains filtered or unexported fields
}

WebAuthnChallengeStore is an in-memory store.WebAuthnChallengeStore.

func NewWebAuthnChallengeStore added in v0.4.0

func NewWebAuthnChallengeStore() *WebAuthnChallengeStore

func (*WebAuthnChallengeStore) ConsumeWebAuthnChallenge added in v0.4.0

func (s *WebAuthnChallengeStore) ConsumeWebAuthnChallenge(_ context.Context, tokenHash string) (*store.WebAuthnChallenge, error)

ConsumeWebAuthnChallenge deletes and returns under one lock, which is what makes it atomic here. A Get method followed by a Delete method would not be: two callers could both read before either deleted, and both would then be finishing the same ceremony.

func (*WebAuthnChallengeStore) CreateWebAuthnChallenge added in v0.4.0

func (s *WebAuthnChallengeStore) CreateWebAuthnChallenge(_ context.Context, c *store.WebAuthnChallenge) error

type WebAuthnCredentialStore added in v0.4.0

type WebAuthnCredentialStore struct {
	// contains filtered or unexported fields
}

WebAuthnCredentialStore is an in-memory store.WebAuthnCredentialStore.

func NewWebAuthnCredentialStore added in v0.4.0

func NewWebAuthnCredentialStore() *WebAuthnCredentialStore

func (*WebAuthnCredentialStore) CreateWebAuthnCredential added in v0.4.0

func (s *WebAuthnCredentialStore) CreateWebAuthnCredential(_ context.Context, c *store.WebAuthnCredential) error

func (*WebAuthnCredentialStore) DeleteWebAuthnCredential added in v0.4.0

func (s *WebAuthnCredentialStore) DeleteWebAuthnCredential(_ context.Context, id string) error

func (*WebAuthnCredentialStore) GetWebAuthnCredential added in v0.4.0

func (s *WebAuthnCredentialStore) GetWebAuthnCredential(_ context.Context, id string) (*store.WebAuthnCredential, error)

func (*WebAuthnCredentialStore) GetWebAuthnCredentialByCredentialID added in v0.4.0

func (s *WebAuthnCredentialStore) GetWebAuthnCredentialByCredentialID(_ context.Context, credentialID []byte) (*store.WebAuthnCredential, error)

func (*WebAuthnCredentialStore) ListWebAuthnCredentialsByUser added in v0.4.0

func (s *WebAuthnCredentialStore) ListWebAuthnCredentialsByUser(_ context.Context, userID string) ([]*store.WebAuthnCredential, error)

func (*WebAuthnCredentialStore) UpdateWebAuthnCredential added in v0.4.0

func (s *WebAuthnCredentialStore) UpdateWebAuthnCredential(_ context.Context, c *store.WebAuthnCredential) error

Jump to

Keyboard shortcuts

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