policy

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AppName = "policy"
)
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_apps_policy_pb_enum_proto protoreflect.FileDescriptor
View Source
var File_apps_policy_pb_policy_proto protoreflect.FileDescriptor
View Source
var File_apps_policy_pb_request_proto protoreflect.FileDescriptor
View Source
var File_apps_policy_pb_service_proto protoreflect.FileDescriptor
View Source
var Service_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "infraboard.keyauth.policy.Service",
	HandlerType: (*ServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "CreatePolicy",
			Handler:    _Service_CreatePolicy_Handler,
		},
		{
			MethodName: "QueryPolicy",
			Handler:    _Service_QueryPolicy_Handler,
		},
		{
			MethodName: "DescribePolicy",
			Handler:    _Service_DescribePolicy_Handler,
		},
		{
			MethodName: "DeletePolicy",
			Handler:    _Service_DeletePolicy_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "apps/policy/pb/service.proto",
}

Service_ServiceDesc is the grpc.ServiceDesc for Service 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

func HttpEntry() *http.EntrySet

HttpEntry todo

func RegisterServiceServer

func RegisterServiceServer(s grpc.ServiceRegistrar, srv ServiceServer)

Types

type CreatePolicyRequest

type CreatePolicyRequest struct {

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

CreatePolicyRequest 创建策略的请求

func NewCreatePolicyRequest

func NewCreatePolicyRequest() *CreatePolicyRequest

NewCreatePolicyRequest 请求实例

func (*CreatePolicyRequest) Descriptor deprecated

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

Deprecated: Use CreatePolicyRequest.ProtoReflect.Descriptor instead.

func (*CreatePolicyRequest) GetAccount

func (x *CreatePolicyRequest) GetAccount() string

func (*CreatePolicyRequest) GetCreater

func (x *CreatePolicyRequest) GetCreater() string

func (*CreatePolicyRequest) GetDomain

func (x *CreatePolicyRequest) GetDomain() string

func (*CreatePolicyRequest) GetExpiredTime

func (x *CreatePolicyRequest) GetExpiredTime() int64

func (*CreatePolicyRequest) GetNamespaceId

func (x *CreatePolicyRequest) GetNamespaceId() string

func (*CreatePolicyRequest) GetRoleId

func (x *CreatePolicyRequest) GetRoleId() string

func (*CreatePolicyRequest) GetScope

func (x *CreatePolicyRequest) GetScope() string

func (*CreatePolicyRequest) GetType

func (x *CreatePolicyRequest) GetType() PolicyType

func (*CreatePolicyRequest) ProtoMessage

func (*CreatePolicyRequest) ProtoMessage()

func (*CreatePolicyRequest) ProtoReflect

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

func (*CreatePolicyRequest) Reset

func (x *CreatePolicyRequest) Reset()

func (*CreatePolicyRequest) String

func (x *CreatePolicyRequest) String() string

func (*CreatePolicyRequest) Validate

func (req *CreatePolicyRequest) Validate() error

Validate 校验请求合法

type DeletePolicyRequest

type DeletePolicyRequest struct {

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

DeletePolicyRequest todo

func NewDeletePolicyRequest

func NewDeletePolicyRequest() *DeletePolicyRequest

NewDeletePolicyRequest todo

func NewDeletePolicyRequestWithAccount

func NewDeletePolicyRequestWithAccount(account string) *DeletePolicyRequest

NewDeletePolicyRequestWithAccount todo

func NewDeletePolicyRequestWithID

func NewDeletePolicyRequestWithID(id string) *DeletePolicyRequest

NewDeletePolicyRequestWithID todo

func NewDeletePolicyRequestWithNamespaceID

func NewDeletePolicyRequestWithNamespaceID(namespaceID string) *DeletePolicyRequest

NewDeletePolicyRequestWithNamespaceID todo

func NewDeletePolicyRequestWithRoleID

func NewDeletePolicyRequestWithRoleID(roleID string) *DeletePolicyRequest

NewDeletePolicyRequestWithRoleID todo

func (*DeletePolicyRequest) Descriptor deprecated

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

Deprecated: Use DeletePolicyRequest.ProtoReflect.Descriptor instead.

func (*DeletePolicyRequest) GetAccount

func (x *DeletePolicyRequest) GetAccount() string

func (*DeletePolicyRequest) GetDomain

func (x *DeletePolicyRequest) GetDomain() string

func (*DeletePolicyRequest) GetId

func (x *DeletePolicyRequest) GetId() string

func (*DeletePolicyRequest) GetNamespaceId

func (x *DeletePolicyRequest) GetNamespaceId() string

func (*DeletePolicyRequest) GetRoleId

func (x *DeletePolicyRequest) GetRoleId() string

func (*DeletePolicyRequest) GetType

func (x *DeletePolicyRequest) GetType() PolicyType

func (*DeletePolicyRequest) ProtoMessage

func (*DeletePolicyRequest) ProtoMessage()

func (*DeletePolicyRequest) ProtoReflect

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

func (*DeletePolicyRequest) Reset

func (x *DeletePolicyRequest) Reset()

func (*DeletePolicyRequest) String

func (x *DeletePolicyRequest) String() string

func (*DeletePolicyRequest) Validate

func (req *DeletePolicyRequest) Validate() error

Validate todo

type DescribePolicyRequest

type DescribePolicyRequest struct {

	// @gotags: json:"id"
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id"`
	// contains filtered or unexported fields
}

DescribePolicyRequest todo

func NewDescriptPolicyRequest

func NewDescriptPolicyRequest() *DescribePolicyRequest

NewDescriptPolicyRequest new实例

func (*DescribePolicyRequest) Descriptor deprecated

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

Deprecated: Use DescribePolicyRequest.ProtoReflect.Descriptor instead.

func (*DescribePolicyRequest) GetId

func (x *DescribePolicyRequest) GetId() string

func (*DescribePolicyRequest) ProtoMessage

func (*DescribePolicyRequest) ProtoMessage()

func (*DescribePolicyRequest) ProtoReflect

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

func (*DescribePolicyRequest) Reset

func (x *DescribePolicyRequest) Reset()

func (*DescribePolicyRequest) String

func (x *DescribePolicyRequest) String() string

func (*DescribePolicyRequest) Validate

func (req *DescribePolicyRequest) Validate() error

Validate todo

type Policy

type Policy struct {

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

Policy 权限策略

func New

func New(req *CreatePolicyRequest) (*Policy, error)

New 新实例

func NewDefaultPolicy

func NewDefaultPolicy() *Policy

NewDefaultPolicy todo

func (*Policy) CheckDependence

CheckDependence todo

func (*Policy) Descriptor deprecated

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

Deprecated: Use Policy.ProtoReflect.Descriptor instead.

func (*Policy) GetAccount

func (x *Policy) GetAccount() string

func (*Policy) GetCreateAt

func (x *Policy) GetCreateAt() int64

func (*Policy) GetCreater

func (x *Policy) GetCreater() string

func (*Policy) GetDomain

func (x *Policy) GetDomain() string

func (*Policy) GetExpiredTime

func (x *Policy) GetExpiredTime() int64

func (*Policy) GetId

func (x *Policy) GetId() string

func (*Policy) GetNamespace

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

func (*Policy) GetNamespaceId

func (x *Policy) GetNamespaceId() string

func (*Policy) GetRole

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

func (*Policy) GetRoleId

func (x *Policy) GetRoleId() string

func (*Policy) GetScope

func (x *Policy) GetScope() string

func (*Policy) GetType

func (x *Policy) GetType() PolicyType

func (*Policy) GetUpdateAt

func (x *Policy) GetUpdateAt() int64

func (*Policy) GetUserType

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

func (*Policy) IsAllNamespace

func (p *Policy) IsAllNamespace() bool

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

func (*Policy) ProtoMessage

func (*Policy) ProtoMessage()

func (*Policy) ProtoReflect

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

func (*Policy) Reset

func (x *Policy) Reset()

func (*Policy) String

func (x *Policy) String() string

type PolicyType

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

func ParsePolicyTypeFromString

func ParsePolicyTypeFromString(str string) (PolicyType, error)

ParsePolicyTypeFromString Parse PolicyType from string

func (PolicyType) Descriptor

func (PolicyType) Descriptor() protoreflect.EnumDescriptor

func (PolicyType) Enum

func (x PolicyType) Enum() *PolicyType

func (PolicyType) EnumDescriptor deprecated

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

Deprecated: Use PolicyType.Descriptor instead.

func (PolicyType) Equal

func (t PolicyType) Equal(target PolicyType) bool

Equal type compare

func (PolicyType) IsIn

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

IsIn todo

func (PolicyType) MarshalJSON

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

MarshalJSON todo

func (PolicyType) Number

func (x PolicyType) Number() protoreflect.EnumNumber

func (PolicyType) String

func (x PolicyType) String() string

func (PolicyType) Type

func (*PolicyType) UnmarshalJSON

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

UnmarshalJSON todo

type QueryPolicyRequest

type QueryPolicyRequest struct {

	// @gotags: bson:"page" json:"page"
	Page *request.PageRequest `protobuf:"bytes,1,opt,name=page,proto3" json:"page" bson:"page"`
	// @gotags: json:"account,omitempty"
	Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"`
	// @gotags: json:"role_id,omitempty"
	RoleId string `protobuf:"bytes,3,opt,name=role_id,json=roleId,proto3" json:"role_id,omitempty"`
	// @gotags: json:"namespace_id,omitempty"
	NamespaceId string `protobuf:"bytes,4,opt,name=namespace_id,json=namespaceId,proto3" json:"namespace_id,omitempty"`
	// @gotags: json:"type,omitempty"
	Type PolicyType `protobuf:"varint,5,opt,name=type,proto3,enum=infraboard.keyauth.policy.PolicyType" json:"type,omitempty"`
	// @gotags: json:"with_role,omitempty"
	WithRole bool `protobuf:"varint,6,opt,name=with_role,json=withRole,proto3" json:"with_role,omitempty"`
	// @gotags: json:"with_namespace,omitempty"
	WithNamespace bool `protobuf:"varint,7,opt,name=with_namespace,json=withNamespace,proto3" json:"with_namespace,omitempty"`
	// @gotags: json:"domain"
	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

func NewQueryPolicyRequestFromHTTP(r *http.Request) *QueryPolicyRequest

NewQueryPolicyRequestFromHTTP 列表查询请求

func (*QueryPolicyRequest) CheckOwner

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

func (*QueryPolicyRequest) Descriptor deprecated

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

Deprecated: Use QueryPolicyRequest.ProtoReflect.Descriptor instead.

func (*QueryPolicyRequest) GetAccount

func (x *QueryPolicyRequest) GetAccount() string

func (*QueryPolicyRequest) GetDomain

func (x *QueryPolicyRequest) GetDomain() string

func (*QueryPolicyRequest) GetNamespaceId

func (x *QueryPolicyRequest) GetNamespaceId() string

func (*QueryPolicyRequest) GetPage

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

func (*QueryPolicyRequest) GetRoleId

func (x *QueryPolicyRequest) GetRoleId() string

func (*QueryPolicyRequest) GetType

func (x *QueryPolicyRequest) GetType() PolicyType

func (*QueryPolicyRequest) GetWithNamespace

func (x *QueryPolicyRequest) GetWithNamespace() bool

func (*QueryPolicyRequest) GetWithRole

func (x *QueryPolicyRequest) GetWithRole() bool

func (*QueryPolicyRequest) ProtoMessage

func (*QueryPolicyRequest) ProtoMessage()

func (*QueryPolicyRequest) ProtoReflect

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

func (*QueryPolicyRequest) Reset

func (x *QueryPolicyRequest) Reset()

func (*QueryPolicyRequest) String

func (x *QueryPolicyRequest) String() string

func (*QueryPolicyRequest) Validate

func (req *QueryPolicyRequest) Validate() error

Validate 校验请求是否合法

type ServiceClient

type ServiceClient 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)
}

ServiceClient is the client API for Service 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 NewServiceClient

func NewServiceClient(cc grpc.ClientConnInterface) ServiceClient

type ServiceServer

type ServiceServer 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
}

ServiceServer is the server API for Service service. All implementations must embed UnimplementedServiceServer for forward compatibility

type Set

type Set struct {

	// @gotags: bson:"total" json:"total"
	Total int64 `protobuf:"varint,1,opt,name=total,proto3" json:"total" bson:"total"`
	// @gotags: bson:"items" json:"items"
	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

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

Deprecated: Use Set.ProtoReflect.Descriptor instead.

func (*Set) GetItems

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

func (*Set) GetNamespace

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

func (*Set) GetNamespaceWithPage

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

func (*Set) GetRoles

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

GetRoles todo

func (*Set) GetScope

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

GetScope todo

func (*Set) GetTotal

func (x *Set) GetTotal() int64

func (*Set) Length

func (s *Set) Length() int

Length todo

func (*Set) ProtoMessage

func (*Set) ProtoMessage()

func (*Set) ProtoReflect

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

func (*Set) Reset

func (x *Set) Reset()

func (*Set) String

func (x *Set) String() string

func (*Set) UserRoles

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

UserRoles 获取用户的角色

func (*Set) Users

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

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

type UnimplementedServiceServer

type UnimplementedServiceServer struct {
}

UnimplementedServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedServiceServer) CreatePolicy

func (UnimplementedServiceServer) DeletePolicy

func (UnimplementedServiceServer) DescribePolicy

func (UnimplementedServiceServer) QueryPolicy

type UnsafeServiceServer

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

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