diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..a2b36e6c3f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Fix python function discovery where credentials are needed (#6274). diff --git a/src/deploy/functions/prepare.ts b/src/deploy/functions/prepare.ts index b43e79f4da8..b08c0286a6b 100644 --- a/src/deploy/functions/prepare.ts +++ b/src/deploy/functions/prepare.ts @@ -98,7 +98,8 @@ export async function prepare( const wantBackends: Record = {}; for (const [codebase, wantBuild] of Object.entries(wantBuilds)) { const config = configForCodebase(context.config, codebase); - const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId); + const firebaseEnvs = await functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId); + const userEnvOpt: functionsEnv.UserEnvsOpts = { functionsSource: options.config.path(config.source), projectId: projectId, @@ -448,7 +449,7 @@ export async function loadCodebases( logger.debug(`Building ${runtimeDelegate.name} source`); await runtimeDelegate.build(); - const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId); + const firebaseEnvs = await functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId); logLabeledBullet( "functions", `Loading and analyzing source code for codebase ${codebase} to determine what to deploy` diff --git a/src/functions/env.ts b/src/functions/env.ts index b640aff443e..b439f19f13d 100644 --- a/src/functions/env.ts +++ b/src/functions/env.ts @@ -5,6 +5,8 @@ import * as path from "path"; import { FirebaseError } from "../error"; import { logger } from "../logger"; import { logBullet, logWarning } from "../utils"; +import { getProjectDefaultAccount } from "../auth"; +import { getCredentialPathAsync } from "../defaultCredentials"; const FUNCTIONS_EMULATOR_DOTENV = ".env.local"; @@ -403,12 +405,18 @@ export function loadUserEnvs({ * * @return Environment varibles for functions. */ -export function loadFirebaseEnvs( +export async function loadFirebaseEnvs( firebaseConfig: Record, projectId: string -): Record { +): Promise> { + let defaultCredPath = ""; + const account = getProjectDefaultAccount(); + if (account !== undefined) { + defaultCredPath = (await getCredentialPathAsync(account)) || ""; + } return { FIREBASE_CONFIG: JSON.stringify(firebaseConfig), GCLOUD_PROJECT: projectId, + GOOGLE_APPLICATION_CREDENTIALS: defaultCredPath, }; }