From c525bed7f8cbd35ada76117ee2ee3d3033b6093f Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Sun, 14 Jun 2026 12:57:33 +0800 Subject: [PATCH] refactor: reuse yaml parser helpers in sub2api cli (#363) Co-authored-by: Codex --- scripts/src/platform-infra.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/src/platform-infra.ts b/scripts/src/platform-infra.ts index dc910038..988d08f9 100644 --- a/scripts/src/platform-infra.ts +++ b/scripts/src/platform-infra.ts @@ -7,6 +7,7 @@ import { startJob } from "./jobs"; import type { RenderedCliResult } from "./output"; import { pk01CaddyMergeManagedBlocksPython, renderCaddyManagedBlock, renderSimpleReverseProxyCaddySiteBlock } from "./pk01-caddy"; import { capture, compactCapture, parseJsonOutput, prepareFrpcSecret, shQuote } from "./platform-infra-public-service"; +import { yamlBooleanField, yamlIntegerField } from "./platform-infra-ops-library"; import { fingerprintSecretValues, parseEnvFile, readEnvSourceFile, readTextFile, redactRepoPath, requiredEnvValue } from "./secrets"; const serviceName = "sub2api"; @@ -784,9 +785,7 @@ function objectField(obj: Record, key: string, path: string): R } function booleanField(obj: Record, key: string, path: string): boolean { - const value = obj[key]; - if (typeof value !== "boolean") throw new Error(`${configPath}.${path}.${key} must be a boolean`); - return value; + return yamlBooleanField(obj, key, yamlConfigLabel(path), path); } function stringArrayField(obj: Record, key: string, path: string): string[] { @@ -804,9 +803,7 @@ function enumField(obj: Record, key: string, path: string): number { - const value = obj[key]; - if (typeof value !== "number" || !Number.isInteger(value)) throw new Error(`${configPath}.${path}.${key} must be an integer`); - return value; + return yamlIntegerField(obj, key, yamlConfigLabel(path), path); } function integerArrayField(obj: Record, key: string, path: string): number[] { @@ -817,6 +814,10 @@ function integerArrayField(obj: Record, key: string, path: stri return value; } +function yamlConfigLabel(path: string): string { + return path.length === 0 ? `${configPath}.` : configPath; +} + function isKubernetesName(value: string): boolean { return /^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/u.test(value); }