@firebase-function-kits/firestore-bigquery-export 0.0.2-rc.14 → 0.0.2-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -1
- package/README.md +20 -2
- package/lib/events.d.ts +5 -0
- package/lib/events.d.ts.map +1 -1
- package/lib/events.js +10 -3
- package/lib/events.js.map +1 -1
- package/lib/index.js +5 -9
- package/lib/index.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/events.ts +10 -2
- package/src/index.ts +9 -9
- package/tests/events.test.ts +38 -0
- package/tests/required-apis.test.ts +102 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
- fix: `eventarcpublishing.googleapis.com` and `roles/eventarc.publisher` are declared only when `EVENTARC_CHANNEL` is set in `.env`. A default install never publishes an event, yet every deploy prompted to enable the Eventarc Publishing API and declining aborted the deploy with `Must enable required APIs to deploy.` The extension declared only `bigquery.googleapis.com` and gained Eventarc publishing when the user opted into events at install; the kit now does the same. Detecting the channel needs firebase-tools 15.28.0 or later, which loads `.env` during deploy discovery; an older CLI skips the declarations even with `EVENTARC_CHANNEL` set, and every publish then fails with `PERMISSION_DENIED`, logged as a warning while the export continues. A blank `EVENTARC_CHANNEL` now disables events the same as an unset one.
|
|
1
2
|
- fix: cap `syncBigQuery` at `maxInstances: 500`, its declared `maxConcurrentDispatches`. At concurrency `1`, the default 100 instances would take only 100 of the 500 dispatches Cloud Tasks may have in flight, so the cap keeps capacity level with the dispatch limit. A dispatch above the instance ceiling waits up to about 10 seconds for a free instance, then gets a Cloud Run 429 that Cloud Tasks counts as a failed attempt and retries on the queue's schedule (5 attempts, 60s minimum backoff), slowing the queue while 429s continue. The handler never ran for such a dispatch, so a task that exhausts its attempts that way writes no `BACKUP_COLLECTION` row. At 0.1666 vCPU the cap needs about 84 vCPU of regional Cloud Run CPU quota, within the captured defaults (500 in most regions, 343 in `europe-west10` and `europe-west12`); the README describes the deploy failure a smaller quota produces and how to recover.
|
|
2
3
|
- fix: set `timeoutSeconds: 540` on `syncBigQuery`, `initBigQuerySync` and `setupBigQuerySync`, the extension's 1st gen task-function timeout, instead of the 2nd gen default of 60s. `fsexportbigquery` keeps 60s, which the deployed trigger ran at.
|
|
3
4
|
- fix: set every function's `cpu` to `"gcf_gen1"` (0.1666 vCPU), the extension's allocation, instead of the 1 vCPU that the 2nd gen default resolves to at 256MiB.
|
|
4
5
|
- fix: set every function's concurrency to `1`, and `fsexportbigquery` ingress to `ALLOW_INTERNAL_ONLY`, matching the extension. Previously, the kit inherited the 2nd gen defaults of concurrency `80` and ingress `ALLOW_ALL`. The task-queue functions `syncBigQuery`, `initBigQuerySync` and `setupBigQuerySync` declare no `ingressSettings`, so they inherit the default `ALLOW_ALL`, or whatever `setGlobalOptions({ ingressSettings })` sets; the deployed extension's task-queue functions ran with open ingress, and the `initBigQuerySync` HTTP POST needs it. At concurrency `1` a function serves as many requests at once as it has instances: the Cloud Run default of 100, unless your codebase sets `setGlobalOptions({ maxInstances })`.
|
|
5
|
-
- fix: an Eventarc publish failure no longer fails the function. A channel that was deleted or is unreachable answers `PERMISSION_DENIED`, and the publish was awaited before the work the function exists to do, so the document change was never exported. The publish failure is now logged as a warning and the invocation continues. Deploys also
|
|
6
|
+
- fix: an Eventarc publish failure no longer fails the function. A channel that was deleted or is unreachable answers `PERMISSION_DENIED`, and the publish was awaited before the work the function exists to do, so the document change was never exported. The publish failure is now logged as a warning and the invocation continues. Deploys also declared `eventarcpublishing.googleapis.com` unconditionally; the entry above makes that conditional on `EVENTARC_CHANNEL`.
|
|
6
7
|
|
|
7
8
|
- docs: the no-region fallback needs an explicit empty `DATABASE_REGION=` line in `.env`. Omitting the key entirely fails a non-interactive deploy, because the CLI resolves parameters before it reads their defaults. Corrects the note on the `DATABASE_REGION` placement fix below; no behavior change.
|
|
8
9
|
- fix: `USE_NEW_SNAPSHOT_QUERY_SYNTAX` and `EXCLUDE_OLD_DATA` take the extension's `yes` / `no` values again, so a config exported from the extension works unchanged. `WILDCARD_IDS` is unchanged: the extension already used `true` / `false` there.
|
package/README.md
CHANGED
|
@@ -31,10 +31,16 @@ conflicts with that automatic setup.
|
|
|
31
31
|
| `roles/datastore.user` | write failed-row records back to Firestore (only if you configure a backup collection) |
|
|
32
32
|
| `roles/eventarc.eventReceiver` | receive Gen2 Firestore trigger events |
|
|
33
33
|
| `roles/run.invoker` | allow Eventarc to invoke the Gen2 Cloud Run service, and Cloud Tasks to dispatch to the three task-queue functions, which have no function-level invoker binding |
|
|
34
|
-
| `roles/eventarc.publisher` | publish the kit's custom Eventarc events (the Extensions platform granted this implicitly) |
|
|
35
34
|
| `roles/cloudtasks.enqueuer` | enqueue failed writes onto the kit's own `syncBigQuery` task queue |
|
|
35
|
+
| `firestore.googleapis.com` | receive document change events from Cloud Firestore |
|
|
36
36
|
| `bigquery.googleapis.com` | mirror Firestore collection changes in BigQuery |
|
|
37
37
|
|
|
38
|
+
Only when `EVENTARC_CHANNEL` is set in `.env` (see Events), the deploy also
|
|
39
|
+
declares `roles/eventarc.publisher` and `eventarcpublishing.googleapis.com`,
|
|
40
|
+
which the Extensions platform granted implicitly to installs that opted into
|
|
41
|
+
events. A default install declares neither, so nothing prompts you to enable
|
|
42
|
+
the Eventarc Publishing API.
|
|
43
|
+
|
|
38
44
|
If the dataset lives in a different project (`BIGQUERY_PROJECT_ID`), grant the
|
|
39
45
|
managed runtime service account the `bigquery.*` roles on that project. For a
|
|
40
46
|
CMEK dataset, also grant the BigQuery service account access to your KMS key.
|
|
@@ -173,7 +179,19 @@ the instances cannot collide.
|
|
|
173
179
|
When `EVENTARC_CHANNEL` is configured, the functions publish lifecycle events:
|
|
174
180
|
`onStart` and `onError` from the write path, and `onSuccess` from the
|
|
175
181
|
`syncBigQuery` task when a buffered write lands (matching the extension, which
|
|
176
|
-
only emitted `onSuccess` from its queue handler).
|
|
182
|
+
only emitted `onSuccess` from its queue handler). A blank value is the same as
|
|
183
|
+
an unset one: no channel is opened and nothing is published.
|
|
184
|
+
|
|
185
|
+
Setting `EVENTARC_CHANNEL` also makes the deploy declare
|
|
186
|
+
`eventarcpublishing.googleapis.com` and `roles/eventarc.publisher`: the CLI
|
|
187
|
+
grants the role and prompts to enable the API, and declining that prompt
|
|
188
|
+
aborts the deploy. That needs firebase-tools 15.28.0 or later, which loads
|
|
189
|
+
`.env` during deploy discovery; on an older CLI the declarations are skipped
|
|
190
|
+
and every publish fails with `PERMISSION_DENIED`, logged as a warning while
|
|
191
|
+
the export itself continues. The API and role summary printed by
|
|
192
|
+
`firebase functions:kits:install` and `firebase ext:migrate` runs discovery
|
|
193
|
+
without your `.env`, so it does not list either even when `ext:migrate` has
|
|
194
|
+
just written `EVENTARC_CHANNEL`; the deploy declares them regardless.
|
|
177
195
|
|
|
178
196
|
Each event is published twice, exactly as the extension published it: once
|
|
179
197
|
under `firebase.extensions.firestore-bigquery-export.v1.*` and once under
|
package/lib/events.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Eventarc channel named by `EVENTARC_CHANNEL`, or `undefined` when the
|
|
3
|
+
* variable is unset or blank, which disables event publishing.
|
|
4
|
+
*/
|
|
5
|
+
export declare const configuredEventChannel: () => string | undefined;
|
|
1
6
|
/**
|
|
2
7
|
* Sets up the Eventarc channel.
|
|
3
8
|
*
|
package/lib/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAoCA;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAoCA;;;GAGG;AACH,eAAO,MAAM,sBAAsB,QAAO,MAAM,GAAG,SACA,CAAC;AAEpD;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,YAO7B,CAAC;AAkBF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAU,MAAM,MAAM,GAAG,MAAM,kBAY3D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAU,KAAK,KAAK,EAAE,UAAU,MAAM,kBAalE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAU,oBAGtC;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,kBAaA,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAU,MAAM,MAAM,GAAG,MAAM,kBAYhE,CAAC"}
|
package/lib/events.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.recordCompletionEvent = exports.recordSuccessEvent = exports.recordErrorEvent = exports.recordStartEvent = exports.setupEventChannel = void 0;
|
|
36
|
+
exports.recordCompletionEvent = exports.recordSuccessEvent = exports.recordErrorEvent = exports.recordStartEvent = exports.setupEventChannel = exports.configuredEventChannel = void 0;
|
|
37
37
|
/*
|
|
38
38
|
* Copyright 2019 Google LLC
|
|
39
39
|
*
|
|
@@ -66,6 +66,12 @@ const getEventTypes = (eventName) => [
|
|
|
66
66
|
`firebase.extensions.firestore-bigquery-export.v1.${eventName}`, // NEW Event Type following the updated convention
|
|
67
67
|
];
|
|
68
68
|
let eventChannel;
|
|
69
|
+
/**
|
|
70
|
+
* The Eventarc channel named by `EVENTARC_CHANNEL`, or `undefined` when the
|
|
71
|
+
* variable is unset or blank, which disables event publishing.
|
|
72
|
+
*/
|
|
73
|
+
const configuredEventChannel = () => process.env.EVENTARC_CHANNEL?.trim() || undefined;
|
|
74
|
+
exports.configuredEventChannel = configuredEventChannel;
|
|
69
75
|
/**
|
|
70
76
|
* Sets up the Eventarc channel.
|
|
71
77
|
*
|
|
@@ -76,8 +82,9 @@ let eventChannel;
|
|
|
76
82
|
* @function setupEventChannel
|
|
77
83
|
*/
|
|
78
84
|
const setupEventChannel = () => {
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
const channel = (0, exports.configuredEventChannel)();
|
|
86
|
+
eventChannel = channel
|
|
87
|
+
? getEventarc().channel(channel, {
|
|
81
88
|
allowedEventTypes: process.env.EXT_SELECTED_EVENTS,
|
|
82
89
|
})
|
|
83
90
|
: undefined;
|
package/lib/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,kEAAoD;AACpD,2DAA4C;AAE5C,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC;IAC3C,4CAA4C,SAAS,EAAE,EAAE,4CAA4C;IACrG,oDAAoD,SAAS,EAAE,EAAE,kDAAkD;CACpH,CAAC;AAEF,IAAI,YAA0C,CAAC;AAE/C;;;;;;;;GAQG;AACI,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,kEAAoD;AACpD,2DAA4C;AAE5C,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC;IAC3C,4CAA4C,SAAS,EAAE,EAAE,4CAA4C;IACrG,oDAAoD,SAAS,EAAE,EAAE,kDAAkD;CACpH,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M,gBAAgB,GAAG,KAAK,EAAE,GAAU,EAAE,OAAgB,EAAE,EAAE;IACrE,MAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IAE5C,kDAAkD;IAClD,MAAM,OAAO,CAAC,GAAG,CACf,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtB,OAAO,CAAC;QACN,IAAI;QACJ,IAAI,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;QAC9B,OAAO;KACR,CAAC,CACH,CACF,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,gBAAgB,oBAa3B;AAEF;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,OAAO,EACP,IAAI,GAIL,EAAE,EAAE;IACH,MAAM,UAAU,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IAE9C,kDAAkD;IAClD,MAAM,OAAO,CAAC,GAAG,CACf,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtB,OAAO,CAAC;QACN,IAAI;QACJ,OAAO;QACP,IAAI;KACL,CAAC,CACH,CACF,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,kBAAkB,sBAmB7B;AAEF;;;;;GAKG;AACI,MAAM,qBAAqB,GAAG,KAAK,EAAE,IAAqB,EAAE,EAAE;IACnE,MAAM,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;IAEjD,kDAAkD;IAClD,MAAM,OAAO,CAAC,GAAG,CACf,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtB,OAAO,CAAC;QACN,IAAI;QACJ,IAAI;KACL,CAAC,CACH,CACF,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,qBAAqB,yBAYhC"}
|
package/lib/index.js
CHANGED
|
@@ -100,11 +100,6 @@ const REQUIRED_ROLES = [
|
|
|
100
100
|
// Gen2 Firestore triggers need Eventarc receive and run.invoker on the function SA.
|
|
101
101
|
"roles/eventarc.eventReceiver",
|
|
102
102
|
"roles/run.invoker",
|
|
103
|
-
// The Extensions platform granted publish rights on the extension's Eventarc
|
|
104
|
-
// channel implicitly from `events:` in extension.yaml. Kits get no implicit
|
|
105
|
-
// grant, so without this the `channel.publish()` calls in ./events fail with
|
|
106
|
-
// PERMISSION_DENIED and no custom event is ever delivered.
|
|
107
|
-
"roles/eventarc.publisher",
|
|
108
103
|
// The trigger enqueues failed writes onto its own syncBigQuery task queue.
|
|
109
104
|
"roles/cloudtasks.enqueuer",
|
|
110
105
|
];
|
|
@@ -117,10 +112,6 @@ const REQUIRED_APIS = [
|
|
|
117
112
|
api: "bigquery.googleapis.com",
|
|
118
113
|
reason: "Mirrors data from your Cloud Firestore collection in BigQuery.",
|
|
119
114
|
},
|
|
120
|
-
{
|
|
121
|
-
api: "eventarcpublishing.googleapis.com",
|
|
122
|
-
reason: "Publishes the extension's custom events to its Eventarc channel.",
|
|
123
|
-
},
|
|
124
115
|
];
|
|
125
116
|
for (const role of REQUIRED_ROLES) {
|
|
126
117
|
(0, v2_1.requiresRole)(role);
|
|
@@ -128,6 +119,11 @@ for (const role of REQUIRED_ROLES) {
|
|
|
128
119
|
for (const { api, reason } of REQUIRED_APIS) {
|
|
129
120
|
(0, v2_1.requiresAPI)(api, reason);
|
|
130
121
|
}
|
|
122
|
+
// Declining a `requiresAPI` prompt aborts the deploy, and nothing publishes without a channel.
|
|
123
|
+
if (events.configuredEventChannel()) {
|
|
124
|
+
(0, v2_1.requiresRole)("roles/eventarc.publisher");
|
|
125
|
+
(0, v2_1.requiresAPI)("eventarcpublishing.googleapis.com", "Publishes the extension's custom events to its Eventarc channel.");
|
|
126
|
+
}
|
|
131
127
|
(0, lifecycle_1.afterFirstDeploy)({
|
|
132
128
|
task: { function: INIT_BIGQUERY_SYNC_FUNCTION, body: { data: {} } },
|
|
133
129
|
});
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH;;;;;;;;;;;GAWG;AAEH,6GAA6G;AAC7G,4CAA4D;AAC5D,4DAAiE;AACjE,sDAAiD;AACjD,oDAA4D;AAE5D,8CAAkE;AAClE,+DAGyC;AACzC,qCAIkB;AAClB,iDAAmC;AACnC,mDAIyB;AACzB,yCAKoB;AACpB,iCAAiD;AACjD,6CAA+B;AAC/B,qCAA6D;AAC7D,mCAA0C;AAE1C,IAAA,6BAAoB,GAAE,CAAC;AACvB,8EAA8E;AAC9E,wCAAsB;AAEtB,MAAM,2BAA2B,GAAG,kBAAkB,CAAC;AACvD,MAAM,4BAA4B,GAAG,mBAAmB,CAAC;AACzD,MAAM,sBAAsB,GAAG;IAC7B,WAAW,EAAE,EAAE;IACf,iBAAiB,EAAE,EAAE;CACb,CAAC;AACX,MAAM,iBAAiB,GAAG;IACxB,WAAW,EAAE,CAAC;IACd,iBAAiB,EAAE,EAAE;CACb,CAAC;AACX,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAC3C,MAAM,cAAc,GAAwB;IAC1C,2BAA2B;IAC3B,sBAAsB;IACtB,qBAAqB;IACrB,oFAAoF;IACpF,8BAA8B;IAC9B,mBAAmB;IACnB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH;;;;;;;;;;;GAWG;AAEH,6GAA6G;AAC7G,4CAA4D;AAC5D,4DAAiE;AACjE,sDAAiD;AACjD,oDAA4D;AAE5D,8CAAkE;AAClE,+DAGyC;AACzC,qCAIkB;AAClB,iDAAmC;AACnC,mDAIyB;AACzB,yCAKoB;AACpB,iCAAiD;AACjD,6CAA+B;AAC/B,qCAA6D;AAC7D,mCAA0C;AA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AC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,yCAAyC,EAAE,GAAG,CAAC,CAAC;QAClE,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACU,QAAA,gBAAgB,GAAG,IAAA,wBAAgB,EAC9C,sBAAsB,EACtB,gCAAgC,CACjC,CAAC;AAEF;;;GAGG;AACU,QAAA,iBAAiB,GAAG,IAAA,wBAAgB,EAC/C,sBAAsB,EACtB,gCAAgC,CACjC,CAAC"}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firebase-function-kits/firestore-bigquery-export",
|
|
3
|
-
"version": "0.0.2-rc.
|
|
3
|
+
"version": "0.0.2-rc.15",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@firebase-function-kits/firestore-bigquery-export",
|
|
9
|
-
"version": "0.0.2-rc.
|
|
9
|
+
"version": "0.0.2-rc.15",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@firebaseextensions/firestore-bigquery-change-tracker": "^2.2.1",
|
package/package.json
CHANGED
package/src/events.ts
CHANGED
|
@@ -34,6 +34,13 @@ const getEventTypes = (eventName: string) => [
|
|
|
34
34
|
|
|
35
35
|
let eventChannel: eventArc.Channel | undefined;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* The Eventarc channel named by `EVENTARC_CHANNEL`, or `undefined` when the
|
|
39
|
+
* variable is unset or blank, which disables event publishing.
|
|
40
|
+
*/
|
|
41
|
+
export const configuredEventChannel = (): string | undefined =>
|
|
42
|
+
process.env.EVENTARC_CHANNEL?.trim() || undefined;
|
|
43
|
+
|
|
37
44
|
/**
|
|
38
45
|
* Sets up the Eventarc channel.
|
|
39
46
|
*
|
|
@@ -44,8 +51,9 @@ let eventChannel: eventArc.Channel | undefined;
|
|
|
44
51
|
* @function setupEventChannel
|
|
45
52
|
*/
|
|
46
53
|
export const setupEventChannel = () => {
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
const channel = configuredEventChannel();
|
|
55
|
+
eventChannel = channel
|
|
56
|
+
? getEventarc().channel(channel, {
|
|
49
57
|
allowedEventTypes: process.env.EXT_SELECTED_EVENTS,
|
|
50
58
|
})
|
|
51
59
|
: undefined;
|
package/src/index.ts
CHANGED
|
@@ -82,11 +82,6 @@ const REQUIRED_ROLES: ReadonlyArray<Role> = [
|
|
|
82
82
|
// Gen2 Firestore triggers need Eventarc receive and run.invoker on the function SA.
|
|
83
83
|
"roles/eventarc.eventReceiver",
|
|
84
84
|
"roles/run.invoker",
|
|
85
|
-
// The Extensions platform granted publish rights on the extension's Eventarc
|
|
86
|
-
// channel implicitly from `events:` in extension.yaml. Kits get no implicit
|
|
87
|
-
// grant, so without this the `channel.publish()` calls in ./events fail with
|
|
88
|
-
// PERMISSION_DENIED and no custom event is ever delivered.
|
|
89
|
-
"roles/eventarc.publisher",
|
|
90
85
|
// The trigger enqueues failed writes onto its own syncBigQuery task queue.
|
|
91
86
|
"roles/cloudtasks.enqueuer",
|
|
92
87
|
];
|
|
@@ -99,10 +94,6 @@ const REQUIRED_APIS = [
|
|
|
99
94
|
api: "bigquery.googleapis.com",
|
|
100
95
|
reason: "Mirrors data from your Cloud Firestore collection in BigQuery.",
|
|
101
96
|
},
|
|
102
|
-
{
|
|
103
|
-
api: "eventarcpublishing.googleapis.com",
|
|
104
|
-
reason: "Publishes the extension's custom events to its Eventarc channel.",
|
|
105
|
-
},
|
|
106
97
|
] as const;
|
|
107
98
|
|
|
108
99
|
for (const role of REQUIRED_ROLES) {
|
|
@@ -113,6 +104,15 @@ for (const { api, reason } of REQUIRED_APIS) {
|
|
|
113
104
|
requiresAPI(api, reason);
|
|
114
105
|
}
|
|
115
106
|
|
|
107
|
+
// Declining a `requiresAPI` prompt aborts the deploy, and nothing publishes without a channel.
|
|
108
|
+
if (events.configuredEventChannel()) {
|
|
109
|
+
requiresRole("roles/eventarc.publisher");
|
|
110
|
+
requiresAPI(
|
|
111
|
+
"eventarcpublishing.googleapis.com",
|
|
112
|
+
"Publishes the extension's custom events to its Eventarc channel."
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
116
|
afterFirstDeploy({
|
|
117
117
|
task: { function: INIT_BIGQUERY_SYNC_FUNCTION, body: { data: {} } },
|
|
118
118
|
});
|
package/tests/events.test.ts
CHANGED
|
@@ -28,6 +28,7 @@ vi.mock("firebase-admin/eventarc", () => ({
|
|
|
28
28
|
}));
|
|
29
29
|
|
|
30
30
|
import {
|
|
31
|
+
configuredEventChannel,
|
|
31
32
|
recordCompletionEvent,
|
|
32
33
|
recordErrorEvent,
|
|
33
34
|
recordStartEvent,
|
|
@@ -52,6 +53,28 @@ describe("no channel configured", () => {
|
|
|
52
53
|
await recordCompletionEvent({ a: 1 });
|
|
53
54
|
expect(publish).not.toHaveBeenCalled();
|
|
54
55
|
});
|
|
56
|
+
|
|
57
|
+
test.each([
|
|
58
|
+
["empty", ""],
|
|
59
|
+
["whitespace-only", " "],
|
|
60
|
+
])("a %s EVENTARC_CHANNEL opens no channel", async (_label, value) => {
|
|
61
|
+
process.env.EVENTARC_CHANNEL = value;
|
|
62
|
+
setupEventChannel();
|
|
63
|
+
|
|
64
|
+
await recordStartEvent({ a: 1 });
|
|
65
|
+
expect(channel).not.toHaveBeenCalled();
|
|
66
|
+
expect(publish).not.toHaveBeenCalled();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test.each([
|
|
70
|
+
["unset", undefined],
|
|
71
|
+
["empty", ""],
|
|
72
|
+
["whitespace-only", " "],
|
|
73
|
+
])("configuredEventChannel is undefined when %s", (_label, value) => {
|
|
74
|
+
if (value === undefined) delete process.env.EVENTARC_CHANNEL;
|
|
75
|
+
else process.env.EVENTARC_CHANNEL = value;
|
|
76
|
+
expect(configuredEventChannel()).toBeUndefined();
|
|
77
|
+
});
|
|
55
78
|
});
|
|
56
79
|
|
|
57
80
|
describe("channel configured", () => {
|
|
@@ -60,6 +83,21 @@ describe("channel configured", () => {
|
|
|
60
83
|
setupEventChannel();
|
|
61
84
|
});
|
|
62
85
|
|
|
86
|
+
test("configuredEventChannel returns the trimmed channel name", () => {
|
|
87
|
+
process.env.EVENTARC_CHANNEL = " projects/p/locations/l/channels/c ";
|
|
88
|
+
expect(configuredEventChannel()).toBe("projects/p/locations/l/channels/c");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("opens the channel on the trimmed name", () => {
|
|
92
|
+
process.env.EVENTARC_CHANNEL = " projects/p/locations/l/channels/c ";
|
|
93
|
+
setupEventChannel();
|
|
94
|
+
expect(channel).toHaveBeenCalledTimes(2);
|
|
95
|
+
expect(channel).toHaveBeenLastCalledWith(
|
|
96
|
+
"projects/p/locations/l/channels/c",
|
|
97
|
+
expect.anything()
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
63
101
|
test("publishes both the legacy and the current event type", async () => {
|
|
64
102
|
await recordStartEvent({ a: 1 });
|
|
65
103
|
expect(publish).toHaveBeenCalledTimes(2);
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
18
18
|
|
|
19
|
-
const { requiresAPI } = vi.hoisted(() => ({
|
|
19
|
+
const { requiresAPI, requiresRole } = vi.hoisted(() => ({
|
|
20
|
+
requiresAPI: vi.fn(),
|
|
21
|
+
requiresRole: vi.fn(),
|
|
22
|
+
}));
|
|
20
23
|
|
|
21
24
|
vi.mock("firebase-functions/firestore", () => ({
|
|
22
25
|
onDocumentWritten: vi.fn(() => ({})),
|
|
@@ -26,18 +29,17 @@ vi.mock("firebase-functions/tasks", () => ({
|
|
|
26
29
|
}));
|
|
27
30
|
vi.mock("firebase-functions/v2", () => ({
|
|
28
31
|
requiresAPI,
|
|
29
|
-
requiresRole
|
|
32
|
+
requiresRole,
|
|
30
33
|
}));
|
|
31
34
|
vi.mock("firebase-functions/v2/lifecycle", () => ({
|
|
32
35
|
afterFirstDeploy: vi.fn(),
|
|
33
36
|
afterRedeploy: vi.fn(),
|
|
34
37
|
}));
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
+
const EVENTARC_API = "eventarcpublishing.googleapis.com";
|
|
40
|
+
const EVENTARC_PUBLISHER = "roles/eventarc.publisher";
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
const UNCONDITIONAL_APIS: ReadonlyArray<[api: string, reason: string]> = [
|
|
41
43
|
[
|
|
42
44
|
"firestore.googleapis.com",
|
|
43
45
|
"Receives document change events from Cloud Firestore.",
|
|
@@ -46,14 +48,99 @@ test.each([
|
|
|
46
48
|
"bigquery.googleapis.com",
|
|
47
49
|
"Mirrors data from your Cloud Firestore collection in BigQuery.",
|
|
48
50
|
],
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const UNCONDITIONAL_ROLES = [
|
|
54
|
+
"roles/bigquery.dataEditor",
|
|
55
|
+
"roles/datastore.user",
|
|
56
|
+
"roles/bigquery.user",
|
|
57
|
+
"roles/eventarc.eventReceiver",
|
|
58
|
+
"roles/run.invoker",
|
|
59
|
+
"roles/cloudtasks.enqueuer",
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
afterEach(() => {
|
|
63
|
+
vi.unstubAllEnvs();
|
|
64
|
+
vi.clearAllMocks();
|
|
55
65
|
});
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
/** Loads the entry afresh with `EVENTARC_CHANNEL` set to `channel`, or unset when omitted. */
|
|
68
|
+
async function loadWithChannel(channel?: string): Promise<void> {
|
|
69
|
+
vi.resetModules();
|
|
70
|
+
if (channel === undefined) {
|
|
71
|
+
vi.stubEnv("EVENTARC_CHANNEL", undefined);
|
|
72
|
+
} else {
|
|
73
|
+
vi.stubEnv("EVENTARC_CHANNEL", channel);
|
|
74
|
+
}
|
|
75
|
+
await import("../src/index");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function declaredApis(): string[] {
|
|
79
|
+
return requiresAPI.mock.calls.map(([api]) => api);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function declaredRoles(): string[] {
|
|
83
|
+
return requiresRole.mock.calls.map(([role]) => role);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
describe("without an Eventarc channel", () => {
|
|
87
|
+
test.each(UNCONDITIONAL_APIS)("declares %s", async (api, reason) => {
|
|
88
|
+
await loadWithChannel();
|
|
89
|
+
expect(requiresAPI).toHaveBeenCalledWith(api, reason);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("declares exactly the 2 APIs the export path needs", async () => {
|
|
93
|
+
await loadWithChannel();
|
|
94
|
+
expect(declaredApis()).toEqual(UNCONDITIONAL_APIS.map(([api]) => api));
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("declares the roles the export path needs and no publisher role", async () => {
|
|
98
|
+
await loadWithChannel();
|
|
99
|
+
expect(declaredRoles()).toEqual(UNCONDITIONAL_ROLES);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// The extension declared one API and gained Eventarc publishing only when the
|
|
103
|
+
// user opted into events, so a default install must not gate the deploy on it.
|
|
104
|
+
test.each([
|
|
105
|
+
["unset", undefined],
|
|
106
|
+
["empty", ""],
|
|
107
|
+
["whitespace-only", " "],
|
|
108
|
+
])(
|
|
109
|
+
"leaves the Eventarc publishing API and role undeclared when EVENTARC_CHANNEL is %s",
|
|
110
|
+
async (_label, channel) => {
|
|
111
|
+
await loadWithChannel(channel);
|
|
112
|
+
expect(declaredApis()).not.toContain(EVENTARC_API);
|
|
113
|
+
expect(declaredRoles()).not.toContain(EVENTARC_PUBLISHER);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("with an Eventarc channel", () => {
|
|
119
|
+
const CHANNEL = "projects/p/locations/l/channels/firebase";
|
|
120
|
+
|
|
121
|
+
test("declares the Eventarc publishing API", async () => {
|
|
122
|
+
await loadWithChannel(CHANNEL);
|
|
123
|
+
expect(requiresAPI).toHaveBeenCalledWith(
|
|
124
|
+
EVENTARC_API,
|
|
125
|
+
"Publishes the extension's custom events to its Eventarc channel."
|
|
126
|
+
);
|
|
127
|
+
expect(declaredApis()).toEqual([
|
|
128
|
+
...UNCONDITIONAL_APIS.map(([api]) => api),
|
|
129
|
+
EVENTARC_API,
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("declares the publisher role alongside the unconditional roles", async () => {
|
|
134
|
+
await loadWithChannel(CHANNEL);
|
|
135
|
+
expect(declaredRoles()).toEqual([
|
|
136
|
+
...UNCONDITIONAL_ROLES,
|
|
137
|
+
EVENTARC_PUBLISHER,
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("a padded channel name still counts as configured", async () => {
|
|
142
|
+
await loadWithChannel(` ${CHANNEL} `);
|
|
143
|
+
expect(declaredApis()).toContain(EVENTARC_API);
|
|
144
|
+
expect(declaredRoles()).toContain(EVENTARC_PUBLISHER);
|
|
145
|
+
});
|
|
59
146
|
});
|