From 15ecfcfd644f6fb79ac76b8aa7cf09310bf1da37 Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Thu, 21 Sep 2023 14:05:22 -0400 Subject: [PATCH 1/2] treat the service account option as a param --- src/deploy/functions/build.ts | 6 ++-- src/test/deploy/functions/build.spec.ts | 46 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/deploy/functions/build.ts b/src/deploy/functions/build.ts index 846a49043b3..573a199ab4e 100644 --- a/src/deploy/functions/build.ts +++ b/src/deploy/functions/build.ts @@ -235,7 +235,7 @@ export type Endpoint = Triggered & { // The services account that this function should run as. // defaults to the GAE service account when a function is first created as a GCF gen 1 function. // Defaults to the compute service account when a function is first created as a GCF gen 2 function. - serviceAccount?: ServiceAccount | null; + serviceAccount?: Field | ServiceAccount | null; // defaults to ["us-central1"], overridable in firebase-tools with // process.env.FIREBASE_FUNCTIONS_DEFAULT_REGION @@ -457,8 +457,7 @@ export function toBackend( bdEndpoint, "environmentVariables", "labels", - "secretEnvironmentVariables", - "serviceAccount" + "secretEnvironmentVariables" ); proto.convertIfPresent(bkEndpoint, bdEndpoint, "ingressSettings", (from) => { @@ -479,6 +478,7 @@ export function toBackend( return (mem as backend.MemoryOptions) || null; }); + r.resolveStrings(bkEndpoint, bdEndpoint, "serviceAccount"); r.resolveInts( bkEndpoint, bdEndpoint, diff --git a/src/test/deploy/functions/build.spec.ts b/src/test/deploy/functions/build.spec.ts index 873c9a2a3b7..0f29dd55f08 100644 --- a/src/test/deploy/functions/build.spec.ts +++ b/src/test/deploy/functions/build.spec.ts @@ -1,5 +1,6 @@ import { expect } from "chai"; import * as build from "../../../deploy/functions/build"; +import { ParamValue } from "../../../deploy/functions/params"; describe("toBackend", () => { it("populates backend info from Build", () => { @@ -110,4 +111,49 @@ describe("toBackend", () => { ).to.have.members(["service-account-1@", "service-account-2@"]); } }); + + it("populates multiple param values", () => { + const desiredBuild: build.Build = build.of({ + func: { + platform: "gcfv2", + region: ["us-central1"], + project: "project", + runtime: "nodejs16", + entryPoint: "func", + maxInstances: "{{ params.maxinstances }}", + minInstances: "{{ params.mininstances }}", + serviceAccount: "{{ params.serviceaccount }}", + vpc: { + connector: "projects/project/locations/region/connectors/connector", + egressSettings: "PRIVATE_RANGES_ONLY", + }, + ingressSettings: "ALLOW_ALL", + labels: { + test: "testing", + }, + httpsTrigger: { + invoker: ["service-account-2@", "service-account-3@"], + }, + }, + }); + const backend = build.toBackend(desiredBuild, { + maxinstances: new ParamValue("42", false, { number: true }), + mininstances: new ParamValue("1", false, { number: true }), + serviceaccount: new ParamValue("service-account-1@", false, { string: true }), + }); + expect(Object.keys(backend.endpoints).length).to.equal(1); + const endpointDef = Object.values(backend.endpoints)[0]; + expect(endpointDef).to.not.equal(undefined); + if (endpointDef) { + expect(endpointDef.func.id).to.equal("func"); + expect(endpointDef.func.project).to.equal("project"); + expect(endpointDef.func.region).to.equal("us-central1"); + expect(endpointDef.func.maxInstances).to.equal(42); + expect(endpointDef.func.minInstances).to.equal(1); + expect(endpointDef.func.serviceAccount).to.equal("service-account-1@"); + expect( + "httpsTrigger" in endpointDef.func ? endpointDef.func.httpsTrigger.invoker : [] + ).to.have.members(["service-account-2@", "service-account-3@"]); + } + }); }); From d9c315af0da368fb1aaeaed200c92148651c5551 Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Thu, 21 Sep 2023 14:29:15 -0400 Subject: [PATCH 2/2] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f80b20b3933..8d9acbfdb03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ - Fixed an issue where `emulators:export` did not check if the target folder is empty. (#6313) - Fix "Could not find the next executable" on Next.js deployments (#6372) +- Fix an issue where the functions service account option was not treated as a param (#6389).