fix: respect custom env snapshots for vertex auth

This commit is contained in:
Peter Steinberger
2026-04-05 08:29:48 +01:00
parent c9c7271f4f
commit d91d3cc0f0
2 changed files with 27 additions and 10 deletions

View File

@@ -79,15 +79,22 @@ function resolveAnthropicVertexDefaultAdcPath(env: NodeJS.ProcessEnv = process.e
function resolveAnthropicVertexAdcCredentialsPathCandidate(
env: NodeJS.ProcessEnv = process.env,
): string {
return (
normalizeOptionalSecretInput(env.GOOGLE_APPLICATION_CREDENTIALS) ??
resolveAnthropicVertexDefaultAdcPath(env)
);
): string | undefined {
const explicit = normalizeOptionalSecretInput(env.GOOGLE_APPLICATION_CREDENTIALS);
if (explicit) {
return explicit;
}
if (env !== process.env) {
return undefined;
}
return resolveAnthropicVertexDefaultAdcPath(env);
}
function canReadAnthropicVertexAdc(env: NodeJS.ProcessEnv = process.env): boolean {
const credentialsPath = resolveAnthropicVertexAdcCredentialsPathCandidate(env);
if (!credentialsPath) {
return false;
}
try {
readFileSync(credentialsPath, "utf8");
return true;
@@ -100,6 +107,9 @@ function resolveAnthropicVertexProjectIdFromAdc(
env: NodeJS.ProcessEnv = process.env,
): string | undefined {
const credentialsPath = resolveAnthropicVertexAdcCredentialsPathCandidate(env);
if (!credentialsPath) {
return undefined;
}
try {
const parsed = JSON.parse(readFileSync(credentialsPath, "utf8")) as AdcProjectFile;
return (

View File

@@ -35,15 +35,22 @@ function resolveAnthropicVertexDefaultAdcPath(env: NodeJS.ProcessEnv = process.e
function resolveAnthropicVertexAdcCredentialsPathCandidate(
env: NodeJS.ProcessEnv = process.env,
): string {
return (
normalizeOptionalPathInput(env.GOOGLE_APPLICATION_CREDENTIALS) ??
resolveAnthropicVertexDefaultAdcPath(env)
);
): string | undefined {
const explicit = normalizeOptionalPathInput(env.GOOGLE_APPLICATION_CREDENTIALS);
if (explicit) {
return explicit;
}
if (env !== process.env) {
return undefined;
}
return resolveAnthropicVertexDefaultAdcPath(env);
}
function canReadAnthropicVertexAdc(env: NodeJS.ProcessEnv = process.env): boolean {
const credentialsPath = resolveAnthropicVertexAdcCredentialsPathCandidate(env);
if (!credentialsPath) {
return false;
}
try {
readFileSync(credentialsPath, "utf8");
return true;