🔄 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 type SecretValueRunEnv = "ALIBABA_CLOUD" | "HATTER_CLI";
|
||||||
|
|
||||||
|
export interface GetSecretValueOptions {
|
||||||
|
runEnv?: SecretValueRunEnv;
|
||||||
|
}
|
||||||
|
|
||||||
export function getRunEnv(): stirng | null {
|
export function getRunEnv(): stirng | null {
|
||||||
return getEnv("RUN_ENV");
|
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(
|
export async function getSecretValue(
|
||||||
key: string,
|
key: string,
|
||||||
runEnv?: SecretValueRunEnv,
|
runEnvOrOptions?: SecretValueRunEnv | GetSecretValueOptions,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
if (!runEnv) {
|
const options = toGetSecretValueOptions(runEnvOrOptions);
|
||||||
runEnv = getRunEnv();
|
const runEnv = options?.runEnv ?? getRunEnv();
|
||||||
}
|
|
||||||
if (runEnv == "ALIBABA_CLOUD") {
|
if (runEnv == "ALIBABA_CLOUD") {
|
||||||
return await getSecretValueViaAlibabaCloudInstanceIdentity(key);
|
return await getSecretValueViaAlibabaCloudInstanceIdentity(key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
exit,
|
exit,
|
||||||
fetchFileWithCache,
|
fetchFileWithCache,
|
||||||
readFileToString,
|
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(), {
|
const flags = parseArgs(args(), {
|
||||||
boolean: ["help"],
|
boolean: ["help"],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env -S deno run -A
|
#!/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";
|
import {parseArgs} from "jsr:@std/cli/parse-args";
|
||||||
|
|
||||||
const flags = parseArgs(args(), {
|
const flags = parseArgs(args(), {
|
||||||
|
|||||||
Reference in New Issue
Block a user