fix: 落实官方规范评审修复(生成 API 客户端 / SSRF 防护 / 凭据迁 Secret)
对应 docs/operation-audit-halo-compliance.md 评审的两项不符合与第 5 节修复建议: 1. API 客户端生成(清单第 2 条):build.gradle 配置 haloPlugin.openApi 管线; 查询/导出/测试端点补 tag、参数声明与类型化 response(生成契约输入); bootstrap OpenAPI 规范 JSON(与 Springdoc 声明一一对手工对齐)驱动 devtools generateApiClient 产出 TS 客户端(ui/src/api/generated,openapi-generator 7.7.0); UI 经 ui/src/api 封装层复用宿主 axiosInstance,替换手写类型与裸 fetch; @halo-dev/api-client 由死依赖转为 axiosInstance 实际来源。 2. 出站安全与凭据(清单第 4 条):新增 OutboundUrlGuard——URI 解析 + scheme 白名单 + 禁止用户名/密码形态 + 全量 DNS 解析并拒绝环回/私网/链路本地/组播/未指定/ 云元数据(169.254.169.254、100.100.100.200、fd00:ec2::254)/CGNAT/ULA/Teredo/ 6to4/文档与保留段;PinnedAddressResolverGroup 钉定校验地址建连(DNS rebinding 防护,TLS SNI/Host 仍取原主机名);重定向显式关闭、三层超时 10 秒。 Webhook 地址凭据迁移 Halo Secret(settings.yaml 改 secret 输入存引用,服务端经 ReactiveExtensionClient 解析键 webhookUrl,fail closed);日志只记主机名, 不再记录可能内嵌 access_token 的完整地址。 测试:后端 244 用例(新增守卫地址段枚举/Secret 解析 fail closed/建连钉定证明等 25 例)+ UI vitest 54 用例 + vue-tsc + ./gradlew build 全部通过。
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
wwwroot/*.js
|
||||
node_modules
|
||||
typings
|
||||
dist
|
||||
@@ -0,0 +1 @@
|
||||
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
|
||||
@@ -0,0 +1,23 @@
|
||||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
||||
@@ -0,0 +1,18 @@
|
||||
.gitignore
|
||||
.npmignore
|
||||
.openapi-generator-ignore
|
||||
api.ts
|
||||
api/audit-v1alpha1-console-api.ts
|
||||
base.ts
|
||||
common.ts
|
||||
configuration.ts
|
||||
git_push.sh
|
||||
index.ts
|
||||
models/alert-send-result.ts
|
||||
models/audit-log-list.ts
|
||||
models/audit-log-spec.ts
|
||||
models/audit-log.ts
|
||||
models/change-entry.ts
|
||||
models/change-type.ts
|
||||
models/index.ts
|
||||
models/metadata.ts
|
||||
@@ -0,0 +1 @@
|
||||
7.7.0
|
||||
@@ -0,0 +1,18 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
export * from './api/audit-v1alpha1-console-api';
|
||||
|
||||
@@ -0,0 +1,433 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import type { Configuration } from '../configuration';
|
||||
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
|
||||
import globalAxios from 'axios';
|
||||
// Some imports not used depending on template conditions
|
||||
// @ts-ignore
|
||||
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common';
|
||||
// @ts-ignore
|
||||
import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base';
|
||||
// @ts-ignore
|
||||
import type { AlertSendResult } from '../models';
|
||||
// @ts-ignore
|
||||
import type { AuditLogList } from '../models';
|
||||
/**
|
||||
* AuditV1alpha1ConsoleApi - axios parameter creator
|
||||
* @export
|
||||
*/
|
||||
export const AuditV1alpha1ConsoleApiAxiosParamCreator = function (configuration?: Configuration) {
|
||||
return {
|
||||
/**
|
||||
* 按筛选条件导出审计日志为 CSV 附件(UTF-8 BOM,Excel/WPS 可直接打开):筛选参数与 query 完全一致,不分页全量导出,按时间升序输出
|
||||
* @param {Array<string>} [fieldSelector] 等值筛选,可重复(与 query 一致)
|
||||
* @param {string} [result] 结果筛选(success/failure)
|
||||
* @param {string} [keyword] 关键字(resourceName/path 模糊匹配)
|
||||
* @param {string} [startTime] 开始时间(ISO-8601,含边界)
|
||||
* @param {string} [endTime] 结束时间(ISO-8601,含边界)
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
exportAuditLogs: async (fieldSelector?: Array<string>, result?: string, keyword?: string, startTime?: string, endTime?: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
const localVarPath = `/apis/audit.guichumo.com/v1alpha1/auditlogs/-/export`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
if (fieldSelector) {
|
||||
localVarQueryParameter['fieldSelector'] = fieldSelector;
|
||||
}
|
||||
|
||||
if (result !== undefined) {
|
||||
localVarQueryParameter['result'] = result;
|
||||
}
|
||||
|
||||
if (keyword !== undefined) {
|
||||
localVarQueryParameter['keyword'] = keyword;
|
||||
}
|
||||
|
||||
if (startTime !== undefined) {
|
||||
localVarQueryParameter['startTime'] = (startTime as any instanceof Date) ?
|
||||
(startTime as any).toISOString() :
|
||||
startTime;
|
||||
}
|
||||
|
||||
if (endTime !== undefined) {
|
||||
localVarQueryParameter['endTime'] = (endTime as any instanceof Date) ?
|
||||
(endTime as any).toISOString() :
|
||||
endTime;
|
||||
}
|
||||
|
||||
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
* 分页查询审计日志:支持等值筛选(fieldSelector,含 spec.action 语义动作)、关键字(resourceName/path 模糊)、结果(success/failure)、时间区间(含边界)
|
||||
* @param {number} [page] 页码(从 1 开始)
|
||||
* @param {number} [size] 每页大小(1-100)
|
||||
* @param {string} [sort] 排序(field,(asc|desc)),仅支持 metadata.creationTimestamp
|
||||
* @param {Array<string>} [fieldSelector] 等值筛选,可重复(spec.username/spec.resourceType/spec.method/spec.action)
|
||||
* @param {string} [result] 结果筛选(success/failure)
|
||||
* @param {string} [keyword] 关键字(resourceName/path 模糊匹配)
|
||||
* @param {string} [startTime] 开始时间(ISO-8601,含边界)
|
||||
* @param {string} [endTime] 结束时间(ISO-8601,含边界)
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
listAuditLogs: async (page?: number, size?: number, sort?: string, fieldSelector?: Array<string>, result?: string, keyword?: string, startTime?: string, endTime?: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
const localVarPath = `/apis/audit.guichumo.com/v1alpha1/auditlogs/-/query`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
if (page !== undefined) {
|
||||
localVarQueryParameter['page'] = page;
|
||||
}
|
||||
|
||||
if (size !== undefined) {
|
||||
localVarQueryParameter['size'] = size;
|
||||
}
|
||||
|
||||
if (sort !== undefined) {
|
||||
localVarQueryParameter['sort'] = sort;
|
||||
}
|
||||
|
||||
if (fieldSelector) {
|
||||
localVarQueryParameter['fieldSelector'] = fieldSelector;
|
||||
}
|
||||
|
||||
if (result !== undefined) {
|
||||
localVarQueryParameter['result'] = result;
|
||||
}
|
||||
|
||||
if (keyword !== undefined) {
|
||||
localVarQueryParameter['keyword'] = keyword;
|
||||
}
|
||||
|
||||
if (startTime !== undefined) {
|
||||
localVarQueryParameter['startTime'] = (startTime as any instanceof Date) ?
|
||||
(startTime as any).toISOString() :
|
||||
startTime;
|
||||
}
|
||||
|
||||
if (endTime !== undefined) {
|
||||
localVarQueryParameter['endTime'] = (endTime as any instanceof Date) ?
|
||||
(endTime as any).toISOString() :
|
||||
endTime;
|
||||
}
|
||||
|
||||
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
* 向当前配置的 Webhook 地址推送一条测试告警(type=test)并返回推送结果:success 为是否送达(接收方 2xx),message 为状态/原因摘要;Webhook 未配置或非法时返回 400
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
testAlertWebhook: async (options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
const localVarPath = `/apis/audit.guichumo.com/v1alpha1/alerts/-/test`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* AuditV1alpha1ConsoleApi - functional programming interface
|
||||
* @export
|
||||
*/
|
||||
export const AuditV1alpha1ConsoleApiFp = function(configuration?: Configuration) {
|
||||
const localVarAxiosParamCreator = AuditV1alpha1ConsoleApiAxiosParamCreator(configuration)
|
||||
return {
|
||||
/**
|
||||
* 按筛选条件导出审计日志为 CSV 附件(UTF-8 BOM,Excel/WPS 可直接打开):筛选参数与 query 完全一致,不分页全量导出,按时间升序输出
|
||||
* @param {Array<string>} [fieldSelector] 等值筛选,可重复(与 query 一致)
|
||||
* @param {string} [result] 结果筛选(success/failure)
|
||||
* @param {string} [keyword] 关键字(resourceName/path 模糊匹配)
|
||||
* @param {string} [startTime] 开始时间(ISO-8601,含边界)
|
||||
* @param {string} [endTime] 结束时间(ISO-8601,含边界)
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async exportAuditLogs(fieldSelector?: Array<string>, result?: string, keyword?: string, startTime?: string, endTime?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<File>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.exportAuditLogs(fieldSelector, result, keyword, startTime, endTime, options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['AuditV1alpha1ConsoleApi.exportAuditLogs']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
/**
|
||||
* 分页查询审计日志:支持等值筛选(fieldSelector,含 spec.action 语义动作)、关键字(resourceName/path 模糊)、结果(success/failure)、时间区间(含边界)
|
||||
* @param {number} [page] 页码(从 1 开始)
|
||||
* @param {number} [size] 每页大小(1-100)
|
||||
* @param {string} [sort] 排序(field,(asc|desc)),仅支持 metadata.creationTimestamp
|
||||
* @param {Array<string>} [fieldSelector] 等值筛选,可重复(spec.username/spec.resourceType/spec.method/spec.action)
|
||||
* @param {string} [result] 结果筛选(success/failure)
|
||||
* @param {string} [keyword] 关键字(resourceName/path 模糊匹配)
|
||||
* @param {string} [startTime] 开始时间(ISO-8601,含边界)
|
||||
* @param {string} [endTime] 结束时间(ISO-8601,含边界)
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async listAuditLogs(page?: number, size?: number, sort?: string, fieldSelector?: Array<string>, result?: string, keyword?: string, startTime?: string, endTime?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<AuditLogList>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.listAuditLogs(page, size, sort, fieldSelector, result, keyword, startTime, endTime, options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['AuditV1alpha1ConsoleApi.listAuditLogs']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
/**
|
||||
* 向当前配置的 Webhook 地址推送一条测试告警(type=test)并返回推送结果:success 为是否送达(接收方 2xx),message 为状态/原因摘要;Webhook 未配置或非法时返回 400
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async testAlertWebhook(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<AlertSendResult>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.testAlertWebhook(options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['AuditV1alpha1ConsoleApi.testAlertWebhook']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* AuditV1alpha1ConsoleApi - factory interface
|
||||
* @export
|
||||
*/
|
||||
export const AuditV1alpha1ConsoleApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
|
||||
const localVarFp = AuditV1alpha1ConsoleApiFp(configuration)
|
||||
return {
|
||||
/**
|
||||
* 按筛选条件导出审计日志为 CSV 附件(UTF-8 BOM,Excel/WPS 可直接打开):筛选参数与 query 完全一致,不分页全量导出,按时间升序输出
|
||||
* @param {AuditV1alpha1ConsoleApiExportAuditLogsRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
exportAuditLogs(requestParameters: AuditV1alpha1ConsoleApiExportAuditLogsRequest = {}, options?: RawAxiosRequestConfig): AxiosPromise<File> {
|
||||
return localVarFp.exportAuditLogs(requestParameters.fieldSelector, requestParameters.result, requestParameters.keyword, requestParameters.startTime, requestParameters.endTime, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
* 分页查询审计日志:支持等值筛选(fieldSelector,含 spec.action 语义动作)、关键字(resourceName/path 模糊)、结果(success/failure)、时间区间(含边界)
|
||||
* @param {AuditV1alpha1ConsoleApiListAuditLogsRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
listAuditLogs(requestParameters: AuditV1alpha1ConsoleApiListAuditLogsRequest = {}, options?: RawAxiosRequestConfig): AxiosPromise<AuditLogList> {
|
||||
return localVarFp.listAuditLogs(requestParameters.page, requestParameters.size, requestParameters.sort, requestParameters.fieldSelector, requestParameters.result, requestParameters.keyword, requestParameters.startTime, requestParameters.endTime, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
* 向当前配置的 Webhook 地址推送一条测试告警(type=test)并返回推送结果:success 为是否送达(接收方 2xx),message 为状态/原因摘要;Webhook 未配置或非法时返回 400
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
testAlertWebhook(options?: RawAxiosRequestConfig): AxiosPromise<AlertSendResult> {
|
||||
return localVarFp.testAlertWebhook(options).then((request) => request(axios, basePath));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Request parameters for exportAuditLogs operation in AuditV1alpha1ConsoleApi.
|
||||
* @export
|
||||
* @interface AuditV1alpha1ConsoleApiExportAuditLogsRequest
|
||||
*/
|
||||
export interface AuditV1alpha1ConsoleApiExportAuditLogsRequest {
|
||||
/**
|
||||
* 等值筛选,可重复(与 query 一致)
|
||||
* @type {Array<string>}
|
||||
* @memberof AuditV1alpha1ConsoleApiExportAuditLogs
|
||||
*/
|
||||
readonly fieldSelector?: Array<string>
|
||||
|
||||
/**
|
||||
* 结果筛选(success/failure)
|
||||
* @type {string}
|
||||
* @memberof AuditV1alpha1ConsoleApiExportAuditLogs
|
||||
*/
|
||||
readonly result?: string
|
||||
|
||||
/**
|
||||
* 关键字(resourceName/path 模糊匹配)
|
||||
* @type {string}
|
||||
* @memberof AuditV1alpha1ConsoleApiExportAuditLogs
|
||||
*/
|
||||
readonly keyword?: string
|
||||
|
||||
/**
|
||||
* 开始时间(ISO-8601,含边界)
|
||||
* @type {string}
|
||||
* @memberof AuditV1alpha1ConsoleApiExportAuditLogs
|
||||
*/
|
||||
readonly startTime?: string
|
||||
|
||||
/**
|
||||
* 结束时间(ISO-8601,含边界)
|
||||
* @type {string}
|
||||
* @memberof AuditV1alpha1ConsoleApiExportAuditLogs
|
||||
*/
|
||||
readonly endTime?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Request parameters for listAuditLogs operation in AuditV1alpha1ConsoleApi.
|
||||
* @export
|
||||
* @interface AuditV1alpha1ConsoleApiListAuditLogsRequest
|
||||
*/
|
||||
export interface AuditV1alpha1ConsoleApiListAuditLogsRequest {
|
||||
/**
|
||||
* 页码(从 1 开始)
|
||||
* @type {number}
|
||||
* @memberof AuditV1alpha1ConsoleApiListAuditLogs
|
||||
*/
|
||||
readonly page?: number
|
||||
|
||||
/**
|
||||
* 每页大小(1-100)
|
||||
* @type {number}
|
||||
* @memberof AuditV1alpha1ConsoleApiListAuditLogs
|
||||
*/
|
||||
readonly size?: number
|
||||
|
||||
/**
|
||||
* 排序(field,(asc|desc)),仅支持 metadata.creationTimestamp
|
||||
* @type {string}
|
||||
* @memberof AuditV1alpha1ConsoleApiListAuditLogs
|
||||
*/
|
||||
readonly sort?: string
|
||||
|
||||
/**
|
||||
* 等值筛选,可重复(spec.username/spec.resourceType/spec.method/spec.action)
|
||||
* @type {Array<string>}
|
||||
* @memberof AuditV1alpha1ConsoleApiListAuditLogs
|
||||
*/
|
||||
readonly fieldSelector?: Array<string>
|
||||
|
||||
/**
|
||||
* 结果筛选(success/failure)
|
||||
* @type {string}
|
||||
* @memberof AuditV1alpha1ConsoleApiListAuditLogs
|
||||
*/
|
||||
readonly result?: string
|
||||
|
||||
/**
|
||||
* 关键字(resourceName/path 模糊匹配)
|
||||
* @type {string}
|
||||
* @memberof AuditV1alpha1ConsoleApiListAuditLogs
|
||||
*/
|
||||
readonly keyword?: string
|
||||
|
||||
/**
|
||||
* 开始时间(ISO-8601,含边界)
|
||||
* @type {string}
|
||||
* @memberof AuditV1alpha1ConsoleApiListAuditLogs
|
||||
*/
|
||||
readonly startTime?: string
|
||||
|
||||
/**
|
||||
* 结束时间(ISO-8601,含边界)
|
||||
* @type {string}
|
||||
* @memberof AuditV1alpha1ConsoleApiListAuditLogs
|
||||
*/
|
||||
readonly endTime?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* AuditV1alpha1ConsoleApi - object-oriented interface
|
||||
* @export
|
||||
* @class AuditV1alpha1ConsoleApi
|
||||
* @extends {BaseAPI}
|
||||
*/
|
||||
export class AuditV1alpha1ConsoleApi extends BaseAPI {
|
||||
/**
|
||||
* 按筛选条件导出审计日志为 CSV 附件(UTF-8 BOM,Excel/WPS 可直接打开):筛选参数与 query 完全一致,不分页全量导出,按时间升序输出
|
||||
* @param {AuditV1alpha1ConsoleApiExportAuditLogsRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof AuditV1alpha1ConsoleApi
|
||||
*/
|
||||
public exportAuditLogs(requestParameters: AuditV1alpha1ConsoleApiExportAuditLogsRequest = {}, options?: RawAxiosRequestConfig) {
|
||||
return AuditV1alpha1ConsoleApiFp(this.configuration).exportAuditLogs(requestParameters.fieldSelector, requestParameters.result, requestParameters.keyword, requestParameters.startTime, requestParameters.endTime, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询审计日志:支持等值筛选(fieldSelector,含 spec.action 语义动作)、关键字(resourceName/path 模糊)、结果(success/failure)、时间区间(含边界)
|
||||
* @param {AuditV1alpha1ConsoleApiListAuditLogsRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof AuditV1alpha1ConsoleApi
|
||||
*/
|
||||
public listAuditLogs(requestParameters: AuditV1alpha1ConsoleApiListAuditLogsRequest = {}, options?: RawAxiosRequestConfig) {
|
||||
return AuditV1alpha1ConsoleApiFp(this.configuration).listAuditLogs(requestParameters.page, requestParameters.size, requestParameters.sort, requestParameters.fieldSelector, requestParameters.result, requestParameters.keyword, requestParameters.startTime, requestParameters.endTime, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* 向当前配置的 Webhook 地址推送一条测试告警(type=test)并返回推送结果:success 为是否送达(接收方 2xx),message 为状态/原因摘要;Webhook 未配置或非法时返回 400
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof AuditV1alpha1ConsoleApi
|
||||
*/
|
||||
public testAlertWebhook(options?: RawAxiosRequestConfig) {
|
||||
return AuditV1alpha1ConsoleApiFp(this.configuration).testAlertWebhook(options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import type { Configuration } from './configuration';
|
||||
// Some imports not used depending on template conditions
|
||||
// @ts-ignore
|
||||
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
|
||||
import globalAxios from 'axios';
|
||||
|
||||
export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const COLLECTION_FORMATS = {
|
||||
csv: ",",
|
||||
ssv: " ",
|
||||
tsv: "\t",
|
||||
pipes: "|",
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface RequestArgs
|
||||
*/
|
||||
export interface RequestArgs {
|
||||
url: string;
|
||||
options: RawAxiosRequestConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @class BaseAPI
|
||||
*/
|
||||
export class BaseAPI {
|
||||
protected configuration: Configuration | undefined;
|
||||
|
||||
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
this.basePath = configuration.basePath ?? basePath;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @class RequiredError
|
||||
* @extends {Error}
|
||||
*/
|
||||
export class RequiredError extends Error {
|
||||
constructor(public field: string, msg?: string) {
|
||||
super(msg);
|
||||
this.name = "RequiredError"
|
||||
}
|
||||
}
|
||||
|
||||
interface ServerMap {
|
||||
[key: string]: {
|
||||
url: string,
|
||||
description: string,
|
||||
}[];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const operationServerMap: ServerMap = {
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import type { Configuration } from "./configuration";
|
||||
import type { RequestArgs } from "./base";
|
||||
import type { AxiosInstance, AxiosResponse } from 'axios';
|
||||
import { RequiredError } from "./base";
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const DUMMY_BASE_URL = 'https://example.com'
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws {RequiredError}
|
||||
* @export
|
||||
*/
|
||||
export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
|
||||
if (paramValue === null || paramValue === undefined) {
|
||||
throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
|
||||
if (configuration && configuration.apiKey) {
|
||||
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
|
||||
? await configuration.apiKey(keyParamName)
|
||||
: await configuration.apiKey;
|
||||
object[keyParamName] = localVarApiKeyValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
|
||||
if (configuration && (configuration.username || configuration.password)) {
|
||||
object["auth"] = { username: configuration.username, password: configuration.password };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
|
||||
if (configuration && configuration.accessToken) {
|
||||
const accessToken = typeof configuration.accessToken === 'function'
|
||||
? await configuration.accessToken()
|
||||
: await configuration.accessToken;
|
||||
object["Authorization"] = "Bearer " + accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
|
||||
if (configuration && configuration.accessToken) {
|
||||
const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
|
||||
? await configuration.accessToken(name, scopes)
|
||||
: await configuration.accessToken;
|
||||
object["Authorization"] = "Bearer " + localVarAccessTokenValue;
|
||||
}
|
||||
}
|
||||
|
||||
function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void {
|
||||
if (parameter == null) return;
|
||||
if (typeof parameter === "object") {
|
||||
if (Array.isArray(parameter)) {
|
||||
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
|
||||
}
|
||||
else {
|
||||
Object.keys(parameter).forEach(currentKey =>
|
||||
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (urlSearchParams.has(key)) {
|
||||
urlSearchParams.append(key, parameter);
|
||||
}
|
||||
else {
|
||||
urlSearchParams.set(key, parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setSearchParams = function (url: URL, ...objects: any[]) {
|
||||
const searchParams = new URLSearchParams(url.search);
|
||||
setFlattenedQueryParams(searchParams, objects);
|
||||
url.search = searchParams.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
|
||||
const nonString = typeof value !== 'string';
|
||||
const needsSerialization = nonString && configuration && configuration.isJsonMime
|
||||
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
||||
: nonString;
|
||||
return needsSerialization
|
||||
? JSON.stringify(value !== undefined ? value : {})
|
||||
: (value || "");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const toPathString = function (url: URL) {
|
||||
return url.pathname + url.search + url.hash
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
|
||||
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
||||
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
|
||||
return axios.request<T, R>(axiosRequestArgs);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export interface ConfigurationParameters {
|
||||
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
||||
username?: string;
|
||||
password?: string;
|
||||
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
|
||||
basePath?: string;
|
||||
serverIndex?: number;
|
||||
baseOptions?: any;
|
||||
formDataCtor?: new () => any;
|
||||
}
|
||||
|
||||
export class Configuration {
|
||||
/**
|
||||
* parameter for apiKey security
|
||||
* @param name security name
|
||||
* @memberof Configuration
|
||||
*/
|
||||
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* parameter for oauth2 security
|
||||
* @param name security name
|
||||
* @param scopes oauth2 scope
|
||||
* @memberof Configuration
|
||||
*/
|
||||
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
|
||||
/**
|
||||
* override base path
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
basePath?: string;
|
||||
/**
|
||||
* override server index
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
serverIndex?: number;
|
||||
/**
|
||||
* base options for axios calls
|
||||
*
|
||||
* @type {any}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
baseOptions?: any;
|
||||
/**
|
||||
* The FormData constructor that will be used to create multipart form data
|
||||
* requests. You can inject this here so that execution environments that
|
||||
* do not support the FormData class can still run the generated client.
|
||||
*
|
||||
* @type {new () => FormData}
|
||||
*/
|
||||
formDataCtor?: new () => any;
|
||||
|
||||
constructor(param: ConfigurationParameters = {}) {
|
||||
this.apiKey = param.apiKey;
|
||||
this.username = param.username;
|
||||
this.password = param.password;
|
||||
this.accessToken = param.accessToken;
|
||||
this.basePath = param.basePath;
|
||||
this.serverIndex = param.serverIndex;
|
||||
this.baseOptions = param.baseOptions;
|
||||
this.formDataCtor = param.formDataCtor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given MIME is a JSON MIME.
|
||||
* JSON MIME examples:
|
||||
* application/json
|
||||
* application/json; charset=UTF8
|
||||
* APPLICATION/JSON
|
||||
* application/vnd.company+json
|
||||
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
||||
* @return True if the given MIME is JSON, false otherwise.
|
||||
*/
|
||||
public isJsonMime(mime: string): boolean {
|
||||
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
||||
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||
#
|
||||
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
|
||||
|
||||
git_user_id=$1
|
||||
git_repo_id=$2
|
||||
release_note=$3
|
||||
git_host=$4
|
||||
|
||||
if [ "$git_host" = "" ]; then
|
||||
git_host="github.com"
|
||||
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
|
||||
fi
|
||||
|
||||
if [ "$git_user_id" = "" ]; then
|
||||
git_user_id="GIT_USER_ID"
|
||||
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||
fi
|
||||
|
||||
if [ "$git_repo_id" = "" ]; then
|
||||
git_repo_id="GIT_REPO_ID"
|
||||
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||
fi
|
||||
|
||||
if [ "$release_note" = "" ]; then
|
||||
release_note="Minor update"
|
||||
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
||||
fi
|
||||
|
||||
# Initialize the local directory as a Git repository
|
||||
git init
|
||||
|
||||
# Adds the files in the local repository and stages them for commit.
|
||||
git add .
|
||||
|
||||
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
||||
git commit -m "$release_note"
|
||||
|
||||
# Sets the new remote
|
||||
git_remote=$(git remote)
|
||||
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||
|
||||
if [ "$GIT_TOKEN" = "" ]; then
|
||||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
|
||||
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
|
||||
else
|
||||
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
git pull origin master
|
||||
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
@@ -0,0 +1,18 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export * from "./api";
|
||||
export * from "./configuration";
|
||||
export * from "./models";
|
||||
@@ -0,0 +1,36 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Webhook 推送结果(成功为接收方 2xx;失败时 message 携带原因摘要)
|
||||
* @export
|
||||
* @interface AlertSendResult
|
||||
*/
|
||||
export interface AlertSendResult {
|
||||
/**
|
||||
* 是否送达(接收方 2xx)
|
||||
* @type {boolean}
|
||||
* @memberof AlertSendResult
|
||||
*/
|
||||
'success': boolean;
|
||||
/**
|
||||
* 成功时为响应状态摘要(如 HTTP 200),失败时为原因摘要
|
||||
* @type {string}
|
||||
* @memberof AlertSendResult
|
||||
*/
|
||||
'message': string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
// May contain unused imports in some cases
|
||||
// @ts-ignore
|
||||
import type { AuditLog } from './audit-log';
|
||||
|
||||
/**
|
||||
* 审计日志分页结果(ListResult<AuditLog>)
|
||||
* @export
|
||||
* @interface AuditLogList
|
||||
*/
|
||||
export interface AuditLogList {
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof AuditLogList
|
||||
*/
|
||||
'page': number;
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof AuditLogList
|
||||
*/
|
||||
'size': number;
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof AuditLogList
|
||||
*/
|
||||
'total': number;
|
||||
/**
|
||||
*
|
||||
* @type {Array<AuditLog>}
|
||||
* @memberof AuditLogList
|
||||
*/
|
||||
'items': Array<AuditLog>;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof AuditLogList
|
||||
*/
|
||||
'first'?: boolean;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof AuditLogList
|
||||
*/
|
||||
'last'?: boolean;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof AuditLogList
|
||||
*/
|
||||
'hasNext'?: boolean;
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof AuditLogList
|
||||
*/
|
||||
'hasPrevious'?: boolean;
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof AuditLogList
|
||||
*/
|
||||
'totalPages'?: number;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
// May contain unused imports in some cases
|
||||
// @ts-ignore
|
||||
import type { ChangeEntry } from './change-entry';
|
||||
|
||||
/**
|
||||
* 审计日志业务字段(spec)
|
||||
* @export
|
||||
* @interface AuditLogSpec
|
||||
*/
|
||||
export interface AuditLogSpec {
|
||||
/**
|
||||
* 操作者用户名;登录失败记 unknown
|
||||
* @type {string}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'username': string;
|
||||
/**
|
||||
* 登录尝试的用户名(仅 POST /login 白名单提取落库);提取失败或非登录请求为 null
|
||||
* @type {string}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'attemptedUsername'?: string | null;
|
||||
/**
|
||||
* HTTP 方法(动作),如 POST/PUT/DELETE/PATCH
|
||||
* @type {string}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'method': string;
|
||||
/**
|
||||
* 语义动作键(捕获时标注落库);旧版本写入的历史记录可能缺失
|
||||
* @type {string}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'action'?: string | null;
|
||||
/**
|
||||
* 资源类型(复数形式,如 posts/comments/users/auth)
|
||||
* @type {string}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'resourceType': string;
|
||||
/**
|
||||
* 资源名称;集合级操作或登录端点为空
|
||||
* @type {string}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'resourceName'?: string | null;
|
||||
/**
|
||||
* 完整请求路径(含查询串)
|
||||
* @type {string}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'path': string;
|
||||
/**
|
||||
* 响应状态码(结果:2xx 成功,其余失败)
|
||||
* @type {number}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'statusCode': number;
|
||||
/**
|
||||
* 来源 IP
|
||||
* @type {string}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'remoteIp': string;
|
||||
/**
|
||||
* User-Agent;系统内部变更记录为 null
|
||||
* @type {string}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'userAgent'?: string | null;
|
||||
/**
|
||||
* 字段级变更列表;历史记录或不可捕获场景缺失
|
||||
* @type {Array<ChangeEntry>}
|
||||
* @memberof AuditLogSpec
|
||||
*/
|
||||
'changes'?: Array<ChangeEntry> | null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
// May contain unused imports in some cases
|
||||
// @ts-ignore
|
||||
import type { AuditLogSpec } from './audit-log-spec';
|
||||
// May contain unused imports in some cases
|
||||
// @ts-ignore
|
||||
import type { Metadata } from './metadata';
|
||||
|
||||
/**
|
||||
* 审计日志自定义模型(Extension,group audit.guichumo.com/v1alpha1)
|
||||
* @export
|
||||
* @interface AuditLog
|
||||
*/
|
||||
export interface AuditLog {
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof AuditLog
|
||||
*/
|
||||
'apiVersion': string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof AuditLog
|
||||
*/
|
||||
'kind': string;
|
||||
/**
|
||||
*
|
||||
* @type {Metadata}
|
||||
* @memberof AuditLog
|
||||
*/
|
||||
'metadata': Metadata;
|
||||
/**
|
||||
*
|
||||
* @type {AuditLogSpec}
|
||||
* @memberof AuditLog
|
||||
*/
|
||||
'spec': AuditLogSpec;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
// May contain unused imports in some cases
|
||||
// @ts-ignore
|
||||
import type { ChangeType } from './change-type';
|
||||
|
||||
/**
|
||||
* 字段级变更条目(新旧值均已在后端脱敏与截断;缺失侧为 null)
|
||||
* @export
|
||||
* @interface ChangeEntry
|
||||
*/
|
||||
export interface ChangeEntry {
|
||||
/**
|
||||
* 字段路径(点号分隔,如 spec.title)
|
||||
* @type {string}
|
||||
* @memberof ChangeEntry
|
||||
*/
|
||||
'field': string;
|
||||
/**
|
||||
*
|
||||
* @type {ChangeType}
|
||||
* @memberof ChangeEntry
|
||||
*/
|
||||
'changeType': ChangeType;
|
||||
/**
|
||||
* 变更前的值;字段为新增时缺失
|
||||
* @type {string}
|
||||
* @memberof ChangeEntry
|
||||
*/
|
||||
'oldValue'?: string | null;
|
||||
/**
|
||||
* 变更后的值;字段被移除时缺失
|
||||
* @type {string}
|
||||
* @memberof ChangeEntry
|
||||
*/
|
||||
'newValue'?: string | null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 字段级变更类型(新增/修改/删除)
|
||||
* @export
|
||||
* @enum {string}
|
||||
*/
|
||||
|
||||
export const ChangeType = {
|
||||
Added: 'ADDED',
|
||||
Updated: 'UPDATED',
|
||||
Removed: 'REMOVED'
|
||||
} as const;
|
||||
|
||||
export type ChangeType = typeof ChangeType[keyof typeof ChangeType];
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export * from './alert-send-result';
|
||||
export * from './audit-log';
|
||||
export * from './audit-log-list';
|
||||
export * from './audit-log-spec';
|
||||
export * from './change-entry';
|
||||
export * from './change-type';
|
||||
export * from './metadata';
|
||||
@@ -0,0 +1,72 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Operation Audit Extension API
|
||||
* 操作审计插件自有子资源端点(query/export/test)的 OpenAPI 契约。本文件为 bootstrap 契约(与 SpringdocRouteBuilder 声明一一对应手工对齐),供 devtools generateApiClient 离线生成 TS 客户端;待有可用的 Halo 实例(Docker haloServer 或 useExistingServer)时,运行 ./gradlew generateOpenApiDocs 将以运行时 springdoc 输出覆盖本文件,再重新生成客户端即可(generateApiClient 每次先清空 outputDir)。版本号与插件版本保持同步。
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 扩展资源元数据(run.halo.app.extension.Metadata)
|
||||
* @export
|
||||
* @interface Metadata
|
||||
*/
|
||||
export interface Metadata {
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Metadata
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Metadata
|
||||
*/
|
||||
'generateName'?: string;
|
||||
/**
|
||||
*
|
||||
* @type {{ [key: string]: string; }}
|
||||
* @memberof Metadata
|
||||
*/
|
||||
'labels'?: { [key: string]: string; };
|
||||
/**
|
||||
*
|
||||
* @type {{ [key: string]: string; }}
|
||||
* @memberof Metadata
|
||||
*/
|
||||
'annotations'?: { [key: string]: string; };
|
||||
/**
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof Metadata
|
||||
*/
|
||||
'version'?: number;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Metadata
|
||||
*/
|
||||
'creationTimestamp': string;
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Metadata
|
||||
*/
|
||||
'deletionTimestamp'?: string | null;
|
||||
/**
|
||||
*
|
||||
* @type {Array<string>}
|
||||
* @memberof Metadata
|
||||
*/
|
||||
'finalizers'?: Array<string>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { axiosInstance } from '@halo-dev/api-client'
|
||||
import { AuditV1alpha1ConsoleApi } from './generated'
|
||||
|
||||
/**
|
||||
* 插件 API 客户端封装(官方 api-request 指南):
|
||||
*
|
||||
* <p>TS 类型与请求方法来自 {@link ./generated}(devtools `generateApiClient` 产物,
|
||||
* 由 build.gradle 的 openApi 管线从 Springdoc 声明生成),禁止手写或改动生成内容;
|
||||
* API 契约变更一律修改后端 SpringdocRouteBuilder 声明后重新生成。
|
||||
*
|
||||
* <p>生成类实例复用宿主 {@link axiosInstance}(自带登录态、权限失败与统一错误处理),
|
||||
* 不得另行 axios.create() 直连 /api、/apis。
|
||||
*/
|
||||
const auditApiClient = {
|
||||
audit: new AuditV1alpha1ConsoleApi(undefined, '', axiosInstance),
|
||||
}
|
||||
|
||||
export { auditApiClient }
|
||||
@@ -4,31 +4,32 @@ import { describe, expect, it } from 'vitest'
|
||||
|
||||
// 结构性回归测试:不渲染组件,仅检查 SFC 源码中的测试告警链路。
|
||||
// 「发送测试告警」为插件设置「告警通知」区的自定义 FormKit 输入(功能评审 P0-2):
|
||||
// 点击 → POST 测试告警端点(无请求体)→ 同步反馈结果提示(成功/失败两色),
|
||||
// 点击 → 生成客户端 testAlertWebhook(端点路径由后端 Springdoc 声明经
|
||||
// generateApiClient 生成,禁止手写)→ 同步反馈结果提示(成功/失败两色),
|
||||
// 期间按钮 loading。历史上验证 webhook 配置只能等真实告警触发,本测试锁定
|
||||
// 端点路径与反馈链路形态,防止路径漂移或链路残缺。
|
||||
// 生成客户端链路与反馈形态,防止链路残缺或退回裸 fetch。
|
||||
const sfc = readFileSync(
|
||||
fileURLToPath(new URL('./TestAlertButton.vue', import.meta.url)),
|
||||
'utf-8',
|
||||
)
|
||||
|
||||
describe('TestAlertButton 测试告警', () => {
|
||||
it('声明与后端一致的测试告警端点路径', () => {
|
||||
expect(sfc).toContain(
|
||||
"const TEST_ALERT_ENDPOINT = '/apis/audit.guichumo.com/v1alpha1/alerts/-/test'",
|
||||
)
|
||||
it('经生成客户端调用测试端点(不手写端点路径、不裸 fetch)', () => {
|
||||
expect(sfc).toContain('auditApiClient.audit.testAlertWebhook()')
|
||||
expect(sfc).not.toContain('/apis/audit.guichumo.com')
|
||||
expect(sfc).not.toMatch(/\bfetch\(/)
|
||||
})
|
||||
|
||||
it('点击 POST 测试告警端点,按钮 loading、防重复点击', () => {
|
||||
expect(sfc).toContain("await fetch(TEST_ALERT_ENDPOINT, { method: 'POST' })")
|
||||
it('点击触发推送,按钮 loading、防重复点击', () => {
|
||||
expect(sfc).toContain('if (sending.value)')
|
||||
expect(sfc).toMatch(/<VButton :loading="sending"[^>]*@click="sendTestAlert">/)
|
||||
expect(sfc).toContain('发送测试告警')
|
||||
})
|
||||
|
||||
it('推送结果以提示反馈:成功/失败两色,非 2xx 抛出后进失败提示', () => {
|
||||
expect(sfc).toContain('hintType.value = body.success ? \'success\' : \'error\'')
|
||||
expect(sfc).toMatch(/throw new Error\(body\.message \|\| `发送失败(HTTP \$\{response\.status\})`\)/)
|
||||
it('推送结果以提示反馈:成功/失败两色,HTTP 400 消息取后端返回的 message', () => {
|
||||
expect(sfc).toContain("hintType.value = data.success ? 'success' : 'error'")
|
||||
expect(sfc).toContain("hint.value = data.success ? `发送成功(${data.message})`")
|
||||
expect(sfc).toContain('axiosError?.response?.data?.message')
|
||||
expect(sfc).toContain("hintType.value = 'error'")
|
||||
expect(sfc).toContain('hint-success')
|
||||
expect(sfc).toContain('hint-error')
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { VButton } from '@halo-dev/components'
|
||||
import { auditApiClient } from '@/api'
|
||||
|
||||
/**
|
||||
* 「发送测试告警」自定义 FormKit 输入(功能评审 P0-2):
|
||||
* 在插件设置「告警通知」区提供手动推送入口——向当前已保存的 Webhook 地址
|
||||
* 推送一条 type=test 测试消息,并同步反馈发送结果(成功/失败 + 原因摘要)。
|
||||
* 不承载任何配置值(settings.yaml 中以 ignore: true 声明,不新增设置项)。
|
||||
* (存于 Halo Secret,设置仅持引用)推送一条 type=test 测试消息,并同步反馈
|
||||
* 发送结果(成功/失败 + 原因摘要)。不承载任何配置值(settings.yaml 中以
|
||||
* ignore: true 声明,不新增设置项)。
|
||||
*
|
||||
* <p>经生成客户端调用测试端点(ui/src/api/generated,generateApiClient 产物):
|
||||
* 400(地址未配置/Secret 缺字段等)与网络失败均归一进失败提示,信息优先取
|
||||
* 后端返回的 message。
|
||||
*/
|
||||
|
||||
/** 测试告警端点(与后端 AlertTestEndpoint 保持一致)。 */
|
||||
const TEST_ALERT_ENDPOINT = '/apis/audit.guichumo.com/v1alpha1/alerts/-/test'
|
||||
|
||||
const sending = ref(false)
|
||||
const hint = ref('')
|
||||
const hintType = ref<'success' | 'error'>('success')
|
||||
@@ -23,16 +25,19 @@ async function sendTestAlert() {
|
||||
sending.value = true
|
||||
hint.value = ''
|
||||
try {
|
||||
const response = await fetch(TEST_ALERT_ENDPOINT, { method: 'POST' })
|
||||
const body = (await response.json()) as { success?: boolean; message?: string }
|
||||
if (!response.ok) {
|
||||
throw new Error(body.message || `发送失败(HTTP ${response.status})`)
|
||||
}
|
||||
hintType.value = body.success ? 'success' : 'error'
|
||||
hint.value = body.success ? `发送成功(${body.message})` : `发送失败:${body.message}`
|
||||
const { data } = await auditApiClient.audit.testAlertWebhook()
|
||||
hintType.value = data.success ? 'success' : 'error'
|
||||
hint.value = data.success ? `发送成功(${data.message})` : `发送失败:${data.message}`
|
||||
} catch (e) {
|
||||
hintType.value = 'error'
|
||||
hint.value = e instanceof Error ? e.message : String(e)
|
||||
const axiosError = e as { response?: { status?: number; data?: { message?: string } } }
|
||||
hint.value =
|
||||
axiosError?.response?.data?.message ||
|
||||
(axiosError?.response?.status
|
||||
? `发送失败(HTTP ${axiosError.response.status})`
|
||||
: e instanceof Error
|
||||
? e.message
|
||||
: String(e))
|
||||
} finally {
|
||||
sending.value = false
|
||||
}
|
||||
|
||||
@@ -1,58 +1,14 @@
|
||||
/**
|
||||
* 审计日志的类型定义与展示辅助。
|
||||
* 审计日志的展示辅助。
|
||||
*
|
||||
* <p>模型类型(AuditLog/AuditLogSpec/ChangeEntry/ChangeType 等)不再在此手写,
|
||||
* 一律从 `@/api/generated` 导入(devtools generateApiClient 产物,与后端契约同源);
|
||||
* 本文件只保留展示与推导逻辑。
|
||||
*/
|
||||
import type { AuditLogSpec, ChangeType } from '@/api/generated'
|
||||
|
||||
export interface AuditLogSpec {
|
||||
username: string
|
||||
/** 登录尝试的用户名(功能评审 P0-1):仅 POST /login 请求提取落库,其余为 null。 */
|
||||
attemptedUsername?: string | null
|
||||
method: string
|
||||
resourceType: string
|
||||
resourceName?: string | null
|
||||
path: string
|
||||
/** 语义动作键(语义动作标注,如 login/create/publish);旧版本写入的历史记录可能缺失。 */
|
||||
action?: string | null
|
||||
statusCode: number
|
||||
remoteIp: string
|
||||
userAgent?: string | null
|
||||
/** 字段级变更列表(字段级变更 diff);历史记录或不可捕获场景缺失。 */
|
||||
changes?: AuditLogChange[] | null
|
||||
}
|
||||
|
||||
/** 字段级变更类型(与后端 ChangeType 一致)。 */
|
||||
export type AuditLogChangeType = 'ADDED' | 'UPDATED' | 'REMOVED'
|
||||
|
||||
/** 字段级变更条目(新旧值均已在后端脱敏与截断)。 */
|
||||
export interface AuditLogChange {
|
||||
/** 字段路径(点号分隔,如 spec.title)。 */
|
||||
field: string
|
||||
changeType: AuditLogChangeType
|
||||
/** 变更前的值;字段为新增时缺失。 */
|
||||
oldValue?: string | null
|
||||
/** 变更后的值;字段被移除时缺失。 */
|
||||
newValue?: 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
|
||||
}
|
||||
/** 展示与推导逻辑使用的审计日志 spec 类型(generated 模型)。 */
|
||||
export type { AuditLogSpec }
|
||||
|
||||
export const UNKNOWN_USERNAME = 'unknown'
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { VButton, VSpace } from '@halo-dev/components'
|
||||
import type { AuditLog, AuditLogChangeType } from '@/utils/audit'
|
||||
import type { AuditLog, ChangeType } from '@/api/generated'
|
||||
import {
|
||||
changeTypeLabel,
|
||||
changeValueDisplay,
|
||||
@@ -34,7 +34,7 @@ const resultText = computed(() => {
|
||||
const changes = computed(() => props.log?.spec.changes ?? [])
|
||||
|
||||
const changeBadgeClass = (changeType?: string | null): string => {
|
||||
switch (changeType as AuditLogChangeType) {
|
||||
switch (changeType as ChangeType) {
|
||||
case 'ADDED':
|
||||
return 'change-added'
|
||||
case 'REMOVED':
|
||||
|
||||
@@ -3,52 +3,47 @@ import { fileURLToPath } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
// 结构性回归测试:不渲染组件,仅检查 SFC 源码中的导出功能链路。
|
||||
// 导出为按当前筛选条件的全量 CSV 下载:工具栏「导出」按钮 → fetch 导出端点
|
||||
// (筛选参数与 query 一致,但去掉分页参数)→ blob 触发 a[download] 下载,
|
||||
// 期间按钮进入 loading、失败走顶部 VAlert 错误提示。
|
||||
// 历史上本功能不存在,本测试锁定端点路径与下载链路形态,防止路径漂移或链路残缺。
|
||||
// 导出为按当前筛选条件的全量 CSV 下载:工具栏「导出」按钮 → 生成客户端
|
||||
// exportAuditLogs(responseType: 'blob',端点路径与参数由 generateApiClient
|
||||
// 从后端声明生成,禁止手写)→ blob 触发 a[download] 下载,期间按钮进入 loading、
|
||||
// 失败走顶部 VAlert 错误提示。本测试锁定生成客户端链路形态与下载行为,
|
||||
// 防止链路残缺或退回裸 fetch。
|
||||
const sfc = readFileSync(fileURLToPath(new URL('./AuditLogList.vue', import.meta.url)), 'utf-8')
|
||||
|
||||
describe('AuditLogList 导出', () => {
|
||||
it('声明与后端一致的导出端点路径', () => {
|
||||
expect(sfc).toContain(
|
||||
"const EXPORT_ENDPOINT =\n '/apis/audit.guichumo.com/v1alpha1/auditlogs/-/export'",
|
||||
)
|
||||
it('经生成客户端导出(不手写端点路径、不裸 fetch)', () => {
|
||||
expect(sfc).toContain('auditApiClient.audit.exportAuditLogs(exportRequest')
|
||||
// 端点路径由生成客户端承载,SFC 不再出现硬编码路径
|
||||
expect(sfc).not.toContain('/apis/audit.guichumo.com')
|
||||
expect(sfc).not.toMatch(/\bfetch\(/)
|
||||
})
|
||||
|
||||
it('工具栏导出按钮:IconSave 图标、loading 绑定 exporting、点击 exportLogs', () => {
|
||||
// 导出按钮位于 VPageHeader #actions 的 VSpace 内,与「刷新」并列
|
||||
const actionsStart = sfc.indexOf('<template #actions>')
|
||||
expect(actionsStart).toBeGreaterThan(-1)
|
||||
const actionsEnd = sfc.indexOf('</VSpace>', actionsStart)
|
||||
const actions = sfc.slice(actionsStart, actionsEnd)
|
||||
expect(actions).toMatch(/<VButton :loading="exporting"[^>]*@click="exportLogs">/)
|
||||
expect(actions).toContain('<IconSave class="h-full w-full" />')
|
||||
expect(actions).toContain('导出')
|
||||
expect(actions).toContain('刷新')
|
||||
})
|
||||
|
||||
it('导出前去掉分页参数(导出为全量接口)', () => {
|
||||
it('导出请求复用查询筛选条件且不带分页参数(导出为全量接口)', () => {
|
||||
const fnStart = sfc.indexOf('async function exportLogs()')
|
||||
expect(fnStart).toBeGreaterThan(-1)
|
||||
const fn = sfc.slice(fnStart, sfc.indexOf('function resetFilter()', fnStart))
|
||||
expect(fn).toContain('new URLSearchParams(buildQuery())')
|
||||
expect(fn).toContain("params.delete('page')")
|
||||
expect(fn).toContain("params.delete('size')")
|
||||
expect(fn).toContain('const request = listRequest()')
|
||||
expect(fn).toContain('AuditV1alpha1ConsoleApiExportAuditLogsRequest')
|
||||
expect(fn).toContain('fieldSelector: request.fieldSelector')
|
||||
expect(fn).toContain('startTime: request.startTime')
|
||||
expect(fn).not.toContain('page: request.page')
|
||||
expect(fn).not.toContain('size: request.size')
|
||||
})
|
||||
|
||||
it('下载链路:fetch 非 ok 报错进 VAlert,blob → createObjectURL → a[download]', () => {
|
||||
it('二进制响应以 blob 请求(CSV 附件下载)', () => {
|
||||
const fnStart = sfc.indexOf('async function exportLogs()')
|
||||
const fn = sfc.slice(fnStart, sfc.indexOf('function resetFilter()', fnStart))
|
||||
// 错误语义与查询一致:HTTP 非 2xx 抛错并写入 error(顶部 VAlert 展示)
|
||||
expect(fn).toMatch(/throw new Error\(`导出失败(HTTP \$\{response\.status\})`\)/)
|
||||
expect(fn).toContain('error.value = e instanceof Error ? e.message : String(e)')
|
||||
expect(fn).toContain('await response.blob()')
|
||||
expect(fn).toContain("responseType: 'blob'")
|
||||
expect(fn).toContain('URL.createObjectURL(blob)')
|
||||
expect(fn).toMatch(/anchor\.download = exportFilename\(\)/)
|
||||
expect(fn).toContain('anchor.click()')
|
||||
expect(fn).toContain('URL.revokeObjectURL(url)')
|
||||
// 无论成败都复位按钮 loading
|
||||
})
|
||||
|
||||
it('失败进顶部 VAlert:错误摘要写 error,无论成败都复位按钮 loading', () => {
|
||||
const fnStart = sfc.indexOf('async function exportLogs()')
|
||||
const fn = sfc.slice(fnStart, sfc.indexOf('function resetFilter()', fnStart))
|
||||
expect(fn).toContain("error.value = errorMessage(e, '导出失败')")
|
||||
expect(fn).toMatch(/finally\s*\{\s*exporting\.value = false\s*\}/)
|
||||
})
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ describe('AuditLogList 查看该资源历史', () => {
|
||||
})
|
||||
|
||||
it('不新增后端参数:复用现有 resourceType fieldSelector 与 keyword 模糊匹配', () => {
|
||||
// 与现有筛选/导出条件共用同一套状态——buildQuery 生成相同参数形态
|
||||
expect(sfc).toContain("params.append('fieldSelector', `spec.resourceType=${filterResourceType.value}`)")
|
||||
expect(sfc).toContain("params.set('keyword', filterKeyword.value.trim())")
|
||||
// 与现有筛选/导出条件共用同一套状态——listRequest 生成相同参数形态(生成客户端请求对象)
|
||||
expect(sfc).toContain('fieldSelector.push(`spec.resourceType=${filterResourceType.value}`)')
|
||||
expect(sfc).toContain('keyword: filterKeyword.value.trim() || undefined')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,7 +14,12 @@ import {
|
||||
IconRefreshLine,
|
||||
IconSave,
|
||||
} from '@halo-dev/components'
|
||||
import type { AuditLog, ListResult } from '@/utils/audit'
|
||||
import type {
|
||||
AuditLog,
|
||||
AuditV1alpha1ConsoleApiExportAuditLogsRequest,
|
||||
AuditV1alpha1ConsoleApiListAuditLogsRequest,
|
||||
} from '@/api/generated'
|
||||
import { auditApiClient } from '@/api'
|
||||
import {
|
||||
describeOperation,
|
||||
displayUsername,
|
||||
@@ -26,13 +31,8 @@ import {
|
||||
} from '@/utils/audit'
|
||||
import AuditLogDetail from './AuditLogDetail.vue'
|
||||
|
||||
/** 查询端点路径(与 AuditQueryEndpoint 保持一致)。 */
|
||||
const QUERY_ENDPOINT =
|
||||
'/apis/audit.guichumo.com/v1alpha1/auditlogs/-/query'
|
||||
|
||||
/** 导出端点路径:筛选参数与 query 一致,全量 CSV 附件下载(与 AuditQueryEndpoint 保持一致)。 */
|
||||
const EXPORT_ENDPOINT =
|
||||
'/apis/audit.guichumo.com/v1alpha1/auditlogs/-/export'
|
||||
// 查询/导出走生成客户端(ui/src/api/generated,generateApiClient 产物):
|
||||
// 端点路径与参数由后端 Springdoc 声明生成,禁止在此手写或覆盖。
|
||||
|
||||
const RESOURCE_TYPES = [
|
||||
'posts', 'comments', 'users', 'roles', 'auth', 'settings', 'configmaps',
|
||||
@@ -73,54 +73,52 @@ const hasActiveFilter = computed(
|
||||
filterEndTime.value,
|
||||
)
|
||||
|
||||
function buildQuery(): string {
|
||||
const params = new URLSearchParams()
|
||||
params.set('page', String(page.value))
|
||||
params.set('size', String(size.value))
|
||||
params.set('sort', 'metadata.creationTimestamp,desc')
|
||||
/** 查询请求对象(与后端 AuditQueryEndpoint 声明一致的生成参数形态)。 */
|
||||
function listRequest(): AuditV1alpha1ConsoleApiListAuditLogsRequest {
|
||||
const fieldSelector: string[] = []
|
||||
if (filterUsername.value.trim()) {
|
||||
params.append('fieldSelector', `spec.username=${filterUsername.value.trim()}`)
|
||||
fieldSelector.push(`spec.username=${filterUsername.value.trim()}`)
|
||||
}
|
||||
if (filterResourceType.value) {
|
||||
params.append('fieldSelector', `spec.resourceType=${filterResourceType.value}`)
|
||||
fieldSelector.push(`spec.resourceType=${filterResourceType.value}`)
|
||||
}
|
||||
if (filterMethod.value) {
|
||||
params.append('fieldSelector', `spec.method=${filterMethod.value}`)
|
||||
fieldSelector.push(`spec.method=${filterMethod.value}`)
|
||||
}
|
||||
// 语义动作筛选(spec.action,捕获时标注落库;历史记录无标注不会被筛出)
|
||||
if (filterAction.value) {
|
||||
params.append('fieldSelector', `spec.action=${filterAction.value}`)
|
||||
fieldSelector.push(`spec.action=${filterAction.value}`)
|
||||
}
|
||||
if (filterResult.value) {
|
||||
params.set('result', filterResult.value)
|
||||
return {
|
||||
page: page.value,
|
||||
size: size.value,
|
||||
sort: 'metadata.creationTimestamp,desc',
|
||||
fieldSelector,
|
||||
result: filterResult.value || undefined,
|
||||
keyword: filterKeyword.value.trim() || undefined,
|
||||
startTime: localDateTimeToInstant(filterStartTime.value) ?? undefined,
|
||||
endTime: localDateTimeToInstant(filterEndTime.value) ?? undefined,
|
||||
}
|
||||
if (filterKeyword.value.trim()) {
|
||||
params.set('keyword', filterKeyword.value.trim())
|
||||
}
|
||||
|
||||
/** 统一错误摘要:HTTP 错误取状态码(沿用旧 fetch 行为),其余取消息原文。 */
|
||||
function errorMessage(e: unknown, action: string): string {
|
||||
const status = (e as { response?: { status?: number } })?.response?.status
|
||||
if (status) {
|
||||
return `${action}(HTTP ${status})`
|
||||
}
|
||||
const start = localDateTimeToInstant(filterStartTime.value)
|
||||
const end = localDateTimeToInstant(filterEndTime.value)
|
||||
if (start) {
|
||||
params.set('startTime', start)
|
||||
}
|
||||
if (end) {
|
||||
params.set('endTime', end)
|
||||
}
|
||||
return params.toString()
|
||||
return e instanceof Error ? e.message : String(e)
|
||||
}
|
||||
|
||||
async function fetchLogs() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const response = await fetch(`${QUERY_ENDPOINT}?${buildQuery()}`)
|
||||
if (!response.ok) {
|
||||
throw new Error(`查询失败(HTTP ${response.status})`)
|
||||
}
|
||||
const result = (await response.json()) as ListResult<AuditLog>
|
||||
logs.value = result.items ?? []
|
||||
total.value = result.total ?? 0
|
||||
const { data } = await auditApiClient.audit.listAuditLogs(listRequest())
|
||||
logs.value = data.items ?? []
|
||||
total.value = data.total ?? 0
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : String(e)
|
||||
error.value = errorMessage(e, '查询失败')
|
||||
logs.value = []
|
||||
total.value = 0
|
||||
} finally {
|
||||
@@ -138,20 +136,24 @@ function exportFilename(): string {
|
||||
)
|
||||
}
|
||||
|
||||
/** 按当前筛选条件导出全部记录:fetch → blob → 触发下载,失败进顶部错误提示。 */
|
||||
/** 按当前筛选条件导出全部记录:生成客户端(responseType=blob)→ 触发下载,失败进顶部错误提示。 */
|
||||
async function exportLogs() {
|
||||
exporting.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
// 导出为全量接口,无需分页参数
|
||||
const params = new URLSearchParams(buildQuery())
|
||||
params.delete('page')
|
||||
params.delete('size')
|
||||
const response = await fetch(`${EXPORT_ENDPOINT}?${params.toString()}`)
|
||||
if (!response.ok) {
|
||||
throw new Error(`导出失败(HTTP ${response.status})`)
|
||||
// 导出为全量接口,无需分页参数(复用查询请求,仅保留筛选条件)
|
||||
const request = listRequest()
|
||||
const exportRequest: AuditV1alpha1ConsoleApiExportAuditLogsRequest = {
|
||||
fieldSelector: request.fieldSelector,
|
||||
result: request.result,
|
||||
keyword: request.keyword,
|
||||
startTime: request.startTime,
|
||||
endTime: request.endTime,
|
||||
}
|
||||
const blob = await response.blob()
|
||||
const response = await auditApiClient.audit.exportAuditLogs(exportRequest, {
|
||||
responseType: 'blob',
|
||||
})
|
||||
const blob = response.data
|
||||
const url = URL.createObjectURL(blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
@@ -159,7 +161,7 @@ async function exportLogs() {
|
||||
anchor.click()
|
||||
URL.revokeObjectURL(url)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : String(e)
|
||||
error.value = errorMessage(e, '导出失败')
|
||||
} finally {
|
||||
exporting.value = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user