mongo

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2019 License: MIT Imports: 8 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")
)
View Source
const (
	// BlacklistedTokensCollection is a collection where blacklisted tokens are stored.
	BlacklistedTokensCollection = "BlacklistedTokens"
)
View Source
const (
	// TokensCollection is a collection to store refresh tokens.
	TokensCollection = "RefreshTokens"
)
View Source
const (
	// UsersCollection is a collection name for users.
	UsersCollection = "Users"
)
View Source
const (
	// VerificationCodesCollection is a collection name for verification codes.
	VerificationCodesCollection = "VerificationCodes"
)

Variables

View Source
var (
	// AppsCollection is a collection name for storing apps data.
	AppsCollection = "Applications"
)

Functions

func NewAppStorage

func NewAppStorage(db *DB) (model.AppStorage, error)

NewAppStorage creates new MongoDB AppStorage implementation.

func NewTokenBlacklist

func NewTokenBlacklist(db *DB) (model.TokenBlacklist, error)

NewTokenBlacklist creates a MongoDB token storage.

func NewTokenStorage

func NewTokenStorage(db *DB) (model.TokenStorage, error)

NewTokenStorage creates a MongoDB token storage.

func NewUserStorage

func NewUserStorage(db *DB) (model.UserStorage, error)

NewUserStorage creates and inits MongoDB user storage.

func NewVerificationCodeStorage

func NewVerificationCodeStorage(db *DB) (model.VerificationCodeStorage, error)

NewVerificationCodeStorage creates and inits MongoDB verification code storage.

func PasswordHash

func PasswordHash(pwd string) string

PasswordHash creates hash with salt for password.

Types

type AppData

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

AppData is a MongoDb model that implements model.AppData.

func AppDataFromJSON

func AppDataFromJSON(d []byte) (AppData, error)

AppDataFromJSON deserializes app data from JSON.

func MakeAppData

func MakeAppData(id, secret string, active bool, name, description string, scopes []string, offline bool, redirectURLs []string,
	refreshTokenLifespan, inviteTokenLifespan, tokenLifespan int64, tokenPayload []string, registrationForbidden bool,
	tfaStatus model.TFAStatus, debugTFACode string, authzWay model.AuthorizationWay, authzModel, authzPolicy string, rolesWhitelist, rolesBlacklist []string, newUserDefaultRole string) (AppData, error)

MakeAppData creates new MongoDB app data instance.

func NewAppData

func NewAppData(data model.AppData) (AppData, error)

NewAppData instantiates MongoDB app data model from the general one.

func (*AppData) Active

func (ad *AppData) Active() bool

Active implements model.AppData interface.

func (*AppData) AppleInfo

func (ad *AppData) AppleInfo() *model.AppleInfo

AppleInfo implements model.AppData interface.

func (*AppData) AuthzModel

func (ad *AppData) AuthzModel() string

AuthzModel implements model.AppData interface.

func (*AppData) AuthzPolicy

func (ad *AppData) AuthzPolicy() string

AuthzPolicy implements model.AppData interface.

func (*AppData) AuthzWay

func (ad *AppData) AuthzWay() model.AuthorizationWay

AuthzWay implements model.AppData interface.

func (*AppData) DebugTFACode

func (ad *AppData) DebugTFACode() string

DebugTFACode implements model.AppData interface.

func (*AppData) Description

func (ad *AppData) Description() string

Description implements model.AppData interface.

func (*AppData) ID

func (ad *AppData) ID() string

ID implements model.AppData interface.

func (*AppData) InviteTokenLifespan

func (ad *AppData) InviteTokenLifespan() int64

InviteTokenLifespan implements model.AppData interface.

func (AppData) Marshal

func (ad AppData) Marshal() ([]byte, error)

Marshal serializes data to byte array.

func (*AppData) Name

func (ad *AppData) Name() string

Name implements model.AppData interface.

func (*AppData) NewUserDefaultRole

func (ad *AppData) NewUserDefaultRole() string

NewUserDefaultRole implements model.AppData interface.

func (*AppData) Offline

func (ad *AppData) Offline() bool

Offline implements model.AppData interface.

func (*AppData) RedirectURLs

func (ad *AppData) RedirectURLs() []string

RedirectURLs implements model.AppData interface.

func (*AppData) RefreshTokenLifespan

func (ad *AppData) RefreshTokenLifespan() int64

RefreshTokenLifespan implements model.AppData interface.

func (*AppData) RegistrationForbidden

func (ad *AppData) RegistrationForbidden() bool

RegistrationForbidden implements model.AppData interface.

func (*AppData) RolesBlacklist

func (ad *AppData) RolesBlacklist() []string

RolesBlacklist implements model.AppData interface.

func (*AppData) RolesWhitelist

func (ad *AppData) RolesWhitelist() []string

RolesWhitelist implements model.AppData interface.

func (*AppData) Sanitize

func (ad *AppData) Sanitize()

Sanitize removes all sensitive data.

func (*AppData) Scopes

func (ad *AppData) Scopes() []string

Scopes implements model.AppData interface.

func (*AppData) Secret

func (ad *AppData) Secret() string

Secret implements model.AppData interface.

func (*AppData) SetSecret

func (ad *AppData) SetSecret(secret string)

SetSecret implements model.AppData interface.

func (*AppData) TFAStatus

func (ad *AppData) TFAStatus() model.TFAStatus

TFAStatus implements model.AppData interface.

func (*AppData) TokenLifespan

func (ad *AppData) TokenLifespan() int64

TokenLifespan implements model.AppData interface.

func (*AppData) TokenPayload

func (ad *AppData) TokenPayload() []string

TokenPayload implements model.AppData interface.

func (*AppData) Type

func (ad *AppData) Type() model.AppType

Type implements model.AppData interface.

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) Close

func (as *AppStorage) Close()

Close closes database connection.

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, skip, limit int) ([]model.AppData, int, error)

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

func (*AppStorage) ImportJSON

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

ImportJSON imports data from JSON.

func (*AppStorage) NewAppData

func (as *AppStorage) NewAppData() model.AppData

NewAppData returns pointer to newly created app data.

func (*AppStorage) TestDatabaseConnection

func (as *AppStorage) TestDatabaseConnection() error

TestDatabaseConnection checks whether we can fetch the first document in the applications collection.

func (*AppStorage) UpdateApp

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

UpdateApp updates app in MongoDB storage.

type DB

type DB struct {
	S  *mgo.Session
	DB string
}

DB is database connection structure

func NewDB

func NewDB(conn string, db string) (*DB, error)

NewDB creates new database connection

func (*DB) Close

func (db *DB) Close()

Close closes database connection

func (*DB) Session

func (db *DB) Session(col string) *Session

Session creates new database connection session don't dorget to close it, defer is commonly used way to do it

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 Session

type Session struct {
	C *mgo.Collection
	S *mgo.Session
}

Session implements one single session connection to database

func (*Session) Close

func (s *Session) Close()

Close closes connection to current session

func (*Session) EnsureIndex

func (s *Session) EnsureIndex(index mgo.Index) error

EnsureIndex wraps mongo EnsureIndex function. Purpose is to try recreate index if something went wrong.

type Token

type Token struct {
	ID    bson.ObjectId `bson:"_id,omitempty"`
	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 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 closes database connection.

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 closes database connection.

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 User

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

User is a data structure for MongoDB storage.

func UserFromJSON

func UserFromJSON(d []byte) (*User, error)

UserFromJSON deserializes user from JSON.

func (*User) AccessRole

func (u *User) AccessRole() string

AccessRole implements model.User interface.

func (*User) Active

func (u *User) Active() bool

Active implements model.User interface.

func (*User) Deanonimize added in v0.0.2

func (u *User) Deanonimize()

Deanonimize implements model.User interface.

func (*User) Email

func (u *User) Email() string

Email implements model.User interface.

func (*User) ID

func (u *User) ID() string

ID implements model.User interface.

func (*User) IsAnonymous added in v0.0.2

func (u *User) IsAnonymous() bool

IsAnonymous implements model.User interface.

func (*User) PasswordHash

func (u *User) PasswordHash() string

PasswordHash implements model.User interface.

func (*User) Phone

func (u *User) Phone() string

Phone implements model.User interface.

func (*User) Sanitize

func (u *User) Sanitize()

Sanitize removes sensitive data.

func (*User) SetEmail

func (u *User) SetEmail(email string)

SetEmail implements model.User interface.

func (*User) SetTFAInfo

func (u *User) SetTFAInfo(tfaInfo model.TFAInfo)

SetTFAInfo implements model.User interface.

func (*User) SetUsername

func (u *User) SetUsername(username string)

SetUsername implements model.User interface.

func (*User) TFAInfo

func (u *User) TFAInfo() model.TFAInfo

TFAInfo implements model.User interface.

func (*User) Username

func (u *User) Username() string

Username implements model.User interface.

type UserStorage

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

UserStorage implements user storage interface.

func (*UserStorage) AddNewUser

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

AddNewUser adds new user to the database.

func (*UserStorage) AddUserByNameAndPassword

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

AddUserByNameAndPassword registers new user.

func (*UserStorage) AddUserByPhone

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

AddUserByPhone registers new user with phone number.

func (*UserStorage) AddUserWithFederatedID

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

AddUserWithFederatedID adds new user with social ID.

func (*UserStorage) AttachDeviceToken

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

AttachDeviceToken do nothing here TODO: implement device storage

func (*UserStorage) Close

func (us *UserStorage) Close()

Close closes database connection.

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) IDByName

func (us *UserStorage) IDByName(name string) (string, error)

IDByName returns userID by name.

func (*UserStorage) ImportJSON

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

ImportJSON imports data from JSON.

func (*UserStorage) NewUser

func (us *UserStorage) NewUser() model.User

NewUser returns pointer to newly created user.

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 its email.

func (*UserStorage) UserByFederatedID

func (us *UserStorage) UserByFederatedID(provider model.FederatedIdentityProvider, 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) UserByNamePassword

func (us *UserStorage) UserByNamePassword(name, password string) (model.User, error)

UserByNamePassword returns user by name and password.

func (*UserStorage) UserByPhone

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

UserByPhone fetches user by phone number.

func (*UserStorage) UserExists

func (us *UserStorage) UserExists(name string) bool

UserExists checks if user with provided name exists.

type VerificationCodeStorage

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

VerificationCodeStorage implements verification code storage interface.

func (*VerificationCodeStorage) Close

func (vcs *VerificationCodeStorage) Close()

Close closes database connection.

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