Skip to content
Merged
Show file tree
Hide file tree
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
@@ -1,2 +1,3 @@
- Fixes secret params resolution in functions emulator. (#7443)
- Fixed bug where `esbuild` execution was throwing an error saying "Command line too long" on Windows (#7250, #6193).
- Automatically detect app platform during `init dataconnect:sdk`.
30 changes: 18 additions & 12 deletions src/deploy/functions/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,37 +278,43 @@ export type DynamicExtension = {
events: string[];
};

interface ResolveBackendOpts {
build: Build;
firebaseConfig: FirebaseConfig;
userEnvOpt: UserEnvsOpts;
userEnvs: Record<string, string>;
nonInteractive?: boolean;
isEmulator?: boolean;
}

/**
* Resolves user-defined parameters inside a Build, and generates a Backend.
* Returns both the Backend and the literal resolved values of any params, since
* the latter also have to be uploaded so user code can see them in process.env
*/
export async function resolveBackend(
build: Build,
firebaseConfig: FirebaseConfig,
userEnvOpt: UserEnvsOpts,
userEnvs: Record<string, string>,
nonInteractive?: boolean,
opts: ResolveBackendOpts,
): Promise<{ backend: backend.Backend; envs: Record<string, params.ParamValue> }> {
let paramValues: Record<string, params.ParamValue> = {};
paramValues = await params.resolveParams(
build.params,
firebaseConfig,
envWithTypes(build.params, userEnvs),
nonInteractive,
opts.build.params,
opts.firebaseConfig,
envWithTypes(opts.build.params, opts.userEnvs),
opts.nonInteractive,
opts.isEmulator,
);

const toWrite: Record<string, string> = {};
for (const paramName of Object.keys(paramValues)) {
const paramValue = paramValues[paramName];
if (Object.prototype.hasOwnProperty.call(userEnvs, paramName) || paramValue.internal) {
if (Object.prototype.hasOwnProperty.call(opts.userEnvs, paramName) || paramValue.internal) {
continue;
}
toWrite[paramName] = paramValue.toString();
}
writeUserEnvs(toWrite, userEnvOpt);
writeUserEnvs(toWrite, opts.userEnvOpt);

return { backend: toBackend(build, paramValues), envs: paramValues };
return { backend: toBackend(opts.build, paramValues), envs: paramValues };
}

// Exported for testing
Expand Down
8 changes: 6 additions & 2 deletions src/deploy/functions/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export async function resolveParams(
firebaseConfig: FirebaseConfig,
userEnvs: Record<string, ParamValue>,
nonInteractive?: boolean,
isEmulator = false,
): Promise<Record<string, ParamValue>> {
const paramValues: Record<string, ParamValue> = populateDefaultParams(firebaseConfig);

Expand All @@ -381,8 +382,11 @@ export async function resolveParams(
}

const [needSecret, needPrompt] = partition(outstanding, (param) => param.type === "secret");
for (const param of needSecret) {
await handleSecret(param as SecretParam, firebaseConfig.projectId);
// The functions emulator will handle secrets
if (!isEmulator) {
for (const param of needSecret) {
await handleSecret(param as SecretParam, firebaseConfig.projectId);
}
}

if (nonInteractive && needPrompt.length > 0) {
Expand Down
9 changes: 5 additions & 4 deletions src/deploy/functions/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ export async function prepare(
const userEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
const envs = { ...userEnvs, ...firebaseEnvs };

const { backend: wantBackend, envs: resolvedEnvs } = await build.resolveBackend(
wantBuild,
const { backend: wantBackend, envs: resolvedEnvs } = await build.resolveBackend({
build: wantBuild,
firebaseConfig,
userEnvOpt,
userEnvs,
options.nonInteractive,
);
nonInteractive: options.nonInteractive,
isEmulator: false,
});

let hasEnvsFromParams = false;
wantBackend.environmentVariables = envs;
Expand Down
12 changes: 6 additions & 6 deletions src/deploy/functions/runtimes/node/parseTriggers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { BEFORE_CREATE_EVENT } from "../../../../functions/events/v1";

async function resolveBackend(bd: build.Build): Promise<backend.Backend> {
return (
await build.resolveBackend(
bd,
{
await build.resolveBackend({
build: bd,
firebaseConfig: {
locationId: "",
projectId: "foo",
storageBucket: "foo.appspot.com",
databaseURL: "https://foo.firebaseio.com",
},
{ functionsSource: "", projectId: "PROJECT" },
{},
)
userEnvOpt: { functionsSource: "", projectId: "PROJECT" },
userEnvs: {},
})
).backend;
}

Expand Down
10 changes: 6 additions & 4 deletions src/emulator/functionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,14 @@ export class FunctionsEmulator implements EmulatorInstance {
};
const userEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
const discoveredBuild = await runtimeDelegate.discoverBuild(runtimeConfig, environment);
const resolution = await resolveBackend(
discoveredBuild,
JSON.parse(firebaseConfig),
const resolution = await resolveBackend({
build: discoveredBuild,
firebaseConfig: JSON.parse(firebaseConfig),
userEnvOpt,
userEnvs,
);
nonInteractive: false,
isEmulator: true,
});
const discoveredBackend = resolution.backend;
const endpoints = backend.allEndpoints(discoveredBackend);
prepareEndpoints(endpoints);
Expand Down