policy

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxUserPolicy = 2048
)

Variables

View Source
var (
	PolicyType_name = map[int32]string{
		0: "NULL",
		1: "CUSTOM",
		2: "BUILD_IN",
	}
	PolicyType_value = map[string]int32{
		"NULL":     0,
		"CUSTOM":   1,
		"BUILD_IN": 2,
	}
)

Enum value maps for PolicyType.

View Source
var File_pkg_policy_pb_enum_proto protoreflect.FileDescriptor
View Source
var File_pkg_policy_pb_policy_proto protoreflect.FileDescriptor
View Source
var File_pkg_policy_pb_request_proto protoreflect.FileDescriptor
View Source
var File_pkg_policy_pb_service_proto protoreflect.FileDescriptor
View Source
var PolicyService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "keyauth.policy.PolicyService",
	HandlerType: (*PolicyServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "CreatePolicy",
			Handler:    _PolicyService_CreatePolicy_Handler,
		},
		{
			MethodName: "QueryPolicy",
			Handler:    _PolicyService_QueryPolicy_Handler,
		},
		{
			MethodName: "DescribePolicy",
			Handler:    _PolicyService_DescribePolicy_Handler,
		},
		{
			MethodName: "DeletePolicy",
			Handler:    _PolicyService_DeletePolicy_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "pkg/policy/pb/service.proto",
}

PolicyService_ServiceDesc is the grpc.ServiceDesc for PolicyService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func HttpEntry added in v0.2.0

func HttpEntry() *http.EntrySet

HttpEntry todo

func RegisterPolicyServiceServer added in v0.2.0

func RegisterPolicyServiceServer(s grpc.ServiceRegistrar, srv PolicyServiceServer)

Types

type CreatePolicyRequest

type CreatePolicyRequest struct {

	// 范围
	NamespaceId string `protobuf:"bytes,1,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id" bson:"namespace_id" validate:"lte=120"`
	// 用户
	Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account" bson:"account" validate:"required,lte=120"`
	// 角色名称
	RoleId string `protobuf:"bytes,3,opt,name=role_id,json=roleId,proto3" json:"role_id" bson:"role_id" validate:"required,lte=40"`
	// 范围控制
	Scope string `protobuf:"bytes,4,opt,name=scope,proto3" json:"scope" bson:"scope"`
	// 策略过期时间
	ExpiredTime int64 `protobuf:"varint,5,opt,name=expired_time,json=expiredTime,proto3" json:"expired_time" bson:"expired_time"`
	// 策略的类型
	Type PolicyType `protobuf:"varint,6,opt,name=type,proto3,enum=keyauth.policy.PolicyType" json:"type" bson:"type"`
	// contains filtered or unexported fields
}

CreatePolicyRequest 创建策略的请求

func NewCreatePolicyRequest

func NewCreatePolicyRequest() *CreatePolicyRequest

NewCreatePolicyRequest 请求实例

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

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

Deprecated: Use CreatePolicyRequest.ProtoReflect.Descriptor instead.

func (*CreatePolicyRequest) GetAccount added in v0.2.0

func (x *CreatePolicyRequest) GetAccount() string

func (*CreatePolicyRequest) GetExpiredTime added in v0.2.0

func (x *CreatePolicyRequest) GetExpiredTime() int64

func (*CreatePolicyRequest) GetNamespaceId added in v0.2.0

func (x *CreatePolicyRequest) GetNamespaceId() string

func (*CreatePolicyRequest) GetRoleId added in v0.2.0

func (x *CreatePolicyRequest) GetRoleId() string

func (*CreatePolicyRequest) GetScope added in v0.2.0

func (x *CreatePolicyRequest) GetScope() string

func (*CreatePolicyRequest) GetType added in v0.2.0

func (x *CreatePolicyRequest) GetType() PolicyType

func (*CreatePolicyRequest) ProtoMessage added in v0.2.0

func (*CreatePolicyRequest) ProtoMessage()

func (*CreatePolicyRequest) ProtoReflect added in v0.2.0

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

func (*CreatePolicyRequest) Reset added in v0.2.0

func (x *CreatePolicyRequest) Reset()

func (*CreatePolicyRequest) String added in v0.2.0

func (x *CreatePolicyRequest) String() string

func (*CreatePolicyRequest) Validate

func (req *CreatePolicyRequest) Validate() error

Validate 校验请求合法

type DeletePolicyRequest added in v0.2.0

type DeletePolicyRequest struct {
	Id          string     `protobuf:"bytes,1,opt,name=id,proto3" json:"id"`
	Account     string     `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"`
	RoleId      string     `protobuf:"bytes,3,opt,name=role_id,json=roleId,proto3" json:"role_id,omitempty"`
	NamespaceId string     `protobuf:"bytes,4,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"`
	Type        PolicyType `protobuf:"varint,5,opt,name=type,proto3,enum=keyauth.policy.PolicyType" json:"type,omitempty"`
	Domain      string     `protobuf:"bytes,6,opt,name=domain,proto3" json:"domain"`
	// contains filtered or unexported fields
}

DeletePolicyRequest todo

func NewDeletePolicyRequest added in v0.2.0

func NewDeletePolicyRequest() *DeletePolicyRequest

NewDeletePolicyRequest todo

func NewDeletePolicyRequestWithAccount added in v0.2.0

func NewDeletePolicyRequestWithAccount(account string) *DeletePolicyRequest

NewDeletePolicyRequestWithAccount todo

func NewDeletePolicyRequestWithID added in v0.2.0

func NewDeletePolicyRequestWithID(id string) *DeletePolicyRequest

NewDeletePolicyRequestWithID todo

func NewDeletePolicyRequestWithNamespaceID added in v0.2.0

func NewDeletePolicyRequestWithNamespaceID(namespaceID string) *DeletePolicyRequest

NewDeletePolicyRequestWithNamespaceID todo

func NewDeletePolicyRequestWithRoleID added in v0.2.0

func NewDeletePolicyRequestWithRoleID(roleID string) *DeletePolicyRequest

NewDeletePolicyRequestWithRoleID todo

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

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

Deprecated: Use DeletePolicyRequest.ProtoReflect.Descriptor instead.

func (*DeletePolicyRequest) GetAccount added in v0.2.0

func (x *DeletePolicyRequest) GetAccount() string

func (*DeletePolicyRequest) GetDomain added in v0.5.5

func (x *DeletePolicyRequest) GetDomain() string

func (*DeletePolicyRequest) GetId added in v0.2.0

func (x *DeletePolicyRequest) GetId() string

func (*DeletePolicyRequest) GetNamespaceId added in v0.2.0

func (x *DeletePolicyRequest) GetNamespaceId() string

func (*DeletePolicyRequest) GetRoleId added in v0.2.0

func (x *DeletePolicyRequest) GetRoleId() string

func (*DeletePolicyRequest) GetType added in v0.2.0

func (x *DeletePolicyRequest) GetType() PolicyType

func (*DeletePolicyRequest) ProtoMessage added in v0.2.0

func (*DeletePolicyRequest) ProtoMessage()

func (*DeletePolicyRequest) ProtoReflect added in v0.2.0

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

func (*DeletePolicyRequest) Reset added in v0.2.0

func (x *DeletePolicyRequest) Reset()

func (*DeletePolicyRequest) String added in v0.2.0

func (x *DeletePolicyRequest) String() string

func (*DeletePolicyRequest) Validate added in v0.2.0

func (req *DeletePolicyRequest) Validate() error

Validate todo

type DescribePolicyRequest

type DescribePolicyRequest struct {
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id"`
	// contains filtered or unexported fields
}

DescribePolicyRequest todo

func NewDescriptPolicyRequest added in v0.2.0

func NewDescriptPolicyRequest() *DescribePolicyRequest

NewDescriptPolicyRequest new实例

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

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

Deprecated: Use DescribePolicyRequest.ProtoReflect.Descriptor instead.

func (*DescribePolicyRequest) GetId added in v0.2.0

func (x *DescribePolicyRequest) GetId() string

func (*DescribePolicyRequest) ProtoMessage added in v0.2.0

func (*DescribePolicyRequest) ProtoMessage()

func (*DescribePolicyRequest) ProtoReflect added in v0.2.0

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

func (*DescribePolicyRequest) Reset added in v0.2.0

func (x *DescribePolicyRequest) Reset()

func (*DescribePolicyRequest) String added in v0.2.0

func (x *DescribePolicyRequest) String() string

func (*DescribePolicyRequest) Validate added in v0.2.0

func (req *DescribePolicyRequest) Validate() error

Validate todo

type Policy

type Policy 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" bson:"create_at"`
	// 更新时间
	UpdateAt int64 `protobuf:"varint,3,opt,name=update_at,json=updateAt,proto3" json:"update_at" bson:"update_at"`
	// 策略所属域
	Domain string `protobuf:"bytes,4,opt,name=domain,proto3" json:"domain" bson:"domain"`
	// 创建者ID
	Creater string `protobuf:"bytes,5,opt,name=creater,proto3" json:"creater" bson:"creater"`
	// 用户类型
	UserType types.UserType `protobuf:"varint,6,opt,name=user_type,json=userType,proto3,enum=keyauth.user.UserType" json:"user_type" bson:"user_type"`
	// 范围
	NamespaceId string `protobuf:"bytes,7,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id" bson:"namespace_id"`
	// 用户
	Account string `protobuf:"bytes,8,opt,name=account,proto3" json:"account" bson:"account"`
	// 角色名称
	RoleId string `protobuf:"bytes,9,opt,name=role_id,json=roleId,proto3" json:"role_id" bson:"role_id"`
	// 范围控制
	Scope string `protobuf:"bytes,10,opt,name=scope,proto3" json:"scope" bson:"scope"`
	// 策略过期时间
	ExpiredTime int64 `protobuf:"varint,11,opt,name=expired_time,json=expiredTime,proto3" json:"expired_time" bson:"expired_time"`
	// 策略的类型
	Type PolicyType `protobuf:"varint,12,opt,name=type,proto3,enum=keyauth.policy.PolicyType" json:"type" bson:"type"`
	// 关联的角色对象
	Role *role.Role `protobuf:"bytes,13,opt,name=role,proto3" json:"role,omitempty" bson:"-"`
	// 关联的空间信息
	Namespace *namespace.Namespace `protobuf:"bytes,14,opt,name=namespace,proto3" json:"namespace,omitempty" bson:"-"`
	// contains filtered or unexported fields
}

Policy 权限策略

func New

func New(tk *token.Token, req *CreatePolicyRequest) (*Policy, error)

New 新实例

func NewDefaultPolicy

func NewDefaultPolicy() *Policy

NewDefaultPolicy todo

func (*Policy) CheckDependence added in v0.2.0

CheckDependence todo

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

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

Deprecated: Use Policy.ProtoReflect.Descriptor instead.

func (*Policy) GetAccount added in v0.2.0

func (x *Policy) GetAccount() string

func (*Policy) GetCreateAt added in v0.2.0

func (x *Policy) GetCreateAt() int64

func (*Policy) GetCreater added in v0.2.0

func (x *Policy) GetCreater() string

func (*Policy) GetDomain added in v0.2.0

func (x *Policy) GetDomain() string

func (*Policy) GetExpiredTime added in v0.2.0

func (x *Policy) GetExpiredTime() int64

func (*Policy) GetId added in v0.2.0

func (x *Policy) GetId() string

func (*Policy) GetNamespace added in v0.2.0

func (x *Policy) GetNamespace() *namespace.Namespace

func (*Policy) GetNamespaceId added in v0.2.0

func (x *Policy) GetNamespaceId() string

func (*Policy) GetRole added in v0.2.0

func (x *Policy) GetRole() *role.Role

func (*Policy) GetRoleId added in v0.2.0

func (x *Policy) GetRoleId() string

func (*Policy) GetScope added in v0.2.0

func (x *Policy) GetScope() string

func (*Policy) GetType added in v0.2.0

func (x *Policy) GetType() PolicyType

func (*Policy) GetUpdateAt added in v0.2.0

func (x *Policy) GetUpdateAt() int64

func (*Policy) GetUserType added in v0.2.0

func (x *Policy) GetUserType() types.UserType

func (*Policy) IsAllNamespace added in v0.2.0

func (p *Policy) IsAllNamespace() bool

IsAllNamespace 是否是对账所有namespace的测试

func (*Policy) ProtoMessage added in v0.2.0

func (*Policy) ProtoMessage()

func (*Policy) ProtoReflect added in v0.2.0

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

func (*Policy) Reset added in v0.2.0

func (x *Policy) Reset()

func (*Policy) String added in v0.2.0

func (x *Policy) String() string

type PolicyServiceClient added in v0.2.0

type PolicyServiceClient interface {
	CreatePolicy(ctx context.Context, in *CreatePolicyRequest, opts ...grpc.CallOption) (*Policy, error)
	QueryPolicy(ctx context.Context, in *QueryPolicyRequest, opts ...grpc.CallOption) (*Set, error)
	DescribePolicy(ctx context.Context, in *DescribePolicyRequest, opts ...grpc.CallOption) (*Policy, error)
	DeletePolicy(ctx context.Context, in *DeletePolicyRequest, opts ...grpc.CallOption) (*Policy, error)
}

PolicyServiceClient is the client API for PolicyService 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 NewPolicyServiceClient added in v0.2.0

func NewPolicyServiceClient(cc grpc.ClientConnInterface) PolicyServiceClient

type PolicyServiceServer added in v0.2.0

type PolicyServiceServer interface {
	CreatePolicy(context.Context, *CreatePolicyRequest) (*Policy, error)
	QueryPolicy(context.Context, *QueryPolicyRequest) (*Set, error)
	DescribePolicy(context.Context, *DescribePolicyRequest) (*Policy, error)
	DeletePolicy(context.Context, *DeletePolicyRequest) (*Policy, error)
	// contains filtered or unexported methods
}

PolicyServiceServer is the server API for PolicyService service. All implementations must embed UnimplementedPolicyServiceServer for forward compatibility

type PolicyType added in v0.2.0

type PolicyType int32
const (
	PolicyType_NULL PolicyType = 0
	// CustomPolicy (custom) 用户自己定义的策略
	PolicyType_CUSTOM PolicyType = 1
	// BuildInPolicy (build_in) 系统内部逻辑, 不允许用户看到并修改
	PolicyType_BUILD_IN PolicyType = 2
)

func ParsePolicyTypeFromString added in v0.2.0

func ParsePolicyTypeFromString(str string) (PolicyType, error)

ParsePolicyTypeFromString Parse PolicyType from string

func (PolicyType) Descriptor added in v0.2.0

func (PolicyType) Descriptor() protoreflect.EnumDescriptor

func (PolicyType) Enum added in v0.2.0

func (x PolicyType) Enum() *PolicyType

func (PolicyType) EnumDescriptor deprecated added in v0.2.0

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

Deprecated: Use PolicyType.Descriptor instead.

func (PolicyType) Equal added in v0.2.0

func (t PolicyType) Equal(target PolicyType) bool

Equal type compare

func (PolicyType) IsIn added in v0.2.0

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

IsIn todo

func (PolicyType) MarshalJSON added in v0.2.0

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

MarshalJSON todo

func (PolicyType) Number added in v0.2.0

func (x PolicyType) Number() protoreflect.EnumNumber

func (PolicyType) String added in v0.2.0

func (x PolicyType) String() string

func (PolicyType) Type added in v0.2.0

func (*PolicyType) UnmarshalJSON added in v0.2.0

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

UnmarshalJSON todo

type QueryPolicyRequest

type QueryPolicyRequest struct {
	Page          *page.PageRequest `protobuf:"bytes,1,opt,name=page,proto3" json:"page" bson:"page"`
	Account       string            `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"`
	RoleId        string            `protobuf:"bytes,3,opt,name=role_id,json=roleId,proto3" json:"role_id,omitempty"`
	NamespaceId   string            `protobuf:"bytes,4,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"`
	Type          PolicyType        `protobuf:"varint,5,opt,name=type,proto3,enum=keyauth.policy.PolicyType" json:"type,omitempty"`
	WithRole      bool              `protobuf:"varint,6,opt,name=with_role,json=withRole,proto3" json:"with_role,omitempty"`
	WithNamespace bool              `protobuf:"varint,7,opt,name=with_namespace,json=withNamespace,proto3" json:"with_namespace,omitempty"`
	Domain        string            `protobuf:"bytes,8,opt,name=domain,proto3" json:"domain"`
	// contains filtered or unexported fields
}

QueryPolicyRequest 获取子账号列表

func NewQueryPolicyRequest

func NewQueryPolicyRequest(pageReq *request.PageRequest) *QueryPolicyRequest

NewQueryPolicyRequest 列表查询请求

func NewQueryPolicyRequestFromHTTP added in v0.2.0

func NewQueryPolicyRequestFromHTTP(r *http.Request) *QueryPolicyRequest

NewQueryPolicyRequestFromHTTP 列表查询请求

func (*QueryPolicyRequest) CheckOwner added in v0.3.2

func (req *QueryPolicyRequest) CheckOwner(account string) bool

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

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

Deprecated: Use QueryPolicyRequest.ProtoReflect.Descriptor instead.

func (*QueryPolicyRequest) GetAccount added in v0.2.0

func (x *QueryPolicyRequest) GetAccount() string

func (*QueryPolicyRequest) GetDomain added in v0.5.5

func (x *QueryPolicyRequest) GetDomain() string

func (*QueryPolicyRequest) GetNamespaceId added in v0.2.0

func (x *QueryPolicyRequest) GetNamespaceId() string

func (*QueryPolicyRequest) GetPage added in v0.2.0

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

func (*QueryPolicyRequest) GetRoleId added in v0.2.0

func (x *QueryPolicyRequest) GetRoleId() string

func (*QueryPolicyRequest) GetType added in v0.2.0

func (x *QueryPolicyRequest) GetType() PolicyType

func (*QueryPolicyRequest) GetWithNamespace added in v0.2.0

func (x *QueryPolicyRequest) GetWithNamespace() bool

func (*QueryPolicyRequest) GetWithRole added in v0.2.0

func (x *QueryPolicyRequest) GetWithRole() bool

func (*QueryPolicyRequest) ProtoMessage added in v0.2.0

func (*QueryPolicyRequest) ProtoMessage()

func (*QueryPolicyRequest) ProtoReflect added in v0.2.0

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

func (*QueryPolicyRequest) Reset added in v0.2.0

func (x *QueryPolicyRequest) Reset()

func (*QueryPolicyRequest) String added in v0.2.0

func (x *QueryPolicyRequest) String() string

func (*QueryPolicyRequest) Validate

func (req *QueryPolicyRequest) Validate() error

Validate 校验请求是否合法

type Set

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

func NewPolicySet

func NewPolicySet() *Set

NewPolicySet todo

func (*Set) Add

func (s *Set) Add(e *Policy)

Add 添加

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() []*Policy

func (*Set) GetNamespace added in v0.3.2

func (s *Set) GetNamespace() (nss []string)

func (*Set) GetNamespaceWithPage added in v0.5.5

func (s *Set) GetNamespaceWithPage(page *page.PageRequest) (nss []string, total int64)

func (*Set) GetRoles added in v0.2.0

func (s *Set) GetRoles(ctx context.Context, r role.RoleServiceServer, withPermission bool) (*role.Set, error)

GetRoles todo

func (*Set) GetScope added in v0.2.9

func (s *Set) GetScope(account string) string

GetScope todo

func (*Set) GetTotal added in v0.2.0

func (x *Set) GetTotal() int64

func (*Set) Length added in v0.2.0

func (s *Set) Length() int

Length 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

func (*Set) UserRoles

func (s *Set) UserRoles(account string) []string

UserRoles 获取用户的角色

func (*Set) Users added in v0.2.0

func (s *Set) Users() []string

Users 策略包含的所有用户ID, 已去重

type UnimplementedPolicyServiceServer added in v0.2.0

type UnimplementedPolicyServiceServer struct {
}

UnimplementedPolicyServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedPolicyServiceServer) CreatePolicy added in v0.2.0

func (UnimplementedPolicyServiceServer) DeletePolicy added in v0.2.0

func (UnimplementedPolicyServiceServer) DescribePolicy added in v0.2.0

func (UnimplementedPolicyServiceServer) QueryPolicy added in v0.2.0

type UnsafePolicyServiceServer added in v0.2.0

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

UnsafePolicyServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to PolicyServiceServer 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