refactor: share non sub2api ops helpers

This commit is contained in:
Codex
2026-06-14 13:03:49 +00:00
parent e3a953fcbb
commit 79d0c58d1e
4 changed files with 38 additions and 87 deletions
+3 -19
View File
@@ -12,11 +12,14 @@ import {
yamlIntegerField,
yamlKubernetesNameField,
yamlObjectField,
parseEnvFile,
yamlRecord,
yamlStringArrayField,
yamlStringField,
} from "./platform-infra-ops-library";
export { parseEnvFile } from "./platform-infra-ops-library";
const defaultConfigPath = "config/secrets-distribution.yaml";
const fieldManager = "unidesk-secret-distribution";
@@ -727,25 +730,6 @@ export function readEnvSourceFile(params: { root: string; sourceRef: string; mis
};
}
export function parseEnvFile(text: string): Record<string, string> {
const result: Record<string, string> = {};
for (const rawLine of text.split(/\r?\n/u)) {
const line = rawLine.trim();
if (line.length === 0 || line.startsWith("#")) continue;
const eq = line.indexOf("=");
if (eq <= 0) continue;
const key = line.slice(0, eq).trim();
if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(key)) continue;
result[key] = unquoteEnvValue(line.slice(eq + 1).trim());
}
return result;
}
function unquoteEnvValue(value: string): string {
if ((value.startsWith("'") && value.endsWith("'")) || (value.startsWith("\"") && value.endsWith("\""))) return value.slice(1, -1);
return value;
}
export function requiredEnvValue(values: Record<string, string>, key: string, sourceRef: string): string {
const value = values[key];
if (value === undefined || value.length === 0) throw new Error(`${sourceRef} is missing required key ${key}`);