Skip to content

Commit

Permalink
Propogate explicit service account to eventarc (#6859)
Browse files Browse the repository at this point in the history
* Propogate explicit service account to eventarc

* changelog
  • Loading branch information
inlined authored Mar 13, 2024
1 parent ec1dd69 commit 27088cd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- Enable dynamic debugger port for functions + support for inspecting multiple codebases (#6854)
- Inject an environment variable in the node functions emulator to tell the google-gax SDK not to look for the metadata service. (#6860)
- Release Firestore Emulator 1.19.3 which fixes ancestor and namespace scope queries for Datastore Mode. This release also fixes internal errors seen across REST API and firebase-js-sdk.
- Inject an environment variable in the node functions emulator to tell the google-gax SDK not to look for the metadata service. (#6860)
- v2 scheduled functions with explicit service accounts trigger eventarc to use that service account (#6858)
- v2 event functions with explicit service accounts trigger eventarc to use that service account (#6859)
5 changes: 4 additions & 1 deletion src/gcp/cloudfunctionsv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc
eventType: endpoint.eventTrigger.eventType,
retryPolicy: "RETRY_POLICY_UNSPECIFIED",
};
if (endpoint.serviceAccount) {
gcfFunction.eventTrigger.serviceAccountEmail = endpoint.serviceAccount;
}
if (gcfFunction.eventTrigger.eventType === PUBSUB_PUBLISH_EVENT) {
if (!endpoint.eventTrigger.eventFilters?.topic) {
throw new FirebaseError(
Expand Down Expand Up @@ -588,7 +591,7 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc

endpoint.eventTrigger.retry
? (gcfFunction.eventTrigger.retryPolicy = "RETRY_POLICY_RETRY")
: (gcfFunction.eventTrigger!.retryPolicy = "RETRY_POLICY_DO_NOT_RETRY");
: (gcfFunction.eventTrigger.retryPolicy = "RETRY_POLICY_DO_NOT_RETRY");

// By default, Functions Framework in GCFv2 opts to downcast incoming cloudevent messages to legacy formats.
// Since Firebase Functions SDK expects messages in cloudevent format, we set FUNCTION_SIGNATURE_TYPE to tell
Expand Down
39 changes: 39 additions & 0 deletions src/test/gcp/cloudfunctionsv2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,45 @@ describe("cloudfunctionsv2", () => {
);
});

it("should propagate serviceAccount to eventarc", () => {
const saEndpoint: backend.Endpoint = {
...ENDPOINT,
platform: "gcfv2",
eventTrigger: {
eventType: events.v2.DATABASE_EVENTS[0],
eventFilters: {
ref: "ref",
},
retry: false,
},
serviceAccount: "sa",
};

const saGcfFunction: cloudfunctionsv2.InputCloudFunction = {
...CLOUD_FUNCTION_V2,
eventTrigger: {
eventType: events.v2.DATABASE_EVENTS[0],
eventFilters: [
{
attribute: "ref",
value: "ref",
},
],
retryPolicy: "RETRY_POLICY_DO_NOT_RETRY",
serviceAccountEmail: "sa",
},
serviceConfig: {
...CLOUD_FUNCTION_V2.serviceConfig,
environmentVariables: {
FUNCTION_SIGNATURE_TYPE: "cloudevent",
},
serviceAccountEmail: "sa",
},
};

expect(cloudfunctionsv2.functionFromEndpoint(saEndpoint)).to.deep.equal(saGcfFunction);
});

it("should correctly convert CPU and concurrency values", () => {
const endpoint: backend.Endpoint = {
...ENDPOINT,
Expand Down

0 comments on commit 27088cd

Please sign in to comment.