From dbe70e880da20adb4e0eb43af370d88c9cd8c2bd Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Thu, 17 Aug 2023 12:33:05 -0400 Subject: [PATCH 1/3] adds GOOGLE_APPLICATION_CREDENTIALS into envs --- src/deploy/functions/prepare.ts | 5 +++-- src/deploy/functions/runtimes/python/index.ts | 2 ++ src/functions/env.ts | 12 ++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) 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/deploy/functions/runtimes/python/index.ts b/src/deploy/functions/runtimes/python/index.ts index 2dfbebbef93..f532871ca62 100644 --- a/src/deploy/functions/runtimes/python/index.ts +++ b/src/deploy/functions/runtimes/python/index.ts @@ -12,6 +12,8 @@ import { logger } from "../../../../logger"; import { DEFAULT_VENV_DIR, runWithVirtualEnv, virtualEnvCmd } from "../../../../functions/python"; import { FirebaseError } from "../../../../error"; import { Build } from "../../build"; +import { getCredentialPathAsync } from "../../../../defaultCredentials"; +import { getProjectDefaultAccount } from "../../../../auth"; export const LATEST_VERSION: runtimes.Runtime = "python311"; diff --git a/src/functions/env.ts b/src/functions/env.ts index b640aff443e..de1b216ecb7 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 }; } From 078b93d608712824db5fe97a86c579247786792f Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Thu, 17 Aug 2023 12:36:52 -0400 Subject: [PATCH 2/3] formatter --- src/deploy/functions/runtimes/python/index.ts | 2 -- src/functions/env.ts | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/deploy/functions/runtimes/python/index.ts b/src/deploy/functions/runtimes/python/index.ts index f532871ca62..2dfbebbef93 100644 --- a/src/deploy/functions/runtimes/python/index.ts +++ b/src/deploy/functions/runtimes/python/index.ts @@ -12,8 +12,6 @@ import { logger } from "../../../../logger"; import { DEFAULT_VENV_DIR, runWithVirtualEnv, virtualEnvCmd } from "../../../../functions/python"; import { FirebaseError } from "../../../../error"; import { Build } from "../../build"; -import { getCredentialPathAsync } from "../../../../defaultCredentials"; -import { getProjectDefaultAccount } from "../../../../auth"; export const LATEST_VERSION: runtimes.Runtime = "python311"; diff --git a/src/functions/env.ts b/src/functions/env.ts index de1b216ecb7..b439f19f13d 100644 --- a/src/functions/env.ts +++ b/src/functions/env.ts @@ -410,13 +410,13 @@ export async function loadFirebaseEnvs( projectId: string ): Promise> { let defaultCredPath = ""; - const account = getProjectDefaultAccount() + const account = getProjectDefaultAccount(); if (account !== undefined) { - defaultCredPath = await getCredentialPathAsync(account) || ""; + defaultCredPath = (await getCredentialPathAsync(account)) || ""; } return { FIREBASE_CONFIG: JSON.stringify(firebaseConfig), GCLOUD_PROJECT: projectId, - GOOGLE_APPLICATION_CREDENTIALS: defaultCredPath + GOOGLE_APPLICATION_CREDENTIALS: defaultCredPath, }; } From 1f6c2d9f6899eeda6c5b0d22f73e876aeca69099 Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Thu, 17 Aug 2023 12:38:11 -0400 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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).