mirror of
https://github.com/certd/certd.git
synced 2026-07-26 22:09:04 +08:00
63be1c1cbd
实现批量更新证书申请参数功能,包括前端界面和后端处理逻辑 - 添加批量修改证书申请参数的按钮和对话框 - 实现后端批量更新证书申请参数的接口和服务 - 添加相关测试用例验证功能正确性
54 lines
1.8 KiB
TypeScript
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;
|
|
}
|