role

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AdminRoleName 管理员角色名称, 系统初始化时创建
	AdminRoleName = "admin"
	// VisitorRoleName 访客角色名称, 系统初始化时创建
	VisitorRoleName = "visitor"
)
View Source
const (
	// MaxPermissionCount 一个角色最多可以容纳的权限条数
	MaxPermissionCount = 500
)

Variables

View Source
var (
	RoleType_name = map[int32]string{
		0: "NULL",
		1: "BUILDIN",
		2: "GLOBAL",
		3: "CUSTOM",
	}
	RoleType_value = map[string]int32{
		"NULL":    0,
		"BUILDIN": 1,
		"GLOBAL":  2,
		"CUSTOM":  3,
	}
)

Enum value maps for RoleType.

View Source
var (
	EffectType_name = map[int32]string{
		0: "ALLOW",
		1: "DENY",
	}
	EffectType_value = map[string]int32{
		"ALLOW": 0,
		"DENY":  1,
	}
)

Enum value maps for EffectType.

View Source
var File_pkg_role_pb_enum_proto protoreflect.FileDescriptor
View Source
var File_pkg_role_pb_request_proto protoreflect.FileDescriptor
View Source
var File_pkg_role_pb_role_proto protoreflect.FileDescriptor
View Source
var File_pkg_role_pb_service_proto protoreflect.FileDescriptor

Functions

func HttpEntry added in v0.2.0

func HttpEntry() *http.EntrySet

HttpEntry todo

func RegisterRoleServiceServer added in v0.2.0

func RegisterRoleServiceServer(s *grpc.Server, srv RoleServiceServer)

Types

type CreateRoleRequest

type CreateRoleRequest struct {

	// 角色类型
	Type RoleType `protobuf:"varint,1,opt,name=type,proto3,enum=keyauth.role.RoleType" json:"type" bson:"type"`
	// 应用名称
	Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name" bson:"name" validate:"required,lte=30"`
	// 应用简单的描述
	Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description" bson:"description" validate:"lte=400"`
	// 读权限
	Permissions []*Permission `protobuf:"bytes,4,rep,name=permissions,proto3" json:"permissions" bson:"permissions"`
	// contains filtered or unexported fields
}

CreateRoleRequest 创建应用请求

func NewCreateRoleRequest

func NewCreateRoleRequest() *CreateRoleRequest

NewCreateRoleRequest 实例化请求

func (*CreateRoleRequest) Descriptor deprecated added in v0.2.0

func (*CreateRoleRequest) Descriptor() ([]byte, []int)

Deprecated: Use CreateRoleRequest.ProtoReflect.Descriptor instead.

func (*CreateRoleRequest) GetDescription added in v0.2.0

func (x *CreateRoleRequest) GetDescription() string

func (*CreateRoleRequest) GetName added in v0.2.0

func (x *CreateRoleRequest) GetName() string

func (*CreateRoleRequest) GetPermissions added in v0.2.0

func (x *CreateRoleRequest) GetPermissions() []*Permission

func (*CreateRoleRequest) GetType added in v0.2.0

func (x *CreateRoleRequest) GetType() RoleType

func (*CreateRoleRequest) IsCumstomType added in v0.2.0

func (req *CreateRoleRequest) IsCumstomType() bool

IsCumstomType todo

func (*CreateRoleRequest) ProtoMessage added in v0.2.0

func (*CreateRoleRequest) ProtoMessage()

func (*CreateRoleRequest) ProtoReflect added in v0.2.0

func (x *CreateRoleRequest) ProtoReflect() protoreflect.Message

func (*CreateRoleRequest) Reset added in v0.2.0

func (x *CreateRoleRequest) Reset()

func (*CreateRoleRequest) String added in v0.2.0

func (x *CreateRoleRequest) String() string

func (*CreateRoleRequest) Validate

func (req *CreateRoleRequest) Validate() error

Validate 请求校验

type DeleteRoleRequest added in v0.2.0

type DeleteRoleRequest struct {
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" validate:"required,lte=64"`
	// contains filtered or unexported fields
}

DeleteRoleRequest role删除

func (*DeleteRoleRequest) Descriptor deprecated added in v0.2.0

func (*DeleteRoleRequest) Descriptor() ([]byte, []int)

Deprecated: Use DeleteRoleRequest.ProtoReflect.Descriptor instead.

func (*DeleteRoleRequest) GetId added in v0.2.0

func (x *DeleteRoleRequest) GetId() string

func (*DeleteRoleRequest) ProtoMessage added in v0.2.0

func (*DeleteRoleRequest) ProtoMessage()

func (*DeleteRoleRequest) ProtoReflect added in v0.2.0

func (x *DeleteRoleRequest) ProtoReflect() protoreflect.Message

func (*DeleteRoleRequest) Reset added in v0.2.0

func (x *DeleteRoleRequest) Reset()

func (*DeleteRoleRequest) String added in v0.2.0

func (x *DeleteRoleRequest) String() string

type DescribeRoleRequest

type DescribeRoleRequest struct {
	Id              string   `protobuf:"bytes,1,opt,name=id,proto3" json:"id"`
	Name            string   `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty" validate:"required,lte=64"`
	WithPermissions bool     `protobuf:"varint,3,opt,name=with_permissions,json=withPermissions,proto3" json:"with_permissions" bson:"with_permissions"`
	Type            RoleType `protobuf:"varint,4,opt,name=type,proto3,enum=keyauth.role.RoleType" json:"type" bson:"type"`
	// contains filtered or unexported fields
}

DescribeRoleRequest role详情

func NewDescribeRoleRequestWithID added in v0.2.0

func NewDescribeRoleRequestWithID(id string) *DescribeRoleRequest

NewDescribeRoleRequestWithID todo

func NewDescribeRoleRequestWithName added in v0.2.0

func NewDescribeRoleRequestWithName(name string) *DescribeRoleRequest

NewDescribeRoleRequestWithName todo

func (*DescribeRoleRequest) Descriptor deprecated added in v0.2.0

func (*DescribeRoleRequest) Descriptor() ([]byte, []int)

Deprecated: Use DescribeRoleRequest.ProtoReflect.Descriptor instead.

func (*DescribeRoleRequest) GetId added in v0.2.0

func (x *DescribeRoleRequest) GetId() string

func (*DescribeRoleRequest) GetName added in v0.2.0

func (x *DescribeRoleRequest) GetName() string

func (*DescribeRoleRequest) GetType added in v0.2.0

func (x *DescribeRoleRequest) GetType() RoleType

func (*DescribeRoleRequest) GetWithPermissions added in v0.2.0

func (x *DescribeRoleRequest) GetWithPermissions() bool

func (*DescribeRoleRequest) ProtoMessage added in v0.2.0

func (*DescribeRoleRequest) ProtoMessage()

func (*DescribeRoleRequest) ProtoReflect added in v0.2.0

func (x *DescribeRoleRequest) ProtoReflect() protoreflect.Message

func (*DescribeRoleRequest) Reset added in v0.2.0

func (x *DescribeRoleRequest) Reset()

func (*DescribeRoleRequest) String added in v0.2.0

func (x *DescribeRoleRequest) String() string

func (*DescribeRoleRequest) Validate added in v0.2.0

func (req *DescribeRoleRequest) Validate() error

Validate todo

type EffectType

type EffectType int32

EffectType 授权效力包括两种:允许(Allow)和拒绝(Deny)

const (
	// 允许访问
	EffectType_ALLOW EffectType = 0
	// 拒绝访问
	EffectType_DENY EffectType = 1
)

func ParseEffectTypeFromString added in v0.2.0

func ParseEffectTypeFromString(str string) (EffectType, error)

ParseEffectTypeFromString Parse EffectType from string

func (EffectType) Descriptor added in v0.2.0

func (EffectType) Descriptor() protoreflect.EnumDescriptor

func (EffectType) Enum added in v0.2.0

func (x EffectType) Enum() *EffectType

func (EffectType) EnumDescriptor deprecated added in v0.2.0

func (EffectType) EnumDescriptor() ([]byte, []int)

Deprecated: Use EffectType.Descriptor instead.

func (EffectType) Equal added in v0.2.0

func (t EffectType) Equal(target EffectType) bool

Equal type compare

func (EffectType) IsIn added in v0.2.0

func (t EffectType) IsIn(targets ...EffectType) bool

IsIn todo

func (EffectType) MarshalJSON

func (t EffectType) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (EffectType) Number added in v0.2.0

func (x EffectType) Number() protoreflect.EnumNumber

func (EffectType) String

func (x EffectType) String() string

func (EffectType) Type added in v0.2.0

func (*EffectType) UnmarshalJSON

func (t *EffectType) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type Permission

type Permission struct {

	// 效力
	Effect EffectType `protobuf:"varint,1,opt,name=effect,proto3,enum=keyauth.role.EffectType" json:"effect" bson:"effect"`
	// 服务ID
	ServiceId string `protobuf:"bytes,2,opt,name=service_id,json=serviceId,proto3" json:"service_id" bson:"service_id"`
	// 资源列表
	ResourceName string `protobuf:"bytes,3,opt,name=resource_name,json=resourceName,proto3" json:"resource_name" bson:"resource_name"`
	// 维度
	LabelKey string `protobuf:"bytes,4,opt,name=label_key,json=labelKey,proto3" json:"label_key" bson:"label_key"`
	// 适配所有值
	MatchAll bool `protobuf:"varint,5,opt,name=match_all,json=matchAll,proto3" json:"match_all" bson:"match_all"`
	// 标识值
	LabelValues []string `protobuf:"bytes,6,rep,name=label_values,json=labelValues,proto3" json:"label_values" bson:"label_values"`
	// contains filtered or unexported fields
}

Permission 权限

func NewDefaultPermission

func NewDefaultPermission() *Permission

NewDefaultPermission todo

func (*Permission) Descriptor deprecated added in v0.2.0

func (*Permission) Descriptor() ([]byte, []int)

Deprecated: Use Permission.ProtoReflect.Descriptor instead.

func (*Permission) GetEffect added in v0.2.0

func (x *Permission) GetEffect() EffectType

func (*Permission) GetLabelKey added in v0.2.0

func (x *Permission) GetLabelKey() string

func (*Permission) GetLabelValues added in v0.2.0

func (x *Permission) GetLabelValues() []string

func (*Permission) GetMatchAll added in v0.2.0

func (x *Permission) GetMatchAll() bool

func (*Permission) GetResourceName added in v0.2.0

func (x *Permission) GetResourceName() string

func (*Permission) GetServiceId added in v0.2.0

func (x *Permission) GetServiceId() string

func (*Permission) ID

func (p *Permission) ID(namespace string) string

ID 计算唯一ID

func (*Permission) MatchLabel added in v0.2.0

func (p *Permission) MatchLabel(label map[string]string) bool

MatchLabel 匹配Label

func (*Permission) MatchResource added in v0.2.0

func (p *Permission) MatchResource(serviceID, resourceName string) bool

MatchResource 检测资源是否匹配

func (*Permission) ProtoMessage added in v0.2.0

func (*Permission) ProtoMessage()

func (*Permission) ProtoReflect added in v0.2.0

func (x *Permission) ProtoReflect() protoreflect.Message

func (*Permission) Reset added in v0.2.0

func (x *Permission) Reset()

func (*Permission) String added in v0.2.0

func (x *Permission) String() string

func (*Permission) Validate added in v0.2.0

func (p *Permission) Validate() error

Validate todo

type PermissionSet

type PermissionSet struct {
	Total int64         `protobuf:"varint,1,opt,name=total,proto3" json:"total" bson:"total"`
	Items []*Permission `protobuf:"bytes,2,rep,name=items,proto3" json:"items" bson:"items"`
	// contains filtered or unexported fields
}

PermissionSet 用户列表

func NewPermissionSet added in v0.2.0

func NewPermissionSet() *PermissionSet

NewPermissionSet todo

func (*PermissionSet) Add

func (s *PermissionSet) Add(items ...*Permission)

Add todo

func (*PermissionSet) Descriptor deprecated added in v0.2.0

func (*PermissionSet) Descriptor() ([]byte, []int)

Deprecated: Use PermissionSet.ProtoReflect.Descriptor instead.

func (*PermissionSet) GetItems added in v0.2.0

func (x *PermissionSet) GetItems() []*Permission

func (*PermissionSet) GetTotal added in v0.2.0

func (x *PermissionSet) GetTotal() int64

func (*PermissionSet) ProtoMessage added in v0.2.0

func (*PermissionSet) ProtoMessage()

func (*PermissionSet) ProtoReflect added in v0.2.0

func (x *PermissionSet) ProtoReflect() protoreflect.Message

func (*PermissionSet) Reset added in v0.2.0

func (x *PermissionSet) Reset()

func (*PermissionSet) String added in v0.2.0

func (x *PermissionSet) String() string

type QueryRoleRequest

type QueryRoleRequest struct {
	Page            *page.PageRequest `protobuf:"bytes,1,opt,name=page,proto3" json:"page" bson:"page"`
	Type            RoleType          `protobuf:"varint,2,opt,name=type,proto3,enum=keyauth.role.RoleType" json:"type" bson:"type"`
	WithPermissions bool              `protobuf:"varint,3,opt,name=with_permissions,json=withPermissions,proto3" json:"with_permissions" bson:"with_permissions"`
	// contains filtered or unexported fields
}

QueryRoleRequest 列表查询

func NewQueryRoleRequest

func NewQueryRoleRequest(pageReq *request.PageRequest) *QueryRoleRequest

NewQueryRoleRequest 列表查询请求

func NewQueryRoleRequestFromHTTP added in v0.2.0

func NewQueryRoleRequestFromHTTP(r *http.Request) *QueryRoleRequest

NewQueryRoleRequestFromHTTP 列表查询请求

func (*QueryRoleRequest) Descriptor deprecated added in v0.2.0

func (*QueryRoleRequest) Descriptor() ([]byte, []int)

Deprecated: Use QueryRoleRequest.ProtoReflect.Descriptor instead.

func (*QueryRoleRequest) GetPage added in v0.2.0

func (x *QueryRoleRequest) GetPage() *page.PageRequest

func (*QueryRoleRequest) GetType added in v0.2.0

func (x *QueryRoleRequest) GetType() RoleType

func (*QueryRoleRequest) GetWithPermissions added in v0.2.0

func (x *QueryRoleRequest) GetWithPermissions() bool

func (*QueryRoleRequest) ProtoMessage added in v0.2.0

func (*QueryRoleRequest) ProtoMessage()

func (*QueryRoleRequest) ProtoReflect added in v0.2.0

func (x *QueryRoleRequest) ProtoReflect() protoreflect.Message

func (*QueryRoleRequest) Reset added in v0.2.0

func (x *QueryRoleRequest) Reset()

func (*QueryRoleRequest) String added in v0.2.0

func (x *QueryRoleRequest) String() string

func (*QueryRoleRequest) Validate added in v0.2.0

func (req *QueryRoleRequest) Validate() error

Validate todo

type Role

type Role struct {

	// 角色ID
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"`
	// 创建时间`
	CreateAt int64 `protobuf:"varint,2,opt,name=create_at,json=createAt,proto3" json:"create_at,omitempty" bson:"create_at"`
	// 更新时间
	UpdateAt int64 `protobuf:"varint,3,opt,name=update_at,json=updateAt,proto3" json:"update_at,omitempty" bson:"update_at"`
	// 角色所属域
	Domain string `protobuf:"bytes,4,opt,name=domain,proto3" json:"domain,omitempty" bson:"domain"`
	// 创建人
	Creater string `protobuf:"bytes,5,opt,name=creater,proto3" json:"creater" bson:"creater"`
	// 角色类型
	Type RoleType `protobuf:"varint,6,opt,name=type,proto3,enum=keyauth.role.RoleType" json:"type" bson:"type"`
	// 应用名称
	Name string `protobuf:"bytes,7,opt,name=name,proto3" json:"name,omitempty" bson:"name" validate:"required,lte=30"`
	// 应用简单的描述
	Description string `protobuf:"bytes,8,opt,name=description,proto3" json:"description,omitempty" bson:"description" validate:"lte=400"`
	// 读权限
	Permissions []*Permission `protobuf:"bytes,9,rep,name=permissions,proto3" json:"permissions,omitempty" bson:"permissions"`
	// contains filtered or unexported fields
}

Role is rbac's role

func New

func New(tk *token.Token, req *CreateRoleRequest) (*Role, error)

New 新创建一个Role

func NewDefaultRole

func NewDefaultRole() *Role

NewDefaultRole 默认实例

func (*Role) CheckPermission

func (r *Role) CheckPermission() error

CheckPermission 检测该角色是否具有该权限

func (*Role) Descriptor deprecated added in v0.2.0

func (*Role) Descriptor() ([]byte, []int)

Deprecated: Use Role.ProtoReflect.Descriptor instead.

func (*Role) GetCreateAt added in v0.2.0

func (x *Role) GetCreateAt() int64

func (*Role) GetCreater added in v0.2.0

func (x *Role) GetCreater() string

func (*Role) GetDescription added in v0.2.0

func (x *Role) GetDescription() string

func (*Role) GetDomain added in v0.2.0

func (x *Role) GetDomain() string

func (*Role) GetId added in v0.2.0

func (x *Role) GetId() string

func (*Role) GetName added in v0.2.0

func (x *Role) GetName() string

func (*Role) GetPermissions added in v0.2.0

func (x *Role) GetPermissions() []*Permission

func (*Role) GetType added in v0.2.0

func (x *Role) GetType() RoleType

func (*Role) GetUpdateAt added in v0.2.0

func (x *Role) GetUpdateAt() int64

func (*Role) HasPermission added in v0.2.0

func (r *Role) HasPermission(ep *endpoint.Endpoint) (*Permission, bool, error)

HasPermission 权限判断

func (*Role) ProtoMessage added in v0.2.0

func (*Role) ProtoMessage()

func (*Role) ProtoReflect added in v0.2.0

func (x *Role) ProtoReflect() protoreflect.Message

func (*Role) Reset added in v0.2.0

func (x *Role) Reset()

func (*Role) String added in v0.2.0

func (x *Role) String() string

type RoleServiceClient added in v0.2.0

type RoleServiceClient interface {
	CreateRole(ctx context.Context, in *CreateRoleRequest, opts ...grpc.CallOption) (*Role, error)
	QueryRole(ctx context.Context, in *QueryRoleRequest, opts ...grpc.CallOption) (*Set, error)
	DescribeRole(ctx context.Context, in *DescribeRoleRequest, opts ...grpc.CallOption) (*Role, error)
	DeleteRole(ctx context.Context, in *DeleteRoleRequest, opts ...grpc.CallOption) (*Role, error)
}

RoleServiceClient is the client API for RoleService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewRoleServiceClient added in v0.2.0

func NewRoleServiceClient(cc grpc.ClientConnInterface) RoleServiceClient

type RoleServiceServer added in v0.2.0

type RoleServiceServer interface {
	CreateRole(context.Context, *CreateRoleRequest) (*Role, error)
	QueryRole(context.Context, *QueryRoleRequest) (*Set, error)
	DescribeRole(context.Context, *DescribeRoleRequest) (*Role, error)
	DeleteRole(context.Context, *DeleteRoleRequest) (*Role, error)
	// contains filtered or unexported methods
}

RoleServiceServer is the server API for RoleService service. All implementations must embed UnimplementedRoleServiceServer for forward compatibility

type RoleType added in v0.2.0

type RoleType int32

RoleType 角色

const (
	RoleType_NULL RoleType = 0
	// 内建角色, 系统初始时创建
	RoleType_BUILDIN RoleType = 1
	// 管理员创建的一些角色, 全局可用
	RoleType_GLOBAL RoleType = 2
	// 用户自定义的角色, 仅域内可见
	RoleType_CUSTOM RoleType = 3
)

func ParseRoleTypeFromString added in v0.2.0

func ParseRoleTypeFromString(str string) (RoleType, error)

ParseRoleTypeFromString Parse RoleType from string

func (RoleType) Descriptor added in v0.2.0

func (RoleType) Descriptor() protoreflect.EnumDescriptor

func (RoleType) Enum added in v0.2.0

func (x RoleType) Enum() *RoleType

func (RoleType) EnumDescriptor deprecated added in v0.2.0

func (RoleType) EnumDescriptor() ([]byte, []int)

Deprecated: Use RoleType.Descriptor instead.

func (RoleType) Equal added in v0.2.0

func (t RoleType) Equal(target RoleType) bool

Equal type compare

func (RoleType) IsIn added in v0.2.0

func (t RoleType) IsIn(targets ...RoleType) bool

IsIn todo

func (RoleType) MarshalJSON added in v0.2.0

func (t RoleType) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (RoleType) Number added in v0.2.0

func (x RoleType) Number() protoreflect.EnumNumber

func (RoleType) String added in v0.2.0

func (x RoleType) String() string

func (RoleType) Type added in v0.2.0

func (*RoleType) UnmarshalJSON added in v0.2.0

func (t *RoleType) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type Set

type Set struct {
	Total int64   `protobuf:"varint,1,opt,name=total,proto3" json:"total" bson:"total"`
	Items []*Role `protobuf:"bytes,2,rep,name=items,proto3" json:"items" bson:"items"`
	// contains filtered or unexported fields
}

func NewRoleSet

func NewRoleSet() *Set

NewRoleSet 实例化make

func (*Set) Add

func (s *Set) Add(item *Role)

Add todo

func (*Set) Descriptor deprecated added in v0.2.0

func (*Set) Descriptor() ([]byte, []int)

Deprecated: Use Set.ProtoReflect.Descriptor instead.

func (*Set) GetItems added in v0.2.0

func (x *Set) GetItems() []*Role

func (*Set) GetTotal added in v0.2.0

func (x *Set) GetTotal() int64

func (*Set) HasPermission added in v0.2.0

func (s *Set) HasPermission(ep *endpoint.Endpoint) (*Permission, bool, error)

HasPermission todo

func (*Set) Permissions added in v0.2.0

func (s *Set) Permissions() *PermissionSet

Permissions todo

func (*Set) ProtoMessage added in v0.2.0

func (*Set) ProtoMessage()

func (*Set) ProtoReflect added in v0.2.0

func (x *Set) ProtoReflect() protoreflect.Message

func (*Set) Reset added in v0.2.0

func (x *Set) Reset()

func (*Set) String added in v0.2.0

func (x *Set) String() string

type UnimplementedRoleServiceServer added in v0.2.0

type UnimplementedRoleServiceServer struct {
}

UnimplementedRoleServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedRoleServiceServer) CreateRole added in v0.2.0

func (UnimplementedRoleServiceServer) DeleteRole added in v0.2.0

func (UnimplementedRoleServiceServer) DescribeRole added in v0.2.0

func (UnimplementedRoleServiceServer) QueryRole added in v0.2.0

type UnsafeRoleServiceServer added in v0.2.0

type UnsafeRoleServiceServer interface {
	// contains filtered or unexported methods
}

UnsafeRoleServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to RoleServiceServer will result in compilation errors.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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