 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- Constants
- type CreatePolicyRequest
- type DeletePolicyRequest
- type DescribePolicyRequest
- type PermissionService
- type Policy
- type PolicyService
- type QueryEndpointRequest
- type QueryEndpointResponse
- type QueryMenuRequest
- type QueryNamespaceRequest
- type QueryPolicyRequest
- func (r *QueryPolicyRequest) SetEnabled(v bool) *QueryPolicyRequest
- func (r *QueryPolicyRequest) SetExpired(v bool) *QueryPolicyRequest
- func (r *QueryPolicyRequest) SetNamespaceId(nsId uint64) *QueryPolicyRequest
- func (r *QueryPolicyRequest) SetSkipPage(v bool) *QueryPolicyRequest
- func (r *QueryPolicyRequest) SetUserId(uid uint64) *QueryPolicyRequest
- func (r *QueryPolicyRequest) SetWithRole(v bool) *QueryPolicyRequest
- func (r *QueryPolicyRequest) SetWithUser(v bool) *QueryPolicyRequest
- func (r *QueryPolicyRequest) SetWithUsers(v bool) *QueryPolicyRequest
 
- type ResourceLabel
- type ResourceScope
- func (r *ResourceScope) BuildMySQLPrefixBlob()
- func (r *ResourceScope) GetNamespaceId() uint64
- func (r ResourceScope) GormResourceFilter(query *gorm.DB) *gorm.DB
- func (r *ResourceScope) SetNamespaceId(v uint64)
- func (l *ResourceScope) SetScope(key string, value []string)
- func (r ResourceScope) String() string
 
- type Service
- type UpdatePolicyRequest
- type ValidateEndpointPermissionRequest
- type ValidateEndpointPermissionResponse
- type ValidatePagePermissionRequest
- type ValidatePagePermissionResponse
Constants ¶
      View Source
      
  
const (
	AppName = "policy"
)
    Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreatePolicyRequest ¶
type CreatePolicyRequest struct {
	// 创建者
	CreateBy uint64 `json:"create_by" bson:"create_by" gorm:"column:create_by;type:uint" description:"创建者" optional:"true"`
	// 资源访问范围
	ResourceScope
	// 用户Id
	UserId uint64 `` /* 129-byte string literal not displayed */
	// 角色Id
	RoleId []uint64 `` /* 139-byte string literal not displayed */
	// 策略过期时间
	ExpiredTime *time.Time `` /* 136-byte string literal not displayed */
	// 只读策略, 不允许用户修改, 一般用于系统管理
	ReadOnly bool `` /* 165-byte string literal not displayed */
	// 该策略是否启用
	Enabled bool `json:"enabled" bson:"enabled" gorm:"column:enabled;type:tinyint(1)" description:"该策略是否启用" optional:"true"`
	// 策略标签
	Label string `json:"label" gorm:"column:label;type:varchar(200);index" description:"策略标签" optional:"true"`
	// 扩展信息
	Extras map[string]string `json:"extras" bson:"extras" gorm:"column:extras;serializer:json;type:json" description:"扩展信息" optional:"true"`
}
    func NewCreatePolicyRequest ¶
func NewCreatePolicyRequest() *CreatePolicyRequest
func (*CreatePolicyRequest) SetNamespaceId ¶ added in v0.0.5
func (r *CreatePolicyRequest) SetNamespaceId(namespaceId uint64) *CreatePolicyRequest
func (*CreatePolicyRequest) Validate ¶
func (r *CreatePolicyRequest) Validate() error
type DeletePolicyRequest ¶
type DeletePolicyRequest struct {
	apps.GetRequest
}
    func NewDeletePolicyRequest ¶
func NewDeletePolicyRequest() *DeletePolicyRequest
type DescribePolicyRequest ¶
type DescribePolicyRequest struct {
	apps.GetRequest
}
    func NewDescribePolicyRequest ¶
func NewDescribePolicyRequest() *DescribePolicyRequest
type PermissionService ¶
type PermissionService interface {
	// 查询用户可以访问的空间
	QueryNamespace(context.Context, *QueryNamespaceRequest) (*types.Set[*namespace.Namespace], error)
	// 查询用户可以访问的菜单
	QueryMenu(context.Context, *QueryMenuRequest) (*types.Set[*view.Menu], error)
	// 查询用户可以访问的Api接口
	QueryEndpoint(context.Context, *QueryEndpointRequest) (*QueryEndpointResponse, error)
	// 校验页面权限
	ValidatePagePermission(context.Context, *ValidatePagePermissionRequest) (*ValidatePagePermissionResponse, error)
	// 校验接口权限
	ValidateEndpointPermission(context.Context, *ValidateEndpointPermissionRequest) (*ValidateEndpointPermissionResponse, error)
}
    type Policy ¶
type Policy struct {
	// 基础数据
	apps.ResourceMeta
	// 策略定义
	CreatePolicyRequest
	// 关联空间
	Namespace *namespace.Namespace `json:"namespace,omitempty" gorm:"-"`
	// 关联用户
	User *user.User `json:"user,omitempty" gorm:"-"`
	// 关联角色
	Role *role.Role `json:"role,omitempty" gorm:"-"`
}
    type PolicyService ¶
type PolicyService interface {
	// 创建策略
	CreatePolicy(context.Context, *CreatePolicyRequest) (*Policy, error)
	// 查询策略列表
	QueryPolicy(context.Context, *QueryPolicyRequest) (*types.Set[*Policy], error)
	// 查询详情
	DescribePolicy(context.Context, *DescribePolicyRequest) (*Policy, error)
	// 更新策略
	UpdatePolicy(context.Context, *UpdatePolicyRequest) (*Policy, error)
	// 删除策略
	DeletePolicy(context.Context, *DeletePolicyRequest) (*Policy, error)
}
    type QueryEndpointRequest ¶
type QueryEndpointRequest struct {
	UserId      uint64 `json:"user_id"`
	NamespaceId uint64 `json:"namespace_id"`
}
    func NewQueryEndpointRequest ¶
func NewQueryEndpointRequest() *QueryEndpointRequest
func (*QueryEndpointRequest) SetNamespaceId ¶
func (r *QueryEndpointRequest) SetNamespaceId(v uint64) *QueryEndpointRequest
func (*QueryEndpointRequest) SetUserId ¶
func (r *QueryEndpointRequest) SetUserId(v uint64) *QueryEndpointRequest
type QueryEndpointResponse ¶ added in v0.0.13
type QueryEndpointResponse struct {
	ResourceScope
	Items []*endpoint.Endpoint `json:"endpoints"`
}
    func NewQueryEndpointResponse ¶ added in v0.0.13
func NewQueryEndpointResponse() *QueryEndpointResponse
type QueryMenuRequest ¶
type QueryMenuRequest struct {
	UserId      uint64 `json:"user_id"`
	NamespaceId uint64 `json:"namespace_id"`
}
    func NewQueryMenuRequest ¶
func NewQueryMenuRequest() *QueryMenuRequest
type QueryNamespaceRequest ¶
type QueryNamespaceRequest struct {
	UserId      uint64 `json:"user_id"`
	NamespaceId uint64 `json:"namespace_id"`
}
    func NewQueryNamespaceRequest ¶
func NewQueryNamespaceRequest() *QueryNamespaceRequest
func (*QueryNamespaceRequest) SetNamespaceId ¶
func (r *QueryNamespaceRequest) SetNamespaceId(v uint64) *QueryNamespaceRequest
func (*QueryNamespaceRequest) SetUserId ¶
func (r *QueryNamespaceRequest) SetUserId(v uint64) *QueryNamespaceRequest
type QueryPolicyRequest ¶
type QueryPolicyRequest struct {
	*request.PageRequest
	// 忽略分页
	SkipPage bool `json:"skip_page"`
	// 关联用户Id
	UserId *uint64 `json:"user_id"`
	// 关联空间
	NamespaceId *uint64 `json:"namespace_id"`
	// 没有过期
	Expired *bool `json:"expired"`
	// 有没有启动
	Enabled *bool `json:"active"`
	// 关联查询出空间对象
	WithNamespace bool `json:"with_namespace"`
	// 关联查询出用户对象
	WithUser bool `json:"with_user"`
	// 关联查询角色对象
	WithRole bool `json:"with_role"`
}
    func NewQueryPolicyRequest ¶
func NewQueryPolicyRequest() *QueryPolicyRequest
func (*QueryPolicyRequest) SetEnabled ¶
func (r *QueryPolicyRequest) SetEnabled(v bool) *QueryPolicyRequest
func (*QueryPolicyRequest) SetExpired ¶
func (r *QueryPolicyRequest) SetExpired(v bool) *QueryPolicyRequest
func (*QueryPolicyRequest) SetNamespaceId ¶
func (r *QueryPolicyRequest) SetNamespaceId(nsId uint64) *QueryPolicyRequest
func (*QueryPolicyRequest) SetSkipPage ¶
func (r *QueryPolicyRequest) SetSkipPage(v bool) *QueryPolicyRequest
func (*QueryPolicyRequest) SetUserId ¶
func (r *QueryPolicyRequest) SetUserId(uid uint64) *QueryPolicyRequest
func (*QueryPolicyRequest) SetWithRole ¶
func (r *QueryPolicyRequest) SetWithRole(v bool) *QueryPolicyRequest
func (*QueryPolicyRequest) SetWithUser ¶
func (r *QueryPolicyRequest) SetWithUser(v bool) *QueryPolicyRequest
func (*QueryPolicyRequest) SetWithUsers ¶
func (r *QueryPolicyRequest) SetWithUsers(v bool) *QueryPolicyRequest
type ResourceLabel ¶ added in v0.0.13
type ResourceLabel struct {
	// 空间
	NamespaceId *uint64 `` /* 144-byte string literal not displayed */
	// 访问范围, 需要提前定义scope, 比如环境, 后端开发小组,开发资源
	Label map[string]string `json:"label" bson:"label" gorm:"column:label;serializer:json;type:json" description:"数据访问的范围" optional:"true"`
}
    func (*ResourceLabel) SetLabel ¶ added in v0.0.13
func (l *ResourceLabel) SetLabel(key, value string)
func (*ResourceLabel) SetNamespaceId ¶ added in v0.0.13
func (l *ResourceLabel) SetNamespaceId(v uint64)
func (ResourceLabel) String ¶ added in v0.0.13
func (r ResourceLabel) String() string
type ResourceScope ¶ added in v0.0.13
type ResourceScope struct {
	// 空间
	NamespaceId *uint64 `` /* 144-byte string literal not displayed */
	// 访问范围, 需要提前定义scope, 比如环境 env: ['dev','test']
	Scope map[string][]string `json:"scope" bson:"scope" gorm:"column:scope;serializer:json;type:json" description:"数据访问的范围" optional:"true"`
}
    func NewResourceScope ¶ added in v0.0.13
func NewResourceScope() *ResourceScope
func (*ResourceScope) BuildMySQLPrefixBlob ¶ added in v0.0.13
func (r *ResourceScope) BuildMySQLPrefixBlob()
func (*ResourceScope) GetNamespaceId ¶ added in v0.0.13
func (r *ResourceScope) GetNamespaceId() uint64
func (ResourceScope) GormResourceFilter ¶ added in v0.0.13
func (r ResourceScope) GormResourceFilter(query *gorm.DB) *gorm.DB
func (*ResourceScope) SetNamespaceId ¶ added in v0.0.13
func (r *ResourceScope) SetNamespaceId(v uint64)
func (*ResourceScope) SetScope ¶ added in v0.0.13
func (l *ResourceScope) SetScope(key string, value []string)
func (ResourceScope) String ¶ added in v0.0.13
func (r ResourceScope) String() string
type Service ¶
type Service interface {
	// 策略管理
	PolicyService
	// 权限查询, 整合用户多个角色的权限合集
	PermissionService
}
    func GetService ¶
func GetService() Service
type UpdatePolicyRequest ¶
type UpdatePolicyRequest struct {
	apps.GetRequest
	CreatePolicyRequest
}
    type ValidateEndpointPermissionRequest ¶
type ValidateEndpointPermissionRequest struct {
	UserId  uint64 `json:"user_id" form:"user_id"`
	Service string `json:"service" form:"service"`
	Path    string `json:"path" form:"path"`
	Method  string `json:"method" form:"method"`
	ResourceScope
}
    func NewValidateEndpointPermissionRequest ¶ added in v0.0.5
func NewValidateEndpointPermissionRequest() *ValidateEndpointPermissionRequest
type ValidateEndpointPermissionResponse ¶
type ValidateEndpointPermissionResponse struct {
	ValidateEndpointPermissionRequest
	HasPermission bool               `json:"has_permission"`
	Endpoint      *endpoint.Endpoint `json:"endpoint"`
}
    func NewValidateEndpointPermissionResponse ¶ added in v0.0.5
func NewValidateEndpointPermissionResponse(req ValidateEndpointPermissionRequest) *ValidateEndpointPermissionResponse
func (*ValidateEndpointPermissionResponse) String ¶ added in v0.0.5
func (r *ValidateEndpointPermissionResponse) String() string
type ValidatePagePermissionRequest ¶
type ValidatePagePermissionRequest struct {
	UserId uint64 `json:"user_id" form:"user_id"`
	Path   string `json:"path" form:"path"`
	ResourceScope
}
    type ValidatePagePermissionResponse ¶
type ValidatePagePermissionResponse struct {
	ValidatePagePermissionRequest
	HasPermission bool       `json:"has_permission"`
	Page          *view.Page `json:"page"`
}
    func NewValidatePagePermissionResponse ¶ added in v0.0.5
func NewValidatePagePermissionResponse(req ValidatePagePermissionRequest) *ValidatePagePermissionResponse
 Click to show internal directories. 
   Click to hide internal directories.