Files
certd/packages/ui/certd-server/src/modules/pipeline/service/pipeline-batch-update.ts
T
xiaojunnuo 63be1c1cbd perf(证书流水线): 添加批量更新证书申请参数功能
实现批量更新证书申请参数功能,包括前端界面和后端处理逻辑
- 添加批量修改证书申请参数的按钮和对话框
- 实现后端批量更新证书申请参数的接口和服务
- 添加相关测试用例验证功能正确性
2026-05-07 22:54:29 +08:00

54 lines
1.8 KiB
TypeScript

export type CertApplyStepInputPatch = {
renewDays?: number;
privateKeyType?: string;
};
export type GetStepInputDefine = (stepType: string) => Record<string, unknown> | undefined;
function isCertApplyStep(step: any) {
return typeof step?.type === "string" && step.type !== "CertApplyLego" && step.type.startsWith("CertApply");
}
function hasPatchValue(patch: CertApplyStepInputPatch, key: keyof CertApplyStepInputPatch) {
return Object.prototype.hasOwnProperty.call(patch, key) && patch[key] !== undefined;
}
function hasInputDefine(inputDefine: Record<string, unknown> | undefined, key: keyof CertApplyStepInputPatch) {
return inputDefine == null || Object.prototype.hasOwnProperty.call(inputDefine, key);
}
function applyPatchFields(target: Record<string, unknown>, patch: CertApplyStepInputPatch, inputDefine: Record<string, unknown> | undefined, fields: (keyof CertApplyStepInputPatch)[]) {
let changed = false;
for (const field of fields) {
if (!hasPatchValue(patch, field) || !hasInputDefine(inputDefine, field)) {
continue;
}
target[field] = patch[field];
changed = true;
}
return changed;
}
export function updateCertApplyStepInputs(pipeline: any, patch: CertApplyStepInputPatch, getStepInputDefine?: GetStepInputDefine) {
const fields: (keyof CertApplyStepInputPatch)[] = ["renewDays", "privateKeyType"];
let count = 0;
for (const stage of pipeline?.stages || []) {
for (const task of stage?.tasks || []) {
for (const step of task?.steps || []) {
if (!isCertApplyStep(step)) {
continue;
}
const inputDefine = getStepInputDefine?.(step.type);
if (step.input == null) {
step.input = {};
}
if (!applyPatchFields(step.input, patch, inputDefine, fields)) {
continue;
}
count++;
}
}
}
return count;
}