Skip to content

Commit 976637e

Browse files
leoortizztaeold
andauthored
handle null service account on CF deploy (#8381)
* handle null service account * changelog * use ternary instead * Update CHANGELOG.md * Fix bug for v1 and add test cases. --------- Co-authored-by: Daniel Young Lee <[email protected]>
1 parent d5a2bfb commit 976637e

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Fixed a bug where the Admin SDK would not automatically connect to the Data Connect emulator when run in the Functions emulator. (#8379)
2+
- Fix Cloud Functions deployment failure when service account is null. (#8381)

src/gcp/cloudfunctions.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,24 @@ describe("cloudfunctions", () => {
288288
serviceAccountEmail: `robot@${ENDPOINT.project}.iam.gserviceaccount.com`,
289289
});
290290
});
291+
292+
it("should handle null service account", () => {
293+
expect(
294+
cloudfunctions.functionFromEndpoint(
295+
{
296+
...ENDPOINT,
297+
httpsTrigger: {},
298+
serviceAccount: null,
299+
},
300+
UPLOAD_URL,
301+
),
302+
).to.deep.equal({
303+
...CLOUD_FUNCTION,
304+
sourceUploadUrl: UPLOAD_URL,
305+
httpsTrigger: {},
306+
serviceAccountEmail: null,
307+
});
308+
});
291309
});
292310

293311
describe("endpointFromFunction", () => {

src/gcp/cloudfunctions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ export function functionFromEndpoint(
681681
);
682682

683683
proto.convertIfPresent(gcfFunction, endpoint, "serviceAccountEmail", "serviceAccount", (from) =>
684-
proto.formatServiceAccount(from!, endpoint.project, true /* removeTypePrefix */),
684+
!from ? null : proto.formatServiceAccount(from, endpoint.project, true /* removeTypePrefix */),
685685
);
686686
proto.convertIfPresent(
687687
gcfFunction,

src/gcp/cloudfunctionsv2.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ describe("cloudfunctionsv2", () => {
421421
});
422422
});
423423

424-
it("should expand shorthand SA to full email", () => {
424+
it("should expand shorthand service account to full email", () => {
425425
expect(
426426
cloudfunctionsv2.functionFromEndpoint({
427427
...ENDPOINT,
@@ -436,6 +436,22 @@ describe("cloudfunctionsv2", () => {
436436
},
437437
});
438438
});
439+
440+
it("should handle null service account", () => {
441+
expect(
442+
cloudfunctionsv2.functionFromEndpoint({
443+
...ENDPOINT,
444+
serviceAccount: null,
445+
httpsTrigger: {},
446+
}),
447+
).to.deep.equal({
448+
...CLOUD_FUNCTION_V2,
449+
serviceConfig: {
450+
...CLOUD_FUNCTION_V2.serviceConfig,
451+
serviceAccountEmail: null,
452+
},
453+
});
454+
});
439455
});
440456

441457
describe("endpointFromFunction", () => {

src/gcp/cloudfunctionsv2.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,10 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc
518518
endpoint,
519519
"serviceAccountEmail",
520520
"serviceAccount",
521-
(from) => proto.formatServiceAccount(from!, endpoint.project, true /* removeTypePrefix */),
521+
(from) =>
522+
!from
523+
? null
524+
: proto.formatServiceAccount(from, endpoint.project, true /* removeTypePrefix */),
522525
);
523526
// Memory must be set because the default value of GCF gen 2 is Megabytes and
524527
// we use mebibytes

0 commit comments

Comments
 (0)