🔄 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user