🔄 Refactor getSecretValue logic and update dependency versions in scripts
This commit is contained in:
@@ -1434,17 +1434,34 @@ export async function getSecretValueViaHatterCli(key: string): Promise<string> {
|
||||
|
||||
export type SecretValueRunEnv = "ALIBABA_CLOUD" | "HATTER_CLI";
|
||||
|
||||
export interface GetSecretValueOptions {
|
||||
runEnv?: SecretValueRunEnv;
|
||||
}
|
||||
|
||||
export function getRunEnv(): stirng | null {
|
||||
return getEnv("RUN_ENV");
|
||||
}
|
||||
|
||||
function toGetSecretValueOptions(
|
||||
runEnvOrOptions?: SecretValueRunEnv | GetSecretValueOptions,
|
||||
): GetSecretValueOptions | undefined {
|
||||
if (!runEnvOrOptions) {
|
||||
return runEnvOrOptions as GetSecretValueOptions;
|
||||
}
|
||||
if (runEnvOrOptions == "ALIBABA_CLOUD" || runEnvOrOptions == "HATTER_CLI") {
|
||||
return {
|
||||
runEnv: runEnvOrOptions as SecretValueRunEnv,
|
||||
} as GetSecretValueOptions;
|
||||
}
|
||||
return runEnvOrOptions as GetSecretValueOptions;
|
||||
}
|
||||
|
||||
export async function getSecretValue(
|
||||
key: string,
|
||||
runEnv?: SecretValueRunEnv,
|
||||
runEnvOrOptions?: SecretValueRunEnv | GetSecretValueOptions,
|
||||
): Promise<string> {
|
||||
if (!runEnv) {
|
||||
runEnv = getRunEnv();
|
||||
}
|
||||
const options = toGetSecretValueOptions(runEnvOrOptions);
|
||||
const runEnv = options?.runEnv ?? getRunEnv();
|
||||
if (runEnv == "ALIBABA_CLOUD") {
|
||||
return await getSecretValueViaAlibabaCloudInstanceIdentity(key);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
exit,
|
||||
fetchFileWithCache,
|
||||
readFileToString,
|
||||
} from "https://global.hatter.ink/script/get/@62/deno-commons-mod.ts";
|
||||
} from "https://global.hatter.ink/script/get/@63/deno-commons-mod.ts";
|
||||
|
||||
const flags = parseArgs(args(), {
|
||||
boolean: ["help"],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env -S deno run -A
|
||||
|
||||
import {args, exit, getSecretValue,} from "https://script.hatter.ink/@61/deno-commons-mod.ts";
|
||||
import {args, exit, getSecretValue,} from "https://script.hatter.ink/@62/deno-commons-mod.ts";
|
||||
import {parseArgs} from "jsr:@std/cli/parse-args";
|
||||
|
||||
const flags = parseArgs(args(), {
|
||||
|
||||
Reference in New Issue
Block a user