73 lines
3.2 KiB
Go
73 lines
3.2 KiB
Go
package model
|
||
|
||
import "time"
|
||
|
||
// LogScopeRole 日志查询范围权限(正则匹配 ES 索引 / Loki label) // Logan.Li
|
||
type LogScopeRole struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
Name string `gorm:"size:64;not null" json:"name"`
|
||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||
Engine string `gorm:"size:32;default:*;comment:引擎 loki/elasticsearch/*" json:"engine"`
|
||
MatchField string `gorm:"size:32;not null;comment:匹配维度 index/app/namespace/job" json:"match_field"`
|
||
Pattern string `gorm:"size:255;not null;comment:正则表达式" json:"pattern"`
|
||
DatasourceID *uint `json:"datasource_id,omitempty"`
|
||
Role string `gorm:"size:16;default:viewer;comment:viewer/analyst" json:"role"`
|
||
Description string `gorm:"size:255" json:"description"`
|
||
Status int `gorm:"default:1;comment:0禁用1启用" json:"status"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
}
|
||
|
||
func (LogScopeRole) TableName() string { return "iam_log_scope_roles" }
|
||
|
||
// UserLogScopeRole 用户 ↔ 日志范围权限 // Logan.Li
|
||
type UserLogScopeRole struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
UserID uint `gorm:"uniqueIndex:idx_iam_user_log_scope_role;not null" json:"user_id"`
|
||
LogScopeRoleID uint `gorm:"uniqueIndex:idx_iam_user_log_scope_role;not null" json:"log_scope_role_id"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
|
||
LogScopeRole *LogScopeRole `json:"log_scope_role,omitempty" gorm:"foreignKey:LogScopeRoleID;references:ID"`
|
||
}
|
||
|
||
func (UserLogScopeRole) TableName() string { return "iam_user_log_scope_roles" }
|
||
|
||
// CreateLogScopeRoleRequest 创建日志权限策略 // Logan.Li
|
||
type CreateLogScopeRoleRequest struct {
|
||
Name string `json:"name" binding:"required,max=64"`
|
||
Code string `json:"code" binding:"required,max=64"`
|
||
Engine string `json:"engine" binding:"omitempty,oneof=loki elasticsearch *"`
|
||
MatchField string `json:"match_field" binding:"required,oneof=index app namespace job"`
|
||
Pattern string `json:"pattern" binding:"required,max=255"`
|
||
DatasourceID *uint `json:"datasource_id"`
|
||
Role string `json:"role" binding:"omitempty,oneof=viewer analyst"`
|
||
Description string `json:"description"`
|
||
}
|
||
|
||
// UpdateLogScopeRoleRequest 更新日志权限策略 // Logan.Li
|
||
type UpdateLogScopeRoleRequest struct {
|
||
Name string `json:"name"`
|
||
Code string `json:"code"`
|
||
Engine string `json:"engine"`
|
||
MatchField string `json:"match_field"`
|
||
Pattern string `json:"pattern"`
|
||
DatasourceID *uint `json:"datasource_id"`
|
||
Role string `json:"role"`
|
||
Description string `json:"description"`
|
||
Status *int `json:"status"`
|
||
}
|
||
|
||
// AssignLogScopeRoleRequest 用户授权(user_id 取自 URL 路径)// Logan.Li
|
||
type AssignLogScopeRoleRequest struct {
|
||
LogScopeRoleID uint `json:"log_scope_role_id" binding:"required"`
|
||
}
|
||
|
||
// PreviewLogScopeRequest 命中预览 // Logan.Li
|
||
type PreviewLogScopeRequest struct {
|
||
Engine string `json:"engine" binding:"required,oneof=loki elasticsearch"`
|
||
DatasourceID uint `json:"datasource_id"`
|
||
Index string `json:"index"`
|
||
Query string `json:"query"`
|
||
SampleValue string `json:"sample_value"`
|
||
}
|