configs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 内置权限
	AdminGrantAll    = "all"
	AdminGrantProxy  = "proxy"
	AdminGrantQ      = "q"
	AdminGrantApi    = "api"
	AdminGrantLog    = "log"
	AdminGrantAgent  = "agent"
	AdminGrantPlugin = "plugin"
	AdminGrantTeam   = "team"
)

Variables

This section is empty.

Functions

func PasswordEncryptTypes

func PasswordEncryptTypes() []maps.Map

密码加密方式列表

Types

type AdminConfig

type AdminConfig struct {
	// 安全设置
	Security *AdminSecurity `yaml:"security" json:"security"`

	// 角色
	Roles []*AdminRole `yaml:"roles" json:"roles"`

	// 权限
	Grant []*AdminGrant `yaml:"grant" json:"grant"`

	// 用户
	Users []*AdminUser `yaml:"users" json:"users"`
}

管理员配置

func SharedAdminConfig

func SharedAdminConfig() *AdminConfig

读取全局的管理员配置

func (*AdminConfig) AddGrant

func (this *AdminConfig) AddGrant(grant *AdminGrant)

添加授权

func (*AdminConfig) AddRole

func (this *AdminConfig) AddRole(role *AdminRole)

添加新角色

func (*AdminConfig) AddUser

func (this *AdminConfig) AddUser(user *AdminUser)

添加用户

func (*AdminConfig) AllowIP

func (this *AdminConfig) AllowIP(ip string) bool

检查是否允许IP

func (*AdminConfig) ComparePassword

func (this *AdminConfig) ComparePassword(inputPassword, encryptedPassword string) bool

对比密码

func (*AdminConfig) ContainsActiveUser

func (this *AdminConfig) ContainsActiveUser(username string) bool

是否包含某个激活的用户名

func (*AdminConfig) ContainsUser

func (this *AdminConfig) ContainsUser(username string) bool

是否包含某个用户名

func (*AdminConfig) EncryptPassword

func (this *AdminConfig) EncryptPassword(password string) string

加密密码

func (*AdminConfig) FindActiveGrant

func (this *AdminConfig) FindActiveGrant(grantCode string) *AdminGrant

根据代号查找权限

func (*AdminConfig) FindActiveRole

func (this *AdminConfig) FindActiveRole(roleCode string) *AdminRole

根据代号查找激活的角色

func (*AdminConfig) FindActiveUser

func (this *AdminConfig) FindActiveUser(username string) *AdminUser

使用用户名查找激活的用户

func (*AdminConfig) FindAllActiveGrants

func (this *AdminConfig) FindAllActiveGrants() []*AdminGrant

取得所有内置的权限

func (*AdminConfig) FindAllActiveRoles

func (this *AdminConfig) FindAllActiveRoles() []*AdminRole

查找激活的角色

func (*AdminConfig) FindRole

func (this *AdminConfig) FindRole(roleCode string) *AdminRole

根据代号查找角色

func (*AdminConfig) FindUser

func (this *AdminConfig) FindUser(username string) *AdminUser

使用用户名查找用户

func (*AdminConfig) FindUserWithKey

func (this *AdminConfig) FindUserWithKey(key string) *AdminUser

使用Key查找用户

func (*AdminConfig) Reset

func (this *AdminConfig) Reset()

重置状态

func (*AdminConfig) Save

func (this *AdminConfig) Save() error

写回配置文件

func (*AdminConfig) Validate

func (this *AdminConfig) Validate() error

校验

type AdminGrant

type AdminGrant struct {
	Name       string `yaml:"name" json:"name"`
	Code       string `yaml:"code" json:"code"`
	IsDisabled bool   `yaml:"isDisabled" json:"isDisabled"`
}

权限定义

func NewAdminGrant

func NewAdminGrant(name string, code string) *AdminGrant

构造新权限

type AdminRole

type AdminRole struct {
	Name       string   `yaml:"name" json:"name"`             // 名称
	Code       string   `yaml:"code" json:"code"`             // 代号
	Grant      []string `yaml:"grant" json:"grant"`           // 授权
	IsDisabled bool     `yaml:"isDisabled" json:"isDisabled"` // 是否禁用
}

角色定义

func NewAdminRole

func NewAdminRole() *AdminRole

构造新角色

func (*AdminRole) Granted

func (this *AdminRole) Granted(grant string) bool

判断是否授权

type AdminSecurity

type AdminSecurity struct {
	TeaVersion string `yaml:"teaVersion" json:"teaVersion"`

	Allow               []string `yaml:"allow" json:"allow"`                             //支持的IP
	Deny                []string `yaml:"deny" json:"deny"`                               // 拒绝的IP
	Secret              string   `yaml:"secret" json:"secret"`                           // 密钥
	IsDisabled          bool     `yaml:"isDisabled" json:"isDisabled"`                   // 是否禁用
	DirAutoComplete     bool     `yaml:"dirAutoComplete" json:"dirAutoComplete"`         // 是否支持目录自动补全
	LoginURL            string   `yaml:"loginURL" json:"loginURL"`                       // 登录页面的URL
	PasswordEncryptType string   `yaml:"passwordEncryptType" json:"passwordEncryptType"` // 密码加密方式
	// contains filtered or unexported fields
}

安全设置定义

func NewAdminSecurity

func NewAdminSecurity() *AdminSecurity

获取新对象

func (*AdminSecurity) AllowIP

func (this *AdminSecurity) AllowIP(ip string) bool

判断某个IP是否允许访问

func (*AdminSecurity) NewLoginURL

func (this *AdminSecurity) NewLoginURL() string

获取登录URL

func (*AdminSecurity) PasswordEncryptTypeText

func (this *AdminSecurity) PasswordEncryptTypeText() string

获取加密方式文字说明

func (*AdminSecurity) Validate

func (this *AdminSecurity) Validate() error

校验

type AdminUser

type AdminUser struct {
	Username string   `yaml:"username" json:"username"` // 用户名
	Password string   `yaml:"password" json:"password"` // 密码
	Role     []string `yaml:"role" json:"role"`         // 角色
	Key      string   `yaml:"key" json:"key"`           // Key,用来请求API等

	Name      string `yaml:"name" json:"name"`           // 姓名
	Avatar    string `yaml:"avatar" json:"avatar"`       // 头像
	Tel       string `yaml:"tel" json:"tel"`             // 联系电话
	CreatedAt int64  `yaml:"createdAt" json:"createdAt"` // 创建时间
	LoggedAt  int64  `yaml:"loggedAt" json:"loggedAt"`   // 最后登录时间
	LoggedIP  string `yaml:"loggedIP" json:"loggedIP"`   // 最后登录IP

	Grant []string `yaml:"grant" json:"grant"` // 权限,会细化到项目,比如:apis:example.com

	IsDisabled bool `yaml:"isDisabled" json:"isDisabled"` // 是否禁用
	// contains filtered or unexported fields
}

管理员用户

func NewAdminUser

func NewAdminUser() *AdminUser

获取新对象

func (*AdminUser) CountLoginTries

func (this *AdminUser) CountLoginTries() uint

func (*AdminUser) GenerateKey

func (this *AdminUser) GenerateKey() string

生成Key

func (*AdminUser) Granted

func (this *AdminUser) Granted(grant string) bool

判断用户是否已被授权

func (*AdminUser) IncreaseLoginTries

func (this *AdminUser) IncreaseLoginTries()

func (*AdminUser) Reset

func (this *AdminUser) Reset()

重置状态

func (*AdminUser) ResetLoginTries

func (this *AdminUser) ResetLoginTries()

Jump to

Keyboard shortcuts

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