refactor: reuse yaml parser helpers in sub2api cli (#363)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -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<string, unknown>, key: string, path: string): R
|
||||
}
|
||||
|
||||
function booleanField(obj: Record<string, unknown>, 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<string, unknown>, key: string, path: string): string[] {
|
||||
@@ -804,9 +803,7 @@ function enumField<const T extends readonly string[]>(obj: Record<string, unknow
|
||||
}
|
||||
|
||||
function integerField(obj: Record<string, unknown>, 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<string, unknown>, key: string, path: string): number[] {
|
||||
@@ -817,6 +814,10 @@ function integerArrayField(obj: Record<string, unknown>, 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user