mongo

package
v2.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrorInactiveUser means user is inactive
	ErrorInactiveUser = Error("User is inactive")
	// ErrorEmptyAppID means appID params is empty
	ErrorEmptyAppID = Error("Empty appID param")
	// ErrorInactiveApp means app is inactive
	ErrorInactiveApp = Error("App is inactive")
	// ErrorEmptyConnectionStringDatabase empty connection string or database name
	ErrorEmptyConnectionStringDatabase = Error("unable to create mongodb storage for empty connection string or empty database name")
)

Variables

This section is empty.

Functions

func NewAppStorage

func NewAppStorage(
	logger *slog.Logger,
	settings model.MongoDatabaseSettings,
) (model.AppStorage, error)

NewAppStorage creates new MongoDB AppStorage implementation.

func NewConnectionTester

func NewConnectionTester(settings model.MongoDatabaseSettings) model.ConnectionTester

NewConnectionTester creates a MongoFB connection tester

func NewInviteStorage

func NewInviteStorage(
	logger *slog.Logger,
	settings model.MongoDatabaseSettings,
) (model.InviteStorage, error)

NewInviteStorage creates a MongoDB invite storage.

func NewManagementKeysStorage added in v2.4.4

func NewManagementKeysStorage(
	logger *slog.Logger,
	settings model.MongoDatabaseSettings,
) (model.ManagementKeysStorage, error)

NewManagementKeysStorage creates a management keys invite storage.

func NewTokenBlacklist

func NewTokenBlacklist(
	logger *slog.Logger,
	settings model.MongoDatabaseSettings,
) (model.TokenBlacklist, error)

NewTokenBlacklist creates new MongoDB-backed token blacklist.

func NewTokenStorage

func NewTokenStorage(
	logger *slog.Logger,
	settings model.MongoDatabaseSettings,
) (model.TokenStorage, error)

NewTokenStorage creates a MongoDB token storage.

func NewUserStorage

func NewUserStorage(
	logger *slog.Logger,
	settings model.MongoDatabaseSettings) (model.UserStorage, error)

NewUserStorage creates and inits MongoDB user storage.

func NewVerificationCodeStorage

func NewVerificationCodeStorage(
	logger *slog.Logger,
	settings model.MongoDatabaseSettings,
) (model.VerificationCodeStorage, error)

NewVerificationCodeStorage creates and inits MongoDB verification code storage.

Types

type AppStorage

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

AppStorage is a fully functional app storage for MongoDB.

func (*AppStorage) ActiveAppByID

func (as *AppStorage) ActiveAppByID(appID string) (model.AppData, error)

ActiveAppByID returns app by id only if it's active.

func (*AppStorage) AppByID

func (as *AppStorage) AppByID(id string) (model.AppData, error)

AppByID returns app from MongoDB by ID.

func (*AppStorage) ClearAllData added in v2.3.2

func (as *AppStorage) ClearAllData()

func (*AppStorage) Close

func (as *AppStorage) Close()

Close is a no-op.

func (*AppStorage) CreateApp

func (as *AppStorage) CreateApp(app model.AppData) (model.AppData, error)

CreateApp creates new app in MongoDB.

func (*AppStorage) DeleteApp

func (as *AppStorage) DeleteApp(id string) error

DeleteApp deletes app by id.

func (*AppStorage) DisableApp

func (as *AppStorage) DisableApp(app model.AppData) error

DisableApp disables app in MongoDB storage.

func (*AppStorage) FetchApps

func (as *AppStorage) FetchApps(filterString string) ([]model.AppData, error)

FetchApps fetches apps which name satisfies provided filterString. Supports pagination.

func (*AppStorage) ImportJSON

func (as *AppStorage) ImportJSON(data []byte, cleanOldData bool) error

ImportJSON imports data from JSON.

func (*AppStorage) TestDatabaseConnection

func (as *AppStorage) TestDatabaseConnection() error

TestDatabaseConnection checks if we can access applications collection.

func (*AppStorage) UpdateApp

func (as *AppStorage) UpdateApp(appID string, newApp model.AppData) (model.AppData, error)

UpdateApp updates app in MongoDB storage.

type ConnectionTester

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

func (*ConnectionTester) Connect

func (ct *ConnectionTester) Connect() error

type DB

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

DB is database connection structure.

func NewDB

func NewDB(logger *slog.Logger, conn string, dbName string) (*DB, error)

NewDB creates new database connection.

func (*DB) Close

func (db *DB) Close()

Close closes database connection.

func (*DB) EnsureCollectionIndices

func (db *DB) EnsureCollectionIndices(collectionName string, newIndices []mongo.IndexModel) error

EnsureCollectionIndices creates indices on a collection.

type Error

type Error string

Error - domain level error type

func (Error) Error

func (e Error) Error() string

Error - implementation of std.Error protocol

type InviteStorage

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

InviteStorage is a MongoDB invite storage.

func (*InviteStorage) ArchiveAllByEmail

func (is *InviteStorage) ArchiveAllByEmail(email string) error

ArchiveAllByEmail invalidates all invites by email.

func (*InviteStorage) ArchiveByID

func (is *InviteStorage) ArchiveByID(id string) error

ArchiveByID invalidates specific invite by its ID.

func (*InviteStorage) Close

func (is *InviteStorage) Close()

Close is a no-op.

func (*InviteStorage) GetAll

func (is *InviteStorage) GetAll(withArchived bool, skip, limit int) ([]model.Invite, int, error)

GetAll returns all active invites by default. To get an invalid invites need to set withInvalid argument to true.

func (*InviteStorage) GetByEmail

func (is *InviteStorage) GetByEmail(email string) (model.Invite, error)

GetByEmail returns valid and not expired invite by email.

func (*InviteStorage) GetByID

func (is *InviteStorage) GetByID(id string) (model.Invite, error)

GetByID returns invite by its ID.

func (*InviteStorage) Save

func (is *InviteStorage) Save(email, inviteToken, role, appID, createdBy string, expiresAt time.Time) error

Save creates and saves new invite to a database.

type ManagementKeysStorage added in v2.4.4

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

ManagementKeysStorage is a MongoDB management keys storage.

func (*ManagementKeysStorage) AddKey added in v2.4.5

func (*ManagementKeysStorage) ChangeScopesForKey added in v2.4.4

func (ms *ManagementKeysStorage) ChangeScopesForKey(ctx context.Context, id string, scopes []string) (model.ManagementKey, error)

func (*ManagementKeysStorage) ClearAllData added in v2.4.5

func (ms *ManagementKeysStorage) ClearAllData()

func (*ManagementKeysStorage) CreateKey added in v2.4.4

func (ms *ManagementKeysStorage) CreateKey(ctx context.Context, name string, scopes []string) (model.ManagementKey, error)

func (*ManagementKeysStorage) DisableKey added in v2.4.4

func (*ManagementKeysStorage) GetKey added in v2.4.4

func (*ManagementKeysStorage) GeyAllKeys added in v2.4.4

func (ms *ManagementKeysStorage) GeyAllKeys(ctx context.Context) ([]model.ManagementKey, error)

func (*ManagementKeysStorage) ImportJSON added in v2.4.5

func (ms *ManagementKeysStorage) ImportJSON(data []byte, cleanOldData bool) error

ImportJSON imports data from JSON.

func (*ManagementKeysStorage) RenameKey added in v2.4.4

func (ms *ManagementKeysStorage) RenameKey(ctx context.Context, id, name string) (model.ManagementKey, error)

func (*ManagementKeysStorage) UseKey added in v2.4.4

type Token

type Token struct {
	ID    string `bson:"_id,omitempty"` // TODO: Make use of jti claim.
	Token string `bson:"token,omitempty"`
}

Token is struct to store tokens in database.

type TokenBlacklist

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

TokenBlacklist is a MongoDB-backed token blacklist.

func (*TokenBlacklist) Add

func (tb *TokenBlacklist) Add(token string) error

Add adds token to the blacklist.

func (*TokenBlacklist) Close

func (tb *TokenBlacklist) Close()

Close is a no-op.

func (*TokenBlacklist) IsBlacklisted

func (tb *TokenBlacklist) IsBlacklisted(token string) bool

IsBlacklisted returns true if the token is present in the blacklist.

type TokenStorage

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

TokenStorage is a MongoDB token storage.

func (*TokenStorage) Close

func (ts *TokenStorage) Close()

Close is a no-op.

func (*TokenStorage) DeleteToken

func (ts *TokenStorage) DeleteToken(token string) error

DeleteToken removes token from the storage.

func (*TokenStorage) HasToken

func (ts *TokenStorage) HasToken(token string) bool

HasToken returns true if the token is present in the storage.

func (*TokenStorage) SaveToken

func (ts *TokenStorage) SaveToken(token string) error

SaveToken saves token in the database.

type UserStorage

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

UserStorage implements user storage interface.

func (*UserStorage) AddNewUser

func (us *UserStorage) AddNewUser(user model.User, password string) (model.User, error)

AddNewUser adds new user to the database.

func (*UserStorage) AddUserWithFederatedID

func (us *UserStorage) AddUserWithFederatedID(user model.User, provider string, federatedID, role string) (model.User, error)

AddUserWithFederatedID adds new user with social ID.

func (*UserStorage) AddUserWithPassword

func (us *UserStorage) AddUserWithPassword(user model.User, password, role string, isAnonymous bool) (model.User, error)

AddUserWithPassword creates new user and saves it in the database.

func (*UserStorage) AllDeviceTokens

func (us *UserStorage) AllDeviceTokens(userID string) ([]string, error)

TODO: implement get all device tokens logic

func (*UserStorage) AttachDeviceToken

func (us *UserStorage) AttachDeviceToken(id, token string) error

AttachDeviceToken do nothing here TODO: implement device storage

func (*UserStorage) CheckPassword

func (us *UserStorage) CheckPassword(id, password string) error

CheckPassword check that password is valid for user id.

func (*UserStorage) ClearAllUserData added in v2.3.0

func (us *UserStorage) ClearAllUserData()

ClearAllUserData - clears the database, used for integration testing

func (*UserStorage) Close

func (us *UserStorage) Close()

Close is a no-op.

func (*UserStorage) DeleteUser

func (us *UserStorage) DeleteUser(id string) error

DeleteUser deletes user by id.

func (*UserStorage) DetachDeviceToken

func (us *UserStorage) DetachDeviceToken(token string) error

DetachDeviceToken do nothing here yet TODO: implement

func (*UserStorage) FetchUsers

func (us *UserStorage) FetchUsers(filterString string, skip, limit int) ([]model.User, int, error)

FetchUsers fetches users which name satisfies provided filterString. Supports pagination.

func (*UserStorage) ImportJSON

func (us *UserStorage) ImportJSON(data []byte, clearOldData bool) error

ImportJSON imports data from JSON.

func (*UserStorage) RequestScopes

func (us *UserStorage) RequestScopes(userID string, scopes []string) ([]string, error)

RequestScopes for now returns requested scope TODO: implement scope logic

func (*UserStorage) ResetPassword

func (us *UserStorage) ResetPassword(id, password string) error

ResetPassword sets new user's password.

func (*UserStorage) ResetUsername

func (us *UserStorage) ResetUsername(id, username string) error

ResetUsername sets new user's username.

func (*UserStorage) Scopes

func (us *UserStorage) Scopes() []string

Scopes returns supported scopes, could be static data of database.

func (*UserStorage) UpdateLoginMetadata

func (us *UserStorage) UpdateLoginMetadata(userID string)

UpdateLoginMetadata updates user's login metadata.

func (*UserStorage) UpdateUser

func (us *UserStorage) UpdateUser(userID string, newUser model.User) (model.User, error)

UpdateUser updates user in MongoDB storage.

func (*UserStorage) UserByEmail

func (us *UserStorage) UserByEmail(email string) (model.User, error)

UserByEmail returns user by their email.

func (*UserStorage) UserByFederatedID

func (us *UserStorage) UserByFederatedID(provider string, id string) (model.User, error)

UserByFederatedID returns user by federated ID.

func (*UserStorage) UserByID

func (us *UserStorage) UserByID(id string) (model.User, error)

UserByID returns user by its ID.

func (*UserStorage) UserByPhone

func (us *UserStorage) UserByPhone(phone string) (model.User, error)

UserByPhone fetches user by phone number.

func (*UserStorage) UserByUsername

func (us *UserStorage) UserByUsername(username string) (model.User, error)

UserByUsername returns user by name.

type VerificationCodeStorage

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

VerificationCodeStorage implements verification code storage interface.

func (*VerificationCodeStorage) Close

func (vcs *VerificationCodeStorage) Close()

Close is a no-op here.

func (*VerificationCodeStorage) CreateVerificationCode

func (vcs *VerificationCodeStorage) CreateVerificationCode(phone, code string) error

CreateVerificationCode inserts new verification code to the database.

func (*VerificationCodeStorage) IsVerificationCodeFound

func (vcs *VerificationCodeStorage) IsVerificationCodeFound(phone, code string) (bool, error)

IsVerificationCodeFound checks whether verification code can be found.

Jump to

Keyboard shortcuts

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