handler

package
v0.0.0-...-a4f8eeb Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPluginNotFound    = tracerr.New("plugin not found")
	ErrPluginIDDuplicate = tracerr.New("plugin ID duplicated")
	ErrPluginInvalid     = tracerr.New("plugin invalid")
	ErrPluginExists      = tracerr.New("plugin already exists")
	ErrPluginIDNotMatch  = tracerr.New("plugin id not match")
	ErrPluginMethod      = tracerr.New("plugin method error")
)
View Source
var ErrUUIDConflict = tracerr.New("uuid conflict")
View Source
var Group = &GroupImpl{}
View Source
var Notification = &NotificationImpl{}
View Source
var Permission = &PermissionImpl{
	cache: new(tpl.SafeMap[uuid.UUID, *PermList]),
}
View Source
var Plugin = &PluginImpl{}
View Source
var Setting = &SettingImpl{
	cache: new(tpl.SafeMap[string, string]),
}
View Source
var User = &UserImpl{}

Functions

func HashPass

func HashPass(pass string) string

HashPass returns hashed password.

func Init

func Init()

Types

type GroupImpl

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

func (*GroupImpl) Count

func (u *GroupImpl) Count(cond *db.Condition) (int64, error)

Count count group by condition.

func (*GroupImpl) Delete

func (u *GroupImpl) Delete(id uuid.UUID) (ok bool, err error)

Delete delete user group data.

Warning: this function will not delete permission.

func (*GroupImpl) DeleteAll

func (u *GroupImpl) DeleteAll() (cnt int64, err error)

DeleteAll delete all user group data.

Warning: this function will not delete permission.

func (*GroupImpl) Get

func (u *GroupImpl) Get(id uuid.UUID) (*db.UserGroup, error)

Get get group by id.

func (*GroupImpl) GetAll

func (u *GroupImpl) GetAll(cond *db.Condition) ([]*db.UserGroup, error)

GetAll get all group by condition.

func (*GroupImpl) GetByName

func (u *GroupImpl) GetByName(name string) (*db.UserGroup, error)

GetByName get group by name.

func (*GroupImpl) GetGroupAllUser

func (u *GroupImpl) GetGroupAllUser(id uuid.UUID) ([]*db.User, error)

GetGroupAllUser get group id all users.

func (*GroupImpl) GetUserAllGroup

func (u *GroupImpl) GetUserAllGroup(id uuid.UUID) ([]*db.UserGroup, error)

GetUserAllGroup get user id all groups.

func (u *GroupImpl) Link(uid []uuid.UUID, gid []uuid.UUID) ([]*db.UserGroupLink, error)

Link link all uid user to all gid group.

Note: For performance reasons, this function will not check whether uid or gid is valid.

func (*GroupImpl) New

func (u *GroupImpl) New(name string, note string) (*db.UserGroup, error)

New create new usergroup.

func (u *GroupImpl) Unlink(uid uuid.UUID, gid uuid.UUID) (int64, error)

Unlink delete user data in user group. When gid is uuid.Nil, delete user in all group. When uid is uuid.Nil, delete group all user.

Warning: this function will not delete permission.

func (*GroupImpl) Update

func (u *GroupImpl) Update(id uuid.UUID, name string, note *string) error

Update update user group infos, properties remain no change if left empty.

func (*GroupImpl) WithTx

func (u *GroupImpl) WithTx(tx *gorm.DB) *GroupImpl

type NotificationHook

type NotificationHook struct{}

func (NotificationHook) Fire

func (h NotificationHook) Fire(e *logrus.Entry) error

func (NotificationHook) Levels

func (h NotificationHook) Levels() []logrus.Level

type NotificationImpl

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

func (*NotificationImpl) Count

func (u *NotificationImpl) Count(cond *db.Condition) (int64, error)

Count count notification by condition.

func (*NotificationImpl) Delete

func (u *NotificationImpl) Delete(id uuid.UUID) (bool, error)

Delete delete notification by id.

func (*NotificationImpl) DeleteAll

func (u *NotificationImpl) DeleteAll() (int64, error)

Delete delete all notification.

func (*NotificationImpl) Get

func (u *NotificationImpl) Get(id uuid.UUID) (*db.Notification, error)

Get get notification by id.

func (*NotificationImpl) GetAll

func (u *NotificationImpl) GetAll(cond *db.Condition) ([]*db.Notification, error)

GetAll get all notification by condition.

func (*NotificationImpl) New

func (s *NotificationImpl) New(level db.NotifyLevel, name string, message string, detail string) error

func (*NotificationImpl) WithTx

func (p *NotificationImpl) WithTx(tx *gorm.DB) *NotificationImpl

type Perm

type Perm struct {
	ID   uuid.UUID
	Name string // filled automatically
	Perm db.UserPerm
}

type PermList

type PermList struct {
	Perm  tpl.SafeMap[uuid.UUID, *Perm]
	Group []uuid.UUID
	Type  PermListType
}

type PermListType

type PermListType int32
const (
	PermListUser PermListType = iota
	PermListGroup
)

type PermissionImpl

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

func (*PermissionImpl) AddToGroup

func (p *PermissionImpl) AddToGroup(gid uuid.UUID, perm []*Perm) (permRet []*db.Permission, err error)

AddToGroup add permission to group gid.

func (*PermissionImpl) DeleteAll

func (p *PermissionImpl) DeleteAll(uid uuid.UUID, gid uuid.UUID) (row int64, err error)

DeleteAll delete all uid or gid permission.

Note: uid or gid is uuid.Nil means not base on this condition. If both uuid.Nil, do nothing. If both given, delete using OR condition.

func (*PermissionImpl) GetAll

func (p *PermissionImpl) GetAll(uid uuid.UUID, gid uuid.UUID, join bool) ([]*db.Permission, error)

GetAll find all permission by condition, if join is true, return records will join PermissionList.

uid and gid should not be both uuid.Nil or both have value, otherwise, nil,nil will be returned

func (*PermissionImpl) GetGroup

func (p *PermissionImpl) GetGroup(id uuid.UUID, force bool) (*PermList, error)

GetGroup get group perm list, if force ignore cache.

func (*PermissionImpl) GetUser

func (p *PermissionImpl) GetUser(id uuid.UUID, force bool) (ret *PermList, err error)

GetUser get user perm list, if force ignore cache.

func (*PermissionImpl) GetUserMerged

func (p *PermissionImpl) GetUserMerged(id uuid.UUID) (map[uuid.UUID]*Perm, error)

GetUserMerged returns merged user permission list.

func (*PermissionImpl) WithTx

func (p *PermissionImpl) WithTx(tx *gorm.DB) *PermissionImpl

type PluginEntry

type PluginEntry struct {
	ID             uuid.UUID `json:"id" yaml:"id"`                         // plugin unique ID
	Name           string    `json:"name" yaml:"name"`                     // plugin name, unique suggested
	Version        string    `json:"version" yaml:"version"`               // plugin version
	SkynetVersion  string    `json:"skynet_version" yaml:"skynet_version"` // compatible skynet version
	CommandUnix    string    `json:"-" yaml:"command_unix"`                // unix execute command
	CommandWindows string    `json:"-" yaml:"command_windows"`             // windows execute command

	Path    string           `json:"path" yaml:"-"`    // runtime relative path
	Enable  bool             `json:"enable" yaml:"-"`  // is plugin enabled
	Message string           `json:"message" yaml:"-"` // plugin message
	Client  *plugin.Client   `json:"-" yaml:"-"`       // go-plugin client
	API     *PluginSkynetAPI `json:"-" yaml:"-"`       // plugin API
}

func (*PluginEntry) KillPlugin

func (p *PluginEntry) KillPlugin()

func (*PluginEntry) StartPlugin

func (p *PluginEntry) StartPlugin() error

type PluginImpl

type PluginImpl struct {
	BaseFolder string
	// contains filtered or unexported fields
}

func (*PluginImpl) CleanSetting

func (p *PluginImpl) CleanSetting()

func (*PluginImpl) Count

func (p *PluginImpl) Count() int

func (*PluginImpl) Disable

func (p *PluginImpl) Disable(id uuid.UUID) error

func (*PluginImpl) Enable

func (p *PluginImpl) Enable(id uuid.UUID) error

func (*PluginImpl) Fini

func (p *PluginImpl) Fini()

func (*PluginImpl) Get

func (p *PluginImpl) Get(id uuid.UUID) *PluginEntry

func (*PluginImpl) GetAll

func (p *PluginImpl) GetAll() []*PluginEntry

func (*PluginImpl) LoadPlugin

func (p *PluginImpl) LoadPlugin(base string) error

type PluginSkynetAPI

type PluginSkynetAPI struct {
	Impl sp.PluginAPI
}

func (*PluginSkynetAPI) Disable

func (p *PluginSkynetAPI) Disable() (*sp.PluginError, error)

func (*PluginSkynetAPI) Enable

func (p *PluginSkynetAPI) Enable() (*sp.PluginError, error)

type SettingImpl

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

func (*SettingImpl) BuildCache

func (s *SettingImpl) BuildCache() error

func (*SettingImpl) Delete

func (s *SettingImpl) Delete(name string) (bool, error)

Delete delete name setting.

func (*SettingImpl) DeleteAll

func (s *SettingImpl) DeleteAll() (int64, error)

DeleteAll delete all settings.

func (*SettingImpl) Get

func (s *SettingImpl) Get(name string) (string, bool)

Get get name setting.

func (*SettingImpl) GetAll

func (s *SettingImpl) GetAll() map[string]string

GetAll return all settings.

Copies are returned, modification will not be saved.

func (*SettingImpl) Set

func (s *SettingImpl) Set(name string, value string) error

Set set setting name with value.

func (*SettingImpl) WithTx

func (p *SettingImpl) WithTx(tx *gorm.DB) *SettingImpl

type UserImpl

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

func (*UserImpl) CheckPass

func (u *UserImpl) CheckPass(user string, pass string) (*db.User, int, error)

CheckPass check whether user and pass match.

If error, return nil,-1,err.

If user not found, return nil,1,nil.

If pass not match, return nil,2,nil.

Return user,0,nil if all match.

func (*UserImpl) Count

func (u *UserImpl) Count(cond *db.Condition) (int64, error)

Count count user by condition.

func (*UserImpl) Delete

func (u *UserImpl) Delete(id uuid.UUID) (ok bool, err error)

Delete delete user data.

Warning: this function will not delete permission or unlink group.

func (*UserImpl) DeleteAll

func (u *UserImpl) DeleteAll() (int64, error)

Delete delete all user data.

Warning: this function will not delete permission or unlink group.

func (*UserImpl) Get

func (u *UserImpl) Get(id uuid.UUID) (*db.User, error)

Get get user by id.

func (*UserImpl) GetAll

func (u *UserImpl) GetAll(cond *db.Condition) ([]*db.User, error)

GetAll get all user by condition.

func (*UserImpl) GetByName

func (u *UserImpl) GetByName(name string) (*db.User, error)

GetByName get user by name.

Return nil,nil when user not found.

func (*UserImpl) Kick

func (u *UserImpl) Kick(id uuid.UUID) error

Kick kick user id login.

func (*UserImpl) New

func (u *UserImpl) New(username string, password string,
	avatar []byte) (user *db.User, newpass string, err error)

New create new user and return created user and created pass, when password is empty, generate random pass, by default no user group will be attached.

func (*UserImpl) Reset

func (u *UserImpl) Reset(id uuid.UUID) (string, error)

Reset reset user password by id, return new password.

Return "",nil when user not found.

func (*UserImpl) Update

func (u *UserImpl) Update(id uuid.UUID, username string, password string,
	avatar []byte, lastTime *time.Time, lastIP string) error

Update update user infos, properties remain no change if left empty.

func (*UserImpl) WithTx

func (u *UserImpl) WithTx(tx *gorm.DB) *UserImpl

Jump to

Keyboard shortcuts

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