Skip to content
Open
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
20 changes: 20 additions & 0 deletions spec/params/params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ describe("Params value extraction", () => {
delete process.env.FIREBASE_CONFIG;
});

it("extracts the special case FUNCTION_REGION / functionRegion / region from process.env", () => {
try {
process.env.FUNCTION_REGION = "us-east1";
expect(params.functionRegion.value()).to.equal("us-east1");
expect(params.region.value()).to.equal("us-east1");
} finally {
delete process.env.FUNCTION_REGION;
}
expect(params.functionRegion.value()).to.equal("");
expect(params.region.value()).to.equal("");
});
Comment thread
inlined marked this conversation as resolved.

it("falls back on the javascript zero values in case of type mismatch", () => {
const stringToInt = params.defineInt("A_STRING");
expect(stringToInt.value()).to.equal(0);
Expand Down Expand Up @@ -378,6 +390,14 @@ describe("Params as CEL", () => {
expect(params.storageBucket.equals(str).toCEL()).to.equal(
`{{ params.STORAGE_BUCKET == params.A_STRING }}`
);
expect(params.functionRegion.toCEL()).to.equal(`{{ params.FUNCTION_REGION }}`);
expect(params.functionRegion.equals("foo").toCEL()).to.equal(
`{{ params.FUNCTION_REGION == "foo" }}`
);
expect(params.functionRegion.equals(str).toCEL()).to.equal(
`{{ params.FUNCTION_REGION == params.A_STRING }}`
);
expect(params.region.toCEL()).to.equal(`{{ params.FUNCTION_REGION }}`);
});

it("identity expressions", () => {
Expand Down
13 changes: 13 additions & 0 deletions src/params/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ export const storageBucket: Param<string> = new InternalExpression(
"STORAGE_BUCKET",
(env: NodeJS.ProcessEnv) => JSON.parse(env.FIREBASE_CONFIG || "{}")?.storageBucket || ""
);
/**
* A built-in parameter that resolves to the Cloud region, without prompting
* the deployer.
*/
export const functionRegion: Param<string> = new InternalExpression(
"FUNCTION_REGION",
(env: NodeJS.ProcessEnv) => env.FUNCTION_REGION || ""
);
/**
* A built-in parameter that resolves to the Cloud region, without prompting
* the deployer. Alias for {@link functionRegion}.
*/
export const region: Param<string> = functionRegion;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own learning... why do we need a region alias of this?


/**
* Declares a secret param, that will persist values only in Cloud Secret Manager.
Expand Down
Loading