feat: Console 查看页与自有查询端点(里程碑 4)
- 服务端 AuditQueryEndpoint(CustomEndpoint,group=audit.example.com):
GET /apis/audit.example.com/v1alpha1/auditlogs/-/query
- 等值筛选(fieldSelector 白名单)、关键字(resourceName/path contains OR)、
结果(success 2xx-3xx / failure 4xx+)、时间区间(含边界 ISO-8601)
- 全部走索引 Query + PageRequestImpl,无内存分页;页大小上限 100
- 风险项 #2 源码级证实并按预案落地:原生 fieldSelector 仅支持 =/!=/IN
- API 使用 2.22+ 新 Queries/Condition 体系(QueryFactory 已 @Deprecated)
- Console 页面:列表(VEntity 行:操作者/动作徽标/资源/路径/状态码/IP)+
七维筛选栏 + 分页(10/20/50)+ 只读详情抽屉(完整字段 + 原始 JSON)
- 端点测试 10 例(默认值/筛选组合/参数校验/排序收敛),UI 类型检查通过
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 审计日志的类型定义与展示辅助。
|
||||
*/
|
||||
|
||||
export interface AuditLogSpec {
|
||||
username: string
|
||||
method: string
|
||||
resourceType: string
|
||||
resourceName?: string | null
|
||||
path: string
|
||||
statusCode: number
|
||||
remoteIp: string
|
||||
userAgent?: string | null
|
||||
}
|
||||
|
||||
export interface AuditLog {
|
||||
metadata: {
|
||||
name: string
|
||||
creationTimestamp: string
|
||||
version?: number
|
||||
}
|
||||
spec: AuditLogSpec
|
||||
}
|
||||
|
||||
export interface ListResult<T> {
|
||||
page: number
|
||||
size: number
|
||||
total: number
|
||||
items: T[]
|
||||
first?: boolean
|
||||
last?: boolean
|
||||
hasNext?: boolean
|
||||
hasPrevious?: boolean
|
||||
totalPages?: number
|
||||
}
|
||||
|
||||
export const UNKNOWN_USERNAME = 'unknown'
|
||||
|
||||
/** 展示用操作者名:登录失败的“未知用户”占位。 */
|
||||
export function displayUsername(username?: string | null): string {
|
||||
if (!username) {
|
||||
return UNKNOWN_USERNAME
|
||||
}
|
||||
return username === UNKNOWN_USERNAME ? '未知用户' : username
|
||||
}
|
||||
|
||||
/** 时间格式化:本地时区 YYYY-MM-DD HH:mm:ss。 */
|
||||
export function formatTime(iso?: string | null): string {
|
||||
if (!iso) {
|
||||
return '-'
|
||||
}
|
||||
const date = new Date(iso)
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return iso
|
||||
}
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return (
|
||||
`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
|
||||
`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
|
||||
)
|
||||
}
|
||||
|
||||
const METHOD_BADGE_CLASS: Record<string, string> = {
|
||||
POST: 'method-post',
|
||||
PUT: 'method-put',
|
||||
DELETE: 'method-delete',
|
||||
PATCH: 'method-patch',
|
||||
}
|
||||
|
||||
export function methodBadgeClass(method?: string | null): string {
|
||||
return method ? METHOD_BADGE_CLASS[method] ?? 'method-other' : 'method-other'
|
||||
}
|
||||
|
||||
/** 结果语义:2xx/3xx 成功,其余失败。 */
|
||||
export function isSuccessful(statusCode?: number | null): boolean {
|
||||
return statusCode != null && statusCode >= 200 && statusCode < 400
|
||||
}
|
||||
|
||||
/** datetime-local 输入值(本地时区)转 ISO-8601 Instant。 */
|
||||
export function localDateTimeToInstant(value: string): string | null {
|
||||
if (!value) {
|
||||
return null
|
||||
}
|
||||
const date = new Date(value)
|
||||
return Number.isNaN(date.getTime()) ? null : date.toISOString()
|
||||
}
|
||||
Reference in New Issue
Block a user