refactor: share non sub2api ops helpers
This commit is contained in:
+3
-19
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user