Documentation ¶
Index ¶
- Constants
- type DBUtil
- type DummyMail
- type DummyMailSender
- type EmailSender
- type Group
- type GroupRepository
- type GroupRole
- type GroupRoleRepository
- type InMemoryDb
- func (mem *InMemoryDb) Count(ctx context.Context) (int, error)
- func (mem *InMemoryDb) CreateAllTable(ctx context.Context) error
- func (mem *InMemoryDb) CreateGroup(ctx context.Context, groupName, description string) (*Group, error)
- func (mem *InMemoryDb) CreateGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)
- func (mem *InMemoryDb) CreateRole(ctx context.Context, roleName, description string) (*Role, error)
- func (mem *InMemoryDb) CreateUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)
- func (mem *InMemoryDb) CreateUserRecord(ctx context.Context, email, passphrase string) (*User, error)
- func (mem *InMemoryDb) CreateUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)
- func (mem *InMemoryDb) DeleteGroup(ctx context.Context, group *Group) error
- func (mem *InMemoryDb) DeleteGroupRole(ctx context.Context, groupRole *GroupRole) error
- func (mem *InMemoryDb) DeleteGroupRoleByGroup(ctx context.Context, group *Group) error
- func (mem *InMemoryDb) DeleteGroupRoleByRole(ctx context.Context, role *Role) error
- func (mem *InMemoryDb) DeleteRole(ctx context.Context, role *Role) error
- func (mem *InMemoryDb) DeleteUser(ctx context.Context, user *User) error
- func (mem *InMemoryDb) DeleteUserGroup(ctx context.Context, userGroup *UserGroup) error
- func (mem *InMemoryDb) DeleteUserGroupByGroup(ctx context.Context, group *Group) error
- func (mem *InMemoryDb) DeleteUserGroupByUser(ctx context.Context, user *User) error
- func (mem *InMemoryDb) DeleteUserRole(ctx context.Context, userRole *UserRole) error
- func (mem *InMemoryDb) DeleteUserRoleByRole(ctx context.Context, role *Role) error
- func (mem *InMemoryDb) DeleteUserRoleByUser(ctx context.Context, user *User) error
- func (mem *InMemoryDb) DropAllTables(ctx context.Context) error
- func (mem *InMemoryDb) GetGroupByName(ctx context.Context, groupName string) (*Group, error)
- func (mem *InMemoryDb) GetGroupByRecID(ctx context.Context, recID string) (*Group, error)
- func (mem *InMemoryDb) GetGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)
- func (mem *InMemoryDb) GetRoleByName(ctx context.Context, roleName string) (*Role, error)
- func (mem *InMemoryDb) GetRoleByRecID(ctx context.Context, recID string) (*Role, error)
- func (mem *InMemoryDb) GetTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)
- func (mem *InMemoryDb) GetUserBy2FAToken(ctx context.Context, token string) (*User, error)
- func (mem *InMemoryDb) GetUserByEmail(ctx context.Context, email string) (*User, error)
- func (mem *InMemoryDb) GetUserByRecID(ctx context.Context, recID string) (*User, error)
- func (mem *InMemoryDb) GetUserByRecoveryToken(ctx context.Context, token string) (*User, error)
- func (mem *InMemoryDb) GetUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)
- func (mem *InMemoryDb) GetUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)
- func (mem *InMemoryDb) ListAllUserRoles(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)
- func (mem *InMemoryDb) ListGroupRoleByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*Role, *helper.Page, error)
- func (mem *InMemoryDb) ListGroupRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*Group, *helper.Page, error)
- func (mem *InMemoryDb) ListGroups(ctx context.Context, request *helper.PageRequest) ([]*Group, *helper.Page, error)
- func (mem *InMemoryDb) ListRoles(ctx context.Context, request *helper.PageRequest) ([]*Role, *helper.Page, error)
- func (mem *InMemoryDb) ListUser(ctx context.Context, request *helper.PageRequest) ([]*User, *helper.Page, error)
- func (mem *InMemoryDb) ListUserGroupByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*User, *helper.Page, error)
- func (mem *InMemoryDb) ListUserGroupByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Group, *helper.Page, error)
- func (mem *InMemoryDb) ListUserRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*User, *helper.Page, error)
- func (mem *InMemoryDb) ListUserRoleByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)
- func (mem *InMemoryDb) MarkTOTPRecoveryCodeUsed(ctx context.Context, user *User, code string) error
- func (mem *InMemoryDb) RecreateTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)
- func (mem *InMemoryDb) SaveOrUpdate(ctx context.Context, user *User) error
- func (mem *InMemoryDb) SaveOrUpdateGroup(ctx context.Context, group *Group) error
- func (mem *InMemoryDb) SaveOrUpdateRole(ctx context.Context, role *Role) error
- type MySQLDB
- func (db *MySQLDB) Count(ctx context.Context) (int, error)
- func (db *MySQLDB) CreateAllTable(ctx context.Context) error
- func (db *MySQLDB) CreateGroup(ctx context.Context, groupName, description string) (*Group, error)
- func (db *MySQLDB) CreateGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)
- func (db *MySQLDB) CreateRole(ctx context.Context, roleName, description string) (*Role, error)
- func (db *MySQLDB) CreateUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)
- func (db *MySQLDB) CreateUserRecord(ctx context.Context, email, passphrase string) (*User, error)
- func (db *MySQLDB) CreateUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)
- func (db *MySQLDB) DeleteGroup(ctx context.Context, group *Group) error
- func (db *MySQLDB) DeleteGroupRole(ctx context.Context, groupRole *GroupRole) error
- func (db *MySQLDB) DeleteGroupRoleByGroup(ctx context.Context, group *Group) error
- func (db *MySQLDB) DeleteGroupRoleByRole(ctx context.Context, role *Role) error
- func (db *MySQLDB) DeleteRole(ctx context.Context, role *Role) error
- func (db *MySQLDB) DeleteUser(ctx context.Context, user *User) error
- func (db *MySQLDB) DeleteUserGroup(ctx context.Context, userGroup *UserGroup) error
- func (db *MySQLDB) DeleteUserGroupByGroup(ctx context.Context, group *Group) error
- func (db *MySQLDB) DeleteUserGroupByUser(ctx context.Context, user *User) error
- func (db *MySQLDB) DeleteUserRole(ctx context.Context, userRole *UserRole) error
- func (db *MySQLDB) DeleteUserRoleByRole(ctx context.Context, role *Role) error
- func (db *MySQLDB) DeleteUserRoleByUser(ctx context.Context, user *User) error
- func (db *MySQLDB) DropAllTables(ctx context.Context) error
- func (db *MySQLDB) GetGroupByName(ctx context.Context, groupName string) (*Group, error)
- func (db *MySQLDB) GetGroupByRecID(ctx context.Context, recID string) (*Group, error)
- func (db *MySQLDB) GetGroupRole(ctx context.Context, group *Group, role *Role) (*GroupRole, error)
- func (db *MySQLDB) GetRoleByName(ctx context.Context, roleName string) (*Role, error)
- func (db *MySQLDB) GetRoleByRecID(ctx context.Context, recID string) (*Role, error)
- func (db *MySQLDB) GetTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)
- func (db *MySQLDB) GetUserBy2FAToken(ctx context.Context, token string) (*User, error)
- func (db *MySQLDB) GetUserByEmail(ctx context.Context, email string) (*User, error)
- func (db *MySQLDB) GetUserByRecID(ctx context.Context, recID string) (*User, error)
- func (db *MySQLDB) GetUserByRecoveryToken(ctx context.Context, token string) (*User, error)
- func (db *MySQLDB) GetUserGroup(ctx context.Context, user *User, group *Group) (*UserGroup, error)
- func (db *MySQLDB) GetUserRole(ctx context.Context, user *User, role *Role) (*UserRole, error)
- func (db *MySQLDB) InitDB(ctx context.Context) error
- func (db *MySQLDB) IsGroupRecIDExist(ctx context.Context, recID string) (bool, error)
- func (db *MySQLDB) IsRoleRecIDExist(ctx context.Context, recID string) (bool, error)
- func (db *MySQLDB) IsUserRecIDExist(ctx context.Context, recID string) (bool, error)
- func (db *MySQLDB) ListAllUserRoles(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)
- func (db *MySQLDB) ListGroupRoleByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*Role, *helper.Page, error)
- func (db *MySQLDB) ListGroupRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*Group, *helper.Page, error)
- func (db *MySQLDB) ListGroups(ctx context.Context, request *helper.PageRequest) ([]*Group, *helper.Page, error)
- func (db *MySQLDB) ListRoles(ctx context.Context, request *helper.PageRequest) ([]*Role, *helper.Page, error)
- func (db *MySQLDB) ListUser(ctx context.Context, request *helper.PageRequest) ([]*User, *helper.Page, error)
- func (db *MySQLDB) ListUserGroupByGroup(ctx context.Context, group *Group, request *helper.PageRequest) ([]*User, *helper.Page, error)
- func (db *MySQLDB) ListUserGroupByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Group, *helper.Page, error)
- func (db *MySQLDB) ListUserRoleByRole(ctx context.Context, role *Role, request *helper.PageRequest) ([]*User, *helper.Page, error)
- func (db *MySQLDB) ListUserRoleByUser(ctx context.Context, user *User, request *helper.PageRequest) ([]*Role, *helper.Page, error)
- func (db *MySQLDB) MarkTOTPRecoveryCodeUsed(ctx context.Context, user *User, code string) error
- func (db *MySQLDB) RecreateTOTPRecoveryCodes(ctx context.Context, user *User) ([]string, error)
- func (db *MySQLDB) SaveOrUpdate(ctx context.Context, user *User) error
- func (db *MySQLDB) SaveOrUpdateGroup(ctx context.Context, group *Group) error
- func (db *MySQLDB) SaveOrUpdateRole(ctx context.Context, role *Role) error
- type Recipients
- type Role
- type RoleRepository
- type SendGridSender
- type SendMailSender
- type TOTPRecoveryCode
- type User
- type UserGroup
- type UserGroupRepository
- type UserRepository
- type UserRole
- type UserRoleRepository
Constants ¶
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 DummyMailSender ¶
type DummyMailSender struct {
LastSentMail *DummyMail
}
DummyMailSender a dummy email sender. It does not send any email.
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 ¶
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 ¶
GetGroupByName return a group record
func (*InMemoryDb) GetGroupByRecID ¶
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 ¶
GetRoleByName return a role record
func (*InMemoryDb) GetRoleByRecID ¶
GetRoleByRecID get a specific role by its recID
func (*InMemoryDb) GetTOTPRecoveryCodes ¶
GetTOTPRecoveryCodes retrieves all valid/not used TOTP recovery codes.
func (*InMemoryDb) GetUserBy2FAToken ¶
GetUserBy2FAToken fetch user by 2fa token
func (*InMemoryDb) GetUserByEmail ¶
GetUserByEmail return user with specified Email
func (*InMemoryDb) GetUserByRecID ¶
GetUserByRecID returns user with specified recID
func (*InMemoryDb) GetUserByRecoveryToken ¶
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 ¶
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 ¶
MarkTOTPRecoveryCodeUsed will mark the specific recovery code as used and thus can not be used anymore.
func (*InMemoryDb) RecreateTOTPRecoveryCodes ¶
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) CreateAllTable ¶
CreateAllTable creates all table used by Hansip
func (*MySQLDB) CreateGroup ¶
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 ¶
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 ¶
CreateUserRecord create a new user
func (*MySQLDB) CreateUserRole ¶
CreateUserRole assign a role to a user.
func (*MySQLDB) DeleteGroup ¶
DeleteGroup delete one speciffic group
func (*MySQLDB) DeleteGroupRole ¶
DeleteGroupRole delete a group-role relation
func (*MySQLDB) DeleteGroupRoleByGroup ¶
DeleteGroupRoleByGroup deletes group-role relation by the group
func (*MySQLDB) DeleteGroupRoleByRole ¶
DeleteGroupRoleByRole deletes grou[-role relation by the role
func (*MySQLDB) DeleteRole ¶
DeleteRole delete a specific role from this server
func (*MySQLDB) DeleteUser ¶
DeleteUser delete a user
func (*MySQLDB) DeleteUserGroup ¶
DeleteUserGroup will delete a user-group
func (*MySQLDB) DeleteUserGroupByGroup ¶
DeleteUserGroupByGroup will delete user-group relation by a group
func (*MySQLDB) DeleteUserGroupByUser ¶
DeleteUserGroupByUser will delete a user-group relation by a user
func (*MySQLDB) DeleteUserRole ¶
DeleteUserRole remove a role from user's assigment
func (*MySQLDB) DeleteUserRoleByRole ¶
DeleteUserRoleByRole remove all user-role assigment to a role
func (*MySQLDB) DeleteUserRoleByUser ¶
DeleteUserRoleByUser remove ALL role assigment of a user
func (*MySQLDB) DropAllTables ¶
DropAllTables will drop all tables used by Hansip
func (*MySQLDB) GetGroupByName ¶
func (*MySQLDB) GetGroupByRecID ¶
GetGroupByRecID return a Group data by its RedID
func (*MySQLDB) GetGroupRole ¶
GetGroupRole get GroupRole relation
func (*MySQLDB) GetRoleByName ¶
GetRoleByName return a role record
func (*MySQLDB) GetRoleByRecID ¶
GetRoleByRecID return a role with speciffic recID
func (*MySQLDB) GetTOTPRecoveryCodes ¶
GetTOTPRecoveryCodes retrieves all valid/not used TOTP recovery codes.
func (*MySQLDB) GetUserBy2FAToken ¶
GetUserBy2FAToken get a user by its 2FA token
func (*MySQLDB) GetUserByEmail ¶
GetUserByEmail get user record by its email address
func (*MySQLDB) GetUserByRecID ¶
GetUserByRecID get user data by its RecID
func (*MySQLDB) GetUserByRecoveryToken ¶
GetUserByRecoveryToken get a user by its recovery token
func (*MySQLDB) GetUserGroup ¶
GetUserGroup list all user-group relation
func (*MySQLDB) GetUserRole ¶
GetUserRole return user's assigned roles
func (*MySQLDB) IsGroupRecIDExist ¶
IsGroupRecIDExist check if a speciffic group recId is exist in database
func (*MySQLDB) IsRoleRecIDExist ¶
IsRoleRecIDExist check if a speciffic role recId is exist in database
func (*MySQLDB) IsUserRecIDExist ¶
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 ¶
MarkTOTPRecoveryCodeUsed will mark the specific recovery code as used and thus can not be used anymore.
func (*MySQLDB) RecreateTOTPRecoveryCodes ¶
RecreateTOTPRecoveryCodes recreates 16 new recovery codes.
func (*MySQLDB) SaveOrUpdate ¶
SaveOrUpdate save or update a user data
func (*MySQLDB) SaveOrUpdateGroup ¶
SaveOrUpdateGroup delete one specific group
type Recipients ¶
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.
type SendMailSender ¶
SendMailSender send mail implementation 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