mongo

package
v0.0.0-...-68463a2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbUsersColl        = "users"
	DbTokensColl       = "tokens"
	DbSettingsColl     = "settings"
	DbUserSettingsColl = "user_settings"

	DbUserEmail       = "email"
	DbUserPass        = "password"
	DbUserLoginTs     = "login_ts"
	DbTokenSubject    = "sub"
	DbTokenExpiresAt  = "exp"
	DbTokenExpireTime = "exp.time"
	DbTokenIssuedAt   = "iat"
	DbTokenTenant     = "tenant"
	DbTokenUser       = "user"
	DbTokenIssuer     = "iss"
	DbTokenScope      = "scp"
	DbTokenAudience   = "aud"
	DbTokenNotBefore  = "nbf"
	DbTokenLastUsed   = "last_used"
	DbTokenName       = "name"
	DbID              = "_id"

	DbTokenIssuedAtTime = DbTokenIssuedAt + ".time"

	DbUniqueEmailIndexName     = "email_1"
	DbUniqueTokenNameIndexName = "token_name_1"
	DbTokenSubjectIndexName    = "token_subject_1"

	DbTenantUniqueTokenNameIndexName = "tenant_1_subject_1_name_1"
	DbTenantTokenSubjectIndexName    = "tenant_1_subject_1"

	DbSettingsEtag            = "etag"
	DbSettingsTenantIndexName = "tenant"
	DbSettingsUserID          = "user_id"
)
View Source
const (
	DbVersion = "2.0.3"
	DbName    = "useradm"
)
View Source
const ErrCodeIndexOptionsError = 85
View Source
const IndexNameTokenExpire = "exp_time"
View Source
const (
	OldDbUniqueEmailIndexName = "uniqueEmail"
)

Variables

View Source
var (
	ErrExpirationTooLong = errors.New("token expiration time to high")
	ErrExpirationVoid    = errors.New("token expiration time cannot be 0")
	ErrExpNotPresent     = errors.New("token expiration not present in context")
)

Functions

This section is empty.

Types

type DataStoreMongo

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

func GetDataStoreMongo

func GetDataStoreMongo(config DataStoreMongoConfig) (*DataStoreMongo, error)

func NewDataStoreMongo

func NewDataStoreMongo(config DataStoreMongoConfig) (*DataStoreMongo, error)

func NewDataStoreMongoWithClient

func NewDataStoreMongoWithClient(client *mongo.Client) (*DataStoreMongo, error)

func (*DataStoreMongo) CountPersonalAccessTokens

func (db *DataStoreMongo) CountPersonalAccessTokens(
	ctx context.Context,
	userID string,
) (int64, error)

func (*DataStoreMongo) CreateUser

func (db *DataStoreMongo) CreateUser(ctx context.Context, u *model.User) error

func (*DataStoreMongo) DeleteToken

func (db *DataStoreMongo) DeleteToken(ctx context.Context, userID, tokenID oid.ObjectID) error

func (*DataStoreMongo) DeleteTokens

func (db *DataStoreMongo) DeleteTokens(ctx context.Context) error

deletes all tenant's tokens (identity in context)

func (*DataStoreMongo) DeleteTokensByUserId

func (db *DataStoreMongo) DeleteTokensByUserId(ctx context.Context, userId string) error

deletes all user's tokens

func (*DataStoreMongo) DeleteTokensByUserIdExceptCurrentOne

func (db *DataStoreMongo) DeleteTokensByUserIdExceptCurrentOne(
	ctx context.Context,
	userId string,
	tokenID oid.ObjectID,
) error

deletes all user's tokens except the current one

func (*DataStoreMongo) DeleteUser

func (db *DataStoreMongo) DeleteUser(ctx context.Context, id string) error

func (*DataStoreMongo) EnsureSessionTokensLimit

func (db *DataStoreMongo) EnsureSessionTokensLimit(ctx context.Context, userID oid.ObjectID,
	tokensLimit int) error

func (*DataStoreMongo) GetPersonalAccessTokens

func (db *DataStoreMongo) GetPersonalAccessTokens(
	ctx context.Context,
	userID string,
) ([]model.PersonalAccessToken, error)

func (*DataStoreMongo) GetSettings

func (db *DataStoreMongo) GetSettings(ctx context.Context) (*model.Settings, error)

func (*DataStoreMongo) GetTokenById

func (db *DataStoreMongo) GetTokenById(ctx context.Context, id oid.ObjectID) (*jwt.Token, error)

func (*DataStoreMongo) GetUserAndPasswordById

func (db *DataStoreMongo) GetUserAndPasswordById(
	ctx context.Context,
	id string,
) (*model.User, error)

func (*DataStoreMongo) GetUserByEmail

func (db *DataStoreMongo) GetUserByEmail(
	ctx context.Context,
	email model.Email,
) (*model.User, error)

func (*DataStoreMongo) GetUserById

func (db *DataStoreMongo) GetUserById(ctx context.Context, id string) (*model.User, error)

func (*DataStoreMongo) GetUserSettings

func (db *DataStoreMongo) GetUserSettings(ctx context.Context,
	userID string) (*model.Settings, error)

func (*DataStoreMongo) GetUsers

func (db *DataStoreMongo) GetUsers(
	ctx context.Context,
	fltr model.UserFilter,
) ([]model.User, error)

func (*DataStoreMongo) Migrate

func (db *DataStoreMongo) Migrate(ctx context.Context, version string) error

func (*DataStoreMongo) MigrateTenant

func (db *DataStoreMongo) MigrateTenant(ctx context.Context, version string, tenant string) error

MigrateTenant migrates a single tenant database.

func (*DataStoreMongo) Ping

func (db *DataStoreMongo) Ping(ctx context.Context) error

func (*DataStoreMongo) SaveSettings

func (db *DataStoreMongo) SaveSettings(ctx context.Context, s *model.Settings, etag string) error

func (*DataStoreMongo) SaveToken

func (db *DataStoreMongo) SaveToken(ctx context.Context, token *jwt.Token) error

func (*DataStoreMongo) SaveUserSettings

func (db *DataStoreMongo) SaveUserSettings(ctx context.Context, userID string,
	s *model.Settings, etag string) error

func (*DataStoreMongo) UpdateLoginTs

func (db *DataStoreMongo) UpdateLoginTs(ctx context.Context, id string) error

func (*DataStoreMongo) UpdateTokenLastUsed

func (db *DataStoreMongo) UpdateTokenLastUsed(ctx context.Context, id oid.ObjectID) error

func (*DataStoreMongo) UpdateUser

func (db *DataStoreMongo) UpdateUser(
	ctx context.Context,
	id string,
	u *model.UserUpdate,
) (*model.User, error)

UpdateUser updates the user of a given ID. NOTE: This function supports using ETag matching using UserUpdate, but defaults to wildcard matching

func (*DataStoreMongo) WithAutomigrate

func (db *DataStoreMongo) WithAutomigrate() *DataStoreMongo

WithAutomigrate enables automatic migration and returns a new datastore based on current one

func (*DataStoreMongo) WithMultitenant

func (db *DataStoreMongo) WithMultitenant() *DataStoreMongo

WithMultitenant enables multitenant support and returns a new datastore based on current one

type DataStoreMongoConfig

type DataStoreMongoConfig struct {
	// MGO connection string
	ConnectionString string

	// SSL support
	SSL           bool
	SSLSkipVerify bool

	// Overwrites credentials provided in connection string if provided
	Username string
	Password string
}

Jump to

Keyboard shortcuts

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