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
@@ -0,0 +1 @@
- Fixed an issue in the extensions emulator where parameter default values would not be substitued into resource definitions.
4 changes: 3 additions & 1 deletion src/emulator/extensionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import { EmulatorInfo, EmulatorInstance, Emulators } from "./types";
import { Build } from "../deploy/functions/build";
import { extractExtensionsFromBuilds } from "../extensions/runtimes/common";
import { populateDefaultParams } from "../extensions/paramHelper";

export interface ExtensionEmulatorArgs {
options: Options;
Expand Down Expand Up @@ -267,7 +268,8 @@
// TODO: This should find package.json, then use that as functionsDir.
const functionsDir = path.join(extensionDir, "functions");
// TODO(b/213335255): For local extensions, this should include extensionSpec instead of extensionVersion
const env = Object.assign(this.autoPopulatedParams(instance), instance.params);
const params = populateDefaultParams(instance.params, await planner.getExtensionSpec(instance));
const env = Object.assign(this.autoPopulatedParams(instance), params);

const { extensionTriggers, runtime, nonSecretEnv, secretEnvVariables } =
await getExtensionFunctionInfo(instance, env);
Expand Down Expand Up @@ -369,7 +371,7 @@
)} triggered functions, and the ${unemulatedServices.join(
", ",
)} emulator does not exist or is not running.`;
this.logger.logLabeled("WARN", `extensions[${backend.extensionInstanceId}]`, msg);

Check warning on line 374 in src/emulator/extensionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "string | undefined" of template literal expression
}
return unemulatedServices.length === 0;
});
Expand Down
13 changes: 13 additions & 0 deletions src/extensions/paramHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// Add project specific key:value here when we want to support that.
}

export function getBaseParamBindings(params: { [key: string]: ParamBindingOptions }): {

Check warning on line 29 in src/extensions/paramHelper.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
[key: string]: string;
} {
let ret = {};
Expand All @@ -39,7 +39,7 @@
return ret;
}

export function buildBindingOptionsWithBaseValue(baseParams: { [key: string]: string }): {

Check warning on line 42 in src/extensions/paramHelper.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
[key: string]: ParamBindingOptions;
} {
let paramOptions: { [key: string]: ParamBindingOptions } = {};
Expand All @@ -54,7 +54,7 @@

/**
* A mutator to switch the defaults for a list of params to new ones.
* For convenience, this also returns the params

Check warning on line 57 in src/extensions/paramHelper.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected only 0 line after block description
*
* @param params A list of params
* @param newDefaults a map of { PARAM_NAME: default_value }
Expand All @@ -75,8 +75,8 @@

/**
* Gets params from the user
* or prompting the user for each param.

Check warning on line 78 in src/extensions/paramHelper.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing @param "args.reconfiguring"

Check warning on line 78 in src/extensions/paramHelper.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing @param "args.nonInteractive"

Check warning on line 78 in src/extensions/paramHelper.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing @param "args.paramSpecs"

Check warning on line 78 in src/extensions/paramHelper.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing @param "args.instanceId"

Check warning on line 78 in src/extensions/paramHelper.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing @param "args.projectId"
* @param projectId the id of the project in use

Check warning on line 79 in src/extensions/paramHelper.ts

View workflow job for this annotation

GitHub Actions / lint (20)

@param "projectId" does not match parameter name "args"
* @param paramSpecs a list of params, ie. extensionSpec.params
* @param envFilePath a path to an env file containing param values
* @throws FirebaseError if an invalid env file is passed in
Expand Down Expand Up @@ -225,3 +225,16 @@
const regex = /^firebaseextensions\.[a-zA-Z0-9\.]*\//;
return regex.test(paramName);
}

// Populate default values for missing params.
// This is only needed when emulating extensions - when deploying, this is handled in the back end.
export function populateDefaultParams(
params: Record<string, string>,
spec: ExtensionSpec,
): Record<string, string> {
const ret = { ...params };
for (const p of spec.params) {
ret[p.param] = ret[p.param] ?? p.default;
}
return ret;
}
1 change: 0 additions & 1 deletion src/responseToError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export function responseToError(response: any, body: any, url?: string): Firebas
if (response.statusCode < 400) {
return;
}

if (typeof body === "string") {
if (response.statusCode === 404) {
body = {
Expand Down
Loading