connector

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: Apache-2.0, Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DropAllSQL contains SQL to drop all existing table for hansip
	DropAllSQL = `DROP TABLE IF EXISTS HANSIP_USER_GROUP, HANSIP_USER_ROLE, HANSIP_GROUP_ROLE, HANSIP_USER, HANSIP_GROUP, HANSIP_ROLE;`
	// CreateUserSQL will create HANSIP_USER table
	CreateUserSQL = `` /* 587-byte string literal not displayed */

	// CreateGroupSQL contains SQL to  create HANSIP_GROUP
	CreateGroupSQL = `` /* 230-byte string literal not displayed */

	// CreateRoleSQL contains SQL to create HANSIP_ROLE table
	CreateRoleSQL = `` /* 227-byte string literal not displayed */

	// CreateUserRoleSQL contains SQL to create HANSIP_USER_ROLE table
	CreateUserRoleSQL = `` /* 340-byte string literal not displayed */

	// CreateUserGroupSQL contains SQL to create HANSIP_USER_GROUP
	CreateUserGroupSQL = `` /* 345-byte string literal not displayed */

	// CreateGroupRoleSQL contains SQL to create HANSIP_GROUP_ROLE table
	CreateGroupRoleSQL = `` /* 345-byte string literal not displayed */

	// CreateTOTPRecoveryCodeSQL contains SQL to create HANSIP_TOTP_RECOVERY_CODES table
	CreateTOTPRecoveryCodeSQL = `` /* 306-byte string literal not displayed */

)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBUtil

type DBUtil interface {
	// DropAllTables will drop all existing table
	DropAllTables(ctx context.Context) error

	// CreateAllTable will create tables needed for the Apps if not exist
	CreateAllTable(ctx context.Context) error
}

DBUtil is interface to help working with table create and drop

type DummyMail

type DummyMail struct {
	From    string
	To      string
	Cc      string
	Bcc     string
	Subject string
	Body    string
}

DummyMail dummy email data structure

type DummyMailSender

type DummyMailSender struct {
	LastSentMail *DummyMail
}

DummyMailSender a dummy email sender. It does not send any email.

func (*DummyMailSender) SendEmail

func (sender *DummyMailSender) SendEmail(ctx context.Context, to, cc, bcc []string, from, fromName, subject, body string) error

SendEmail a dummy implementation, it just log out the email information.

type EmailSender

type EmailSender interface {
	SendEmail(ctx context.Context, to, cc, bcc []string, from, fromName, subject, body string) error
}

EmailSender an email sender interface

type Group

type Group struct {
	// RecID. Primary key
	RecID string `json:"rec_id"`

	// GroupName of the group, Primary Key
	GroupName string `json:"group_name"`

	// Description of the group
	Description string `json:"description"`
}

Group record entity

type GroupRepository

type GroupRepository interface {
	// GetGroupByRecID return a group record
	GetGroupByRecID(ctx context.Context, recID string) (*Group, error)

	// GetGroupByName return a group record
	GetGroupByName(ctx context.Context, groupName string) (*Group, error)

	// CreateGroup into the Group table
	CreateGroup(ctx context.Context, groupName, description string) (*Group, error)

	// ListGroup from the Group table
	ListGroups(ctx context.Context, request *helper.PageRequest) ([]*Group, *helper.Page, error)

	// DeleteGroup from Group table
	DeleteGroup(ctx context.Context, group *Group) error

	// CreateUserGroup into Group table
	SaveOrUpdateGroup(ctx context.Context, group *Group) error
}

GroupRepository manage Group table

type GroupRole

type GroupRole struct {
	// GroupName composite key to Group
	GroupRecID string `json:"group_rec_id"`

	// RoleName composite key to Role
	RoleRecID string `json:"role_rec_id"`
}

GroupRole record entity

type GroupRoleRepository

type GroupRoleRepository interface {

	// GetGroupRole return existing group role
	GetGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)

	// CreateGroupRole into GroupRole table
	CreateGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)

	// ListGroupRoleByGroupName from GroupRole table
	ListGroupRoleByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*Role, *helper.Page, error)

	// ListGroupRoleByRoleName from GroupRole table
	ListGroupRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*Group, *helper.Page, error)

	// DeleteGroupRole from GroupRole table
	DeleteGroupRole(ctx context.Context, groupRole *GroupRole) error

	// DeleteGroupRoleByEmail from GroupRole table
	DeleteGroupRoleByGroup(ctx context.Context, group *Group) error

	// DeleteGroupRoleByRoleName from GroupRole table
	DeleteGroupRoleByRole(ctx context.Context, role *Role) error
}

GroupRoleRepository manage GroupRole table

type InMemoryDb

type InMemoryDb struct {
	UserTable             map[string]*User
	UserRoleTable         map[string]*UserRole
	RoleTable             map[string]*Role
	GroupTable            map[string]*Group
	GroupRoleTable        map[string]*GroupRole
	UserGroupTable        map[string]*UserGroup
	TOTPRecoveryCodeTable map[string]*TOTPRecoveryCode
}

InMemoryDb structure that stores inmemory data.

func GetInMemoryDbInstance

func GetInMemoryDbInstance() *InMemoryDb

GetInMemoryDbInstance get InMemoryDatabase implementation. backed by map

func (*InMemoryDb) Count

func (mem *InMemoryDb) Count(ctx context.Context) (int, error)

Count will count all user entries

func (*InMemoryDb) CreateAllTable

func (mem *InMemoryDb) CreateAllTable(ctx context.Context) error

CreateAllTable clears up all data in the memory. As if database is freshly created all tables.

func (*InMemoryDb) CreateGroup

func (mem *InMemoryDb) CreateGroup(ctx context.Context, groupName, description string) (*Group, error)

CreateGroup creates new Group

func (*InMemoryDb) CreateGroupRole

func (mem *InMemoryDb) CreateGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)

CreateGroupRole creates new group and role relation

func (*InMemoryDb) CreateRole

func (mem *InMemoryDb) CreateRole(ctx context.Context, roleName, description string) (*Role, error)

CreateRole creates new role

func (*InMemoryDb) CreateUserGroup

func (mem *InMemoryDb) CreateUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)

CreateUserGroup create a new user-group relation

func (*InMemoryDb) CreateUserRecord

func (mem *InMemoryDb) CreateUserRecord(ctx context.Context, email, passphrase string) (*User, error)

CreateUserRecord creates new user

func (*InMemoryDb) CreateUserRole

func (mem *InMemoryDb) CreateUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)

CreateUserRole assign a role to user

func (*InMemoryDb) DeleteGroup

func (mem *InMemoryDb) DeleteGroup(ctx context.Context, group *Group) error

DeleteGroup will deletes a group and all relation to user and role

func (*InMemoryDb) DeleteGroupRole

func (mem *InMemoryDb) DeleteGroupRole(ctx context.Context, groupRole *GroupRole) error

DeleteGroupRole deletes a relation between group and role

func (*InMemoryDb) DeleteGroupRoleByGroup

func (mem *InMemoryDb) DeleteGroupRoleByGroup(ctx context.Context, group *Group) error

DeleteGroupRoleByGroup deletes all group-role relation related to a group

func (*InMemoryDb) DeleteGroupRoleByRole

func (mem *InMemoryDb) DeleteGroupRoleByRole(ctx context.Context, role *Role) error

DeleteGroupRoleByRole deletes all group-role relation related to a role

func (*InMemoryDb) DeleteRole

func (mem *InMemoryDb) DeleteRole(ctx context.Context, role *Role) error

DeleteRole deletes a role and all relation to user and group

func (*InMemoryDb) DeleteUser

func (mem *InMemoryDb) DeleteUser(ctx context.Context, user *User) error

DeleteUser delete a user

func (*InMemoryDb) DeleteUserGroup

func (mem *InMemoryDb) DeleteUserGroup(ctx context.Context, userGroup *UserGroup) error

DeleteUserGroup will delete a speciffic user-group relation.

func (*InMemoryDb) DeleteUserGroupByGroup

func (mem *InMemoryDb) DeleteUserGroupByGroup(ctx context.Context, group *Group) error

DeleteUserGroupByGroup deletes all user-group relation by a group

func (*InMemoryDb) DeleteUserGroupByUser

func (mem *InMemoryDb) DeleteUserGroupByUser(ctx context.Context, user *User) error

DeleteUserGroupByUser delete all user-group relations by a user.

func (*InMemoryDb) DeleteUserRole

func (mem *InMemoryDb) DeleteUserRole(ctx context.Context, userRole *UserRole) error

DeleteUserRole delete relation between user and role

func (*InMemoryDb) DeleteUserRoleByRole

func (mem *InMemoryDb) DeleteUserRoleByRole(ctx context.Context, role *Role) error

DeleteUserRoleByRole delete user-role relation by a role

func (*InMemoryDb) DeleteUserRoleByUser

func (mem *InMemoryDb) DeleteUserRoleByUser(ctx context.Context, user *User) error

DeleteUserRoleByUser delete user-role relation by user

func (*InMemoryDb) DropAllTables

func (mem *InMemoryDb) DropAllTables(ctx context.Context) error

DropAllTables will do nothing in this inmemory implementation

func (*InMemoryDb) GetGroupByName

func (mem *InMemoryDb) GetGroupByName(ctx context.Context, groupName string) (*Group, error)

GetGroupByName return a group record

func (*InMemoryDb) GetGroupByRecID

func (mem *InMemoryDb) GetGroupByRecID(ctx context.Context, recID string) (*Group, error)

GetGroupByRecID Get a group by its RecID

func (*InMemoryDb) GetGroupRole

func (mem *InMemoryDb) GetGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)

GetGroupRole will get a group role by specific group and role

func (*InMemoryDb) GetRoleByName

func (mem *InMemoryDb) GetRoleByName(ctx context.Context, roleName string) (*Role, error)

GetRoleByName return a role record

func (*InMemoryDb) GetRoleByRecID

func (mem *InMemoryDb) GetRoleByRecID(ctx context.Context, recID string) (*Role, error)

GetRoleByRecID get a specific role by its recID

func (*InMemoryDb) GetTOTPRecoveryCodes

func (mem *InMemoryDb) GetTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)

GetTOTPRecoveryCodes retrieves all valid/not used TOTP recovery codes.

func (*InMemoryDb) GetUserBy2FAToken

func (mem *InMemoryDb) GetUserBy2FAToken(ctx context.Context, token string) (*User, error)

GetUserBy2FAToken fetch user by 2fa token

func (*InMemoryDb) GetUserByEmail

func (mem *InMemoryDb) GetUserByEmail(ctx context.Context, email string) (*User, error)

GetUserByEmail return user with specified Email

func (*InMemoryDb) GetUserByRecID

func (mem *InMemoryDb) GetUserByRecID(ctx context.Context, recID string) (*User, error)

GetUserByRecID returns user with specified recID

func (*InMemoryDb) GetUserByRecoveryToken

func (mem *InMemoryDb) GetUserByRecoveryToken(ctx context.Context, token string) (*User, error)

GetUserByRecoveryToken fetch user by recovery token

func (*InMemoryDb) GetUserGroup

func (mem *InMemoryDb) GetUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)

GetUserGroup get user group relation by user and group

func (*InMemoryDb) GetUserRole

func (mem *InMemoryDb) GetUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)

GetUserRole get all roles of user

func (*InMemoryDb) ListAllUserRoles

func (mem *InMemoryDb) ListAllUserRoles(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)

ListAllUserRoles list a role owned by user

func (*InMemoryDb) ListGroupRoleByGroup

func (mem *InMemoryDb) ListGroupRoleByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*Role, *helper.Page, error)

ListGroupRoleByGroup list all role owned by a group

func (*InMemoryDb) ListGroupRoleByRole

func (mem *InMemoryDb) ListGroupRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*Group, *helper.Page, error)

ListGroupRoleByRole list all groups owning a role

func (*InMemoryDb) ListGroups

func (mem *InMemoryDb) ListGroups(ctx context.Context, request *helper.PageRequest) ([]*Group, *helper.Page, error)

ListGroups list all groups

func (*InMemoryDb) ListRoles

func (mem *InMemoryDb) ListRoles(ctx context.Context, request *helper.PageRequest) ([]*Role, *helper.Page, error)

ListRoles list all roles

func (*InMemoryDb) ListUser

func (mem *InMemoryDb) ListUser(ctx context.Context, request *helper.PageRequest) ([]*User, *helper.Page, error)

ListUser list all users

func (*InMemoryDb) ListUserGroupByGroup

func (mem *InMemoryDb) ListUserGroupByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*User, *helper.Page, error)

ListUserGroupByGroup will list all users joining a group

func (*InMemoryDb) ListUserGroupByUser

func (mem *InMemoryDb) ListUserGroupByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Group, *helper.Page, error)

ListUserGroupByUser will list all groups joined by a user

func (*InMemoryDb) ListUserRoleByRole

func (mem *InMemoryDb) ListUserRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*User, *helper.Page, error)

ListUserRoleByRole fetch user who owns a role

func (*InMemoryDb) ListUserRoleByUser

func (mem *InMemoryDb) ListUserRoleByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)

ListUserRoleByUser fetch role owned by user

func (*InMemoryDb) MarkTOTPRecoveryCodeUsed

func (mem *InMemoryDb) MarkTOTPRecoveryCodeUsed(ctx context.Context, user *User, code string) error

MarkTOTPRecoveryCodeUsed will mark the specific recovery code as used and thus can not be used anymore.

func (*InMemoryDb) RecreateTOTPRecoveryCodes

func (mem *InMemoryDb) RecreateTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)

RecreateTOTPRecoveryCodes recreates 16 new recovery codes.

func (*InMemoryDb) SaveOrUpdate

func (mem *InMemoryDb) SaveOrUpdate(ctx context.Context, user *User) error

SaveOrUpdate will save a user if its not saved, or update if its already exist

func (*InMemoryDb) SaveOrUpdateGroup

func (mem *InMemoryDb) SaveOrUpdateGroup(ctx context.Context, group *Group) error

SaveOrUpdateGroup save or update group data.

func (*InMemoryDb) SaveOrUpdateRole

func (mem *InMemoryDb) SaveOrUpdateRole(ctx context.Context, role *Role) error

SaveOrUpdateRole will save a role into db if its not exist, or update it if its already exist

type MySQLDB

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

MySQLDB is a struct to hold sql.DB pointer

func GetMySQLDBInstance

func GetMySQLDBInstance() *MySQLDB

GetMySQLDBInstance will obtain the singleton instance to MySQLDB

func (*MySQLDB) Count

func (db *MySQLDB) Count(ctx context.Context) (int, error)

Count all user

func (*MySQLDB) CreateAllTable

func (db *MySQLDB) CreateAllTable(ctx context.Context) error

CreateAllTable creates all table used by Hansip

func (*MySQLDB) CreateGroup

func (db *MySQLDB) CreateGroup(ctx context.Context, groupName, description string) (*Group, error)

CreateGroup create new Group

func (*MySQLDB) CreateGroupRole

func (db *MySQLDB) CreateGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)

CreateGroupRole create new Group and Role relation

func (*MySQLDB) CreateRole

func (db *MySQLDB) CreateRole(ctx context.Context, roleName, description string) (*Role, error)

CreateRole creates a new role

func (*MySQLDB) CreateUserGroup

func (db *MySQLDB) CreateUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)

CreateUserGroup create new relation between user and group

func (*MySQLDB) CreateUserRecord

func (db *MySQLDB) CreateUserRecord(ctx context.Context, email, passphrase string) (*User, error)

CreateUserRecord create a new user

func (*MySQLDB) CreateUserRole

func (db *MySQLDB) CreateUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)

CreateUserRole assign a role to a user.

func (*MySQLDB) DeleteGroup

func (db *MySQLDB) DeleteGroup(ctx context.Context, group *Group) error

DeleteGroup delete one speciffic group

func (*MySQLDB) DeleteGroupRole

func (db *MySQLDB) DeleteGroupRole(ctx context.Context, groupRole *GroupRole) error

DeleteGroupRole delete a group-role relation

func (*MySQLDB) DeleteGroupRoleByGroup

func (db *MySQLDB) DeleteGroupRoleByGroup(ctx context.Context, group *Group) error

DeleteGroupRoleByGroup deletes group-role relation by the group

func (*MySQLDB) DeleteGroupRoleByRole

func (db *MySQLDB) DeleteGroupRoleByRole(ctx context.Context, role *Role) error

DeleteGroupRoleByRole deletes grou[-role relation by the role

func (*MySQLDB) DeleteRole

func (db *MySQLDB) DeleteRole(ctx context.Context, role *Role) error

DeleteRole delete a specific role from this server

func (*MySQLDB) DeleteUser

func (db *MySQLDB) DeleteUser(ctx context.Context, user *User) error

DeleteUser delete a user

func (*MySQLDB) DeleteUserGroup

func (db *MySQLDB) DeleteUserGroup(ctx context.Context, userGroup *UserGroup) error

DeleteUserGroup will delete a user-group

func (*MySQLDB) DeleteUserGroupByGroup

func (db *MySQLDB) DeleteUserGroupByGroup(ctx context.Context, group *Group) error

DeleteUserGroupByGroup will delete user-group relation by a group

func (*MySQLDB) DeleteUserGroupByUser

func (db *MySQLDB) DeleteUserGroupByUser(ctx context.Context, user *User) error

DeleteUserGroupByUser will delete a user-group relation by a user

func (*MySQLDB) DeleteUserRole

func (db *MySQLDB) DeleteUserRole(ctx context.Context, userRole *UserRole) error

DeleteUserRole remove a role from user's assigment

func (*MySQLDB) DeleteUserRoleByRole

func (db *MySQLDB) DeleteUserRoleByRole(ctx context.Context, role *Role) error

DeleteUserRoleByRole remove all user-role assigment to a role

func (*MySQLDB) DeleteUserRoleByUser

func (db *MySQLDB) DeleteUserRoleByUser(ctx context.Context, user *User) error

DeleteUserRoleByUser remove ALL role assigment of a user

func (*MySQLDB) DropAllTables

func (db *MySQLDB) DropAllTables(ctx context.Context) error

DropAllTables will drop all tables used by Hansip

func (*MySQLDB) GetGroupByName

func (db *MySQLDB) GetGroupByName(ctx context.Context, groupName string) (*Group, error)

func (*MySQLDB) GetGroupByRecID

func (db *MySQLDB) GetGroupByRecID(ctx context.Context, recID string) (*Group, error)

GetGroupByRecID return a Group data by its RedID

func (*MySQLDB) GetGroupRole

func (db *MySQLDB) GetGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)

GetGroupRole get GroupRole relation

func (*MySQLDB) GetRoleByName

func (db *MySQLDB) GetRoleByName(ctx context.Context, roleName string) (*Role, error)

GetRoleByName return a role record

func (*MySQLDB) GetRoleByRecID

func (db *MySQLDB) GetRoleByRecID(ctx context.Context, recID string) (*Role, error)

GetRoleByRecID return a role with speciffic recID

func (*MySQLDB) GetTOTPRecoveryCodes

func (db *MySQLDB) GetTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)

GetTOTPRecoveryCodes retrieves all valid/not used TOTP recovery codes.

func (*MySQLDB) GetUserBy2FAToken

func (db *MySQLDB) GetUserBy2FAToken(ctx context.Context, token string) (*User, error)

GetUserBy2FAToken get a user by its 2FA token

func (*MySQLDB) GetUserByEmail

func (db *MySQLDB) GetUserByEmail(ctx context.Context, email string) (*User, error)

GetUserByEmail get user record by its email address

func (*MySQLDB) GetUserByRecID

func (db *MySQLDB) GetUserByRecID(ctx context.Context, recID string) (*User, error)

GetUserByRecID get user data by its RecID

func (*MySQLDB) GetUserByRecoveryToken

func (db *MySQLDB) GetUserByRecoveryToken(ctx context.Context, token string) (*User, error)

GetUserByRecoveryToken get a user by its recovery token

func (*MySQLDB) GetUserGroup

func (db *MySQLDB) GetUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)

GetUserGroup list all user-group relation

func (*MySQLDB) GetUserRole

func (db *MySQLDB) GetUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)

GetUserRole return user's assigned roles

func (*MySQLDB) InitDB

func (db *MySQLDB) InitDB(ctx context.Context) error

InitDB will initialize this connector.

func (*MySQLDB) IsGroupRecIDExist

func (db *MySQLDB) IsGroupRecIDExist(ctx context.Context, recID string) (bool, error)

IsGroupRecIDExist check if a speciffic group recId is exist in database

func (*MySQLDB) IsRoleRecIDExist

func (db *MySQLDB) IsRoleRecIDExist(ctx context.Context, recID string) (bool, error)

IsRoleRecIDExist check if a speciffic role recId is exist in database

func (*MySQLDB) IsUserRecIDExist

func (db *MySQLDB) IsUserRecIDExist(ctx context.Context, recID string) (bool, error)

IsUserRecIDExist check if a specific user recId is exist in database

func (*MySQLDB) ListAllUserRoles

func (db *MySQLDB) ListAllUserRoles(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)

ListAllUserRoles list all user's roles direct and indirect

func (*MySQLDB) ListGroupRoleByGroup

func (db *MySQLDB) ListGroupRoleByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*Role, *helper.Page, error)

ListGroupRoleByGroup list all role related to a group

func (*MySQLDB) ListGroupRoleByRole

func (db *MySQLDB) ListGroupRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*Group, *helper.Page, error)

ListGroupRoleByRole will list all group- related to a role

func (*MySQLDB) ListGroups

func (db *MySQLDB) ListGroups(ctx context.Context, request *helper.PageRequest) ([]*Group, *helper.Page, error)

ListGroups list all groups in this server

func (*MySQLDB) ListRoles

func (db *MySQLDB) ListRoles(ctx context.Context, request *helper.PageRequest) ([]*Role, *helper.Page, error)

ListRoles list all roles in this server

func (*MySQLDB) ListUser

func (db *MySQLDB) ListUser(ctx context.Context, request *helper.PageRequest) ([]*User, *helper.Page, error)

ListUser list all user paginated

func (*MySQLDB) ListUserGroupByGroup

func (db *MySQLDB) ListUserGroupByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*User, *helper.Page, error)

ListUserGroupByGroup will list all users that related to a group

func (*MySQLDB) ListUserGroupByUser

func (db *MySQLDB) ListUserGroupByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Group, *helper.Page, error)

ListUserGroupByUser will list groups that related to a user

func (*MySQLDB) ListUserRoleByRole

func (db *MySQLDB) ListUserRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*User, *helper.Page, error)

ListUserRoleByRole list all user that related to a role

func (*MySQLDB) ListUserRoleByUser

func (db *MySQLDB) ListUserRoleByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)

ListUserRoleByUser get all roles assigned to a user, paginated

func (*MySQLDB) MarkTOTPRecoveryCodeUsed

func (db *MySQLDB) MarkTOTPRecoveryCodeUsed(ctx context.Context, user *User, code string) error

MarkTOTPRecoveryCodeUsed will mark the specific recovery code as used and thus can not be used anymore.

func (*MySQLDB) RecreateTOTPRecoveryCodes

func (db *MySQLDB) RecreateTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)

RecreateTOTPRecoveryCodes recreates 16 new recovery codes.

func (*MySQLDB) SaveOrUpdate

func (db *MySQLDB) SaveOrUpdate(ctx context.Context, user *User) error

SaveOrUpdate save or update a user data

func (*MySQLDB) SaveOrUpdateGroup

func (db *MySQLDB) SaveOrUpdateGroup(ctx context.Context, group *Group) error

SaveOrUpdateGroup delete one specific group

func (*MySQLDB) SaveOrUpdateRole

func (db *MySQLDB) SaveOrUpdateRole(ctx context.Context, role *Role) error

SaveOrUpdateRole save or update a role record

type Recipients

type Recipients struct {
	To map[string]bool
}

Recipients contains recipient map

func (*Recipients) AddAll

func (r *Recipients) AddAll(re []string)

AddAll adds multiple recipient in array

func (*Recipients) Recipients

func (r *Recipients) Recipients() []string

Recipients returns all recipients

type Role

type Role struct {
	// RecID. Primary key
	RecID string `json:"rec_id"`

	// RoleName of the role, Unique
	RoleName string `json:"role_name"`

	// Description of the role
	Description string `json:"description"`
}

Role record entity

type RoleRepository

type RoleRepository interface {
	// GetRoleByRecID return an existing role
	GetRoleByRecID(ctx context.Context, recID string) (*Role, error)

	// GetRoleByName return a role record
	GetRoleByName(ctx context.Context, roleName string) (*Role, error)

	// CreateRole into Role table
	CreateRole(ctx context.Context, roleName, description string) (*Role, error)

	// ListRoles from Role table
	ListRoles(ctx context.Context, request *helper.PageRequest) ([]*Role, *helper.Page, error)

	// DeleteRole from Role table
	DeleteRole(ctx context.Context, role *Role) error

	// SaveOrUpdateRole into Role table
	SaveOrUpdateRole(ctx context.Context, role *Role) error
}

RoleRepository manage Role table

type SendGridSender

type SendGridSender struct {
	Token string
}

SendGridSender implementation using sendgrid. contains sendgrid token.

func (*SendGridSender) SendEmail

func (sender *SendGridSender) SendEmail(ctx context.Context, to, cc, bcc []string, from, fromName, subject, body string) error

SendEmail email sending implementation using SendGrid

type SendMailSender

type SendMailSender struct {
	Host     string
	Port     int
	User     string
	Password string
}

SendMailSender send mail implementation using sendmail

func (*SendMailSender) SendEmail

func (sender *SendMailSender) SendEmail(ctx context.Context, to, cc, bcc []string, from, fromName, subject, body string) error

SendEmail implementation to send email using sendmail

type TOTPRecoveryCode

type TOTPRecoveryCode struct {
	// RecID. Primary Key
	RecID string `json:"rec_id"`

	// The 8 digit key used once code. No dash separator. Only upper A-Z and 0-9
	Code string `json:"code"`

	// The used flag. If true, this token can not be used anymore.
	Used bool `json:"used"`

	// The owner of this code.
	UserRecID string `json:"user_rec_id"`
}

TOTPRecoveryCode used to login the user if the user lost his TOTP code due to lost of 2FE token device.

type User

type User struct {
	// RecID. Primary key
	RecID string `json:"rec_id"`

	// Email address. unique
	Email string `json:"email"`

	// HashedPassphrase bcrypt hashed passphrase
	HashedPassphrase string `json:"hashed_passphrase"`

	// Enabled status of the user
	Enabled bool `json:"enabled"`

	// Suspended status of the user
	Suspended bool `json:"suspended"`

	// LastSeen time of the user
	LastSeen time.Time `json:"last_seen"`

	// LastLogin time of the user
	LastLogin time.Time `json:"last_login"`

	// FailCount of login attempt
	FailCount int `json:"fail_count"`

	// ActivationCode for activating/enabling the user
	ActivationCode string `json:"activation_code"`

	// ActivationDate time of the user
	ActivationDate time.Time `json:"activation_date"`

	// UserTotpSecretKey for 2 factor authentication
	UserTotpSecretKey string `json:"user_totp_secret_key"`

	// Enable2FactorAuth used for enabling 2 factor auth
	Enable2FactorAuth bool `json:"enable_2_factor_auth"`

	// Token2FA used to authenticate back using 2FA
	Token2FA string `json:"token_2_fa"`

	// RecoveryCode used to recover lost passphrase
	RecoveryCode string `json:"recovery_code"`
}

User record entity

type UserGroup

type UserGroup struct {
	// Email composite key to User
	UserRecID string `json:"user_rec_id"`

	// GroupName composite key to Group
	GroupRecID string `json:"group_rec_id"`
}

UserGroup record entity

type UserGroupRepository

type UserGroupRepository interface {
	// GetUserGroup returns existing UserGroup
	GetUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)

	// CreateUserGroup into UserGroup table
	CreateUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)

	// ListUserGroupByEmail from the UserGroup table
	ListUserGroupByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Group, *helper.Page, error)

	// ListUserGroupByGroupName from the UserGroup table
	ListUserGroupByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*User, *helper.Page, error)

	// DeleteUserGroup from the UserGroup table
	DeleteUserGroup(ctx context.Context, userGroup *UserGroup) error

	// DeleteUserGroupByEmail from the UserGroup table
	DeleteUserGroupByUser(ctx context.Context, user *User) error

	// DeleteUserGroupByGroupName from the UserGroup table
	DeleteUserGroupByGroup(ctx context.Context, group *Group) error
}

UserGroupRepository manage UserGroup table

type UserRepository

type UserRepository interface {
	// GetUserByRecID return a user record
	GetUserByRecID(ctx context.Context, recID string) (*User, error)

	// CreateUserRecord in the User table
	CreateUserRecord(ctx context.Context, email, passphrase string) (*User, error)

	// GetUserByEmail return a user record
	GetUserByEmail(ctx context.Context, email string) (*User, error)

	// GetUserBy2FAToken return a user record
	GetUserBy2FAToken(ctx context.Context, token string) (*User, error)

	// GetUserByRecoveryToken return user record
	GetUserByRecoveryToken(ctx context.Context, token string) (*User, error)

	// DeleteUser removes a user entity from table
	DeleteUser(ctx context.Context, user *User) error

	// SaveOrUpdate a user entity into table user
	SaveOrUpdate(ctx context.Context, user *User) error

	// ListUser from database with pagination
	ListUser(ctx context.Context, request *helper.PageRequest) ([]*User, *helper.Page, error)

	// Count all user entity in table
	Count(ctx context.Context) (int, error)

	// ListAllUserRoles will list all roles owned by a particular user
	ListAllUserRoles(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)

	// GetTOTPRecoveryCodes retrieves all valid/not used TOTP recovery codes.
	GetTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)

	// RecreateTOTPRecoveryCodes recreates 16 new recovery codes.
	RecreateTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)

	// MarkTOTPRecoveryCodeUsed will mark the specific recovery code as used and thus can not be used anymore.
	MarkTOTPRecoveryCodeUsed(ctx context.Context, user *User, code string) error
}

UserRepository manage User table

type UserRole

type UserRole struct {
	// Email composite key to User
	UserRecID string `json:"user_rec_id"`

	// RoleName composite key to Role
	RoleRecID string `json:"role_rec_id"`
}

UserRole record entity

type UserRoleRepository

type UserRoleRepository interface {
	// GetUserRole returns existing user role
	GetUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)

	// CreateUserRole into UserRole table
	CreateUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)

	// ListUserRoleByEmail from UserRole table
	ListUserRoleByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)

	// ListUserRoleByRoleName from UserRole table
	ListUserRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*User, *helper.Page, error)

	// DeleteUserRole from UserRole table
	DeleteUserRole(ctx context.Context, userRole *UserRole) error

	// DeleteUserRoleByEmail from UserRole table
	DeleteUserRoleByUser(ctx context.Context, user *User) error

	// DeleteUserRoleByRoleName from UserRole table
	DeleteUserRoleByRole(ctx context.Context, role *Role) error
}

UserRoleRepository manage UserRole table

Jump to

Keyboard shortcuts

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