diff --git a/CHANGELOG.md b/CHANGELOG.md index e8bd6aa2744..e1286bc5ae6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,2 @@ - Fixed a bug where the Admin SDK would not automatically connect to the Data Connect emulator when run in the Functions emulator. (#8379) +- Fix Cloud Functions deployment failure when service account is null. (#8381) diff --git a/src/gcp/cloudfunctions.spec.ts b/src/gcp/cloudfunctions.spec.ts index ffe06b8c671..7e4100ab026 100644 --- a/src/gcp/cloudfunctions.spec.ts +++ b/src/gcp/cloudfunctions.spec.ts @@ -288,6 +288,24 @@ describe("cloudfunctions", () => { serviceAccountEmail: `robot@${ENDPOINT.project}.iam.gserviceaccount.com`, }); }); + + it("should handle null service account", () => { + expect( + cloudfunctions.functionFromEndpoint( + { + ...ENDPOINT, + httpsTrigger: {}, + serviceAccount: null, + }, + UPLOAD_URL, + ), + ).to.deep.equal({ + ...CLOUD_FUNCTION, + sourceUploadUrl: UPLOAD_URL, + httpsTrigger: {}, + serviceAccountEmail: null, + }); + }); }); describe("endpointFromFunction", () => { diff --git a/src/gcp/cloudfunctions.ts b/src/gcp/cloudfunctions.ts index c3029d53fa6..ae73d0f73bc 100644 --- a/src/gcp/cloudfunctions.ts +++ b/src/gcp/cloudfunctions.ts @@ -681,7 +681,7 @@ export function functionFromEndpoint( ); proto.convertIfPresent(gcfFunction, endpoint, "serviceAccountEmail", "serviceAccount", (from) => - proto.formatServiceAccount(from!, endpoint.project, true /* removeTypePrefix */), + !from ? null : proto.formatServiceAccount(from, endpoint.project, true /* removeTypePrefix */), ); proto.convertIfPresent( gcfFunction, diff --git a/src/gcp/cloudfunctionsv2.spec.ts b/src/gcp/cloudfunctionsv2.spec.ts index 5bd436ccb13..ffc0ac5c255 100644 --- a/src/gcp/cloudfunctionsv2.spec.ts +++ b/src/gcp/cloudfunctionsv2.spec.ts @@ -421,7 +421,7 @@ describe("cloudfunctionsv2", () => { }); }); - it("should expand shorthand SA to full email", () => { + it("should expand shorthand service account to full email", () => { expect( cloudfunctionsv2.functionFromEndpoint({ ...ENDPOINT, @@ -436,6 +436,22 @@ describe("cloudfunctionsv2", () => { }, }); }); + + it("should handle null service account", () => { + expect( + cloudfunctionsv2.functionFromEndpoint({ + ...ENDPOINT, + serviceAccount: null, + httpsTrigger: {}, + }), + ).to.deep.equal({ + ...CLOUD_FUNCTION_V2, + serviceConfig: { + ...CLOUD_FUNCTION_V2.serviceConfig, + serviceAccountEmail: null, + }, + }); + }); }); describe("endpointFromFunction", () => { diff --git a/src/gcp/cloudfunctionsv2.ts b/src/gcp/cloudfunctionsv2.ts index df2e00b7b5e..c11c6ed86dd 100644 --- a/src/gcp/cloudfunctionsv2.ts +++ b/src/gcp/cloudfunctionsv2.ts @@ -518,7 +518,10 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc endpoint, "serviceAccountEmail", "serviceAccount", - (from) => proto.formatServiceAccount(from!, endpoint.project, true /* removeTypePrefix */), + (from) => + !from + ? null + : proto.formatServiceAccount(from, endpoint.project, true /* removeTypePrefix */), ); // Memory must be set because the default value of GCF gen 2 is Megabytes and // we use mebibytes