Merge pull request #415 from pikasTech/fix/hwlab-node-admin-key-source

修复 HWLAB node admin API key source 解析
This commit is contained in:
Lyon
2026-06-15 12:28:17 +08:00
committed by GitHub
+11 -7
View File
@@ -114,7 +114,6 @@ interface NodeRuntimeGitMirrorTargetSpec {
gitopsBranch: string;
}
const MASTER_ADMIN_API_KEY_ENV = "/root/.config/hwlab-v02/master-server-admin-api-key.env";
const MASTER_ADMIN_API_KEY_KEY = "api-key";
const BOOTSTRAP_ADMIN_PASSWORD_HASH_KEY = "password-hash";
const BOOTSTRAP_ADMIN_SOURCE_NAMESPACE = "hwlab-v02";
@@ -3462,7 +3461,7 @@ function runNodeSecret(options: NodeSecretOptions): Record<string, unknown> {
}
const bootstrapAdminMaterial = options.preset === "bootstrap-admin" ? readBootstrapAdminSecretMaterial(spec) : null;
const input = options.preset === "master-server-admin-api-key" && options.action === "ensure" && !options.dryRun
? readMasterAdminApiKey().key
? readMasterAdminApiKey(spec).key
: options.preset === "bootstrap-admin" && options.action === "ensure" && !options.dryRun && bootstrapAdminMaterial?.ok === true
? bootstrapAdminMaterial.passwordHash ?? ""
: "";
@@ -5931,13 +5930,18 @@ export function nodeSecretStatusFromTextForTest(text: string, commandOk: boolean
return secretStatusFromText(text, commandOk, exitCode, stderr, runtimeSecretSpec({ node, lane }));
}
function readMasterAdminApiKey(): { key: string; source: string } {
if (!existsSync(MASTER_ADMIN_API_KEY_ENV)) throw new Error(`HWLAB_API_KEY source missing: ${MASTER_ADMIN_API_KEY_ENV}`);
const content = readFileSync(MASTER_ADMIN_API_KEY_ENV, "utf8");
function masterAdminApiKeyEnvPath(spec: RuntimeSecretSpec): string {
return `/root/.config/hwlab-${spec.lane}/master-server-admin-api-key.env`;
}
function readMasterAdminApiKey(spec: RuntimeSecretSpec): { key: string; source: string } {
const source = masterAdminApiKeyEnvPath(spec);
if (!existsSync(source)) throw new Error(`HWLAB_API_KEY source missing: ${source}`);
const content = readFileSync(source, "utf8");
const match = content.match(/^HWLAB_API_KEY=(.+)$/m);
const raw = (match?.[1] ?? "").trim().replace(/^['"]|['"]$/g, "");
if (!raw.startsWith("hwl_live_")) throw new Error(`HWLAB_API_KEY source invalid: ${MASTER_ADMIN_API_KEY_ENV}`);
return { key: raw, source: MASTER_ADMIN_API_KEY_ENV };
if (!raw.startsWith("hwl_live_")) throw new Error(`HWLAB_API_KEY source invalid: ${source}`);
return { key: raw, source };
}
function optionValue(args: string[], name: string): string | undefined {