Skip to content

Fix python function discovery where credentials are needed #6274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix python function discovery where credentials are needed (#6274).
5 changes: 3 additions & 2 deletions src/deploy/functions/prepare.ts
Original file line number Diff line number Diff line change
@@ -98,7 +98,8 @@ export async function prepare(
const wantBackends: Record<string, backend.Backend> = {};
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`
12 changes: 10 additions & 2 deletions src/functions/env.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>,
projectId: string
): Record<string, string> {
): Promise<Record<string, string>> {
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,
};
}