Skip to content

Commit e04a130

Browse files
authored
Add location support to Firebase RTDB events (#76)
This is still not absolutely confirmed, but is definitely the expected result for the Source attribute. Extension attributes for all event conversions will be documented in the future.
1 parent b7c5649 commit e04a130

32 files changed

+81
-44
lines changed

docs/mapping.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,22 @@ Functions Frameworks behave consistently.
172172

173173
### Firebase RTDB events (tentative)
174174

175-
(This information is still actively being worked on.)
175+
The `resource` in the GCF HTTP representation is of the form
176+
`projects/_/instances/{instance-id}/refs/{ref-path}`. Additionally,
177+
there is a top-level `domain` property, which is used to determine the `location` part
178+
of the CloudEvent representation:
179+
180+
- The `domain` property must be present as a string; if it's missing, the conversion should fail.
181+
- If the `domain` value is `firebaseio.com`, the location is `us-central1`.
182+
- Otherwise, the location is the value of `domain` before the first period. For example,
183+
a `domain` value of `europe-west1.firebasedatabase.app` would lead to a location value
184+
of `europe-west1`.
185+
186+
In the CloudEvent representation, this information is split between
187+
the `source` and the `subject`:
188+
189+
- `source`: `//firestore.googleapis.com/projects/_/locations/{location}/instances/{instance-id}`
190+
- `subject: refs/{ref-path}`
176191

177192
### Firebase analytics events (tentative)
178193

@@ -184,7 +199,9 @@ the `source` attributes:
184199
- `source`: `//firebaseanalytics.googleapis.com/projects/{project-id}/apps/{app-id}`
185200
- `subject`: `events/{event-name}`
186201

187-
TBD: Where the `app-id` part comes from.
202+
The `app-id` part it obtained from the data within the GCF HTTP representation, from
203+
a path of `userDim.appInfo.appId` (both the `userDim` and `appInfo` properties are
204+
expected to have object values; the `appId` property is expected to have a string value.)
188205

189206
### Firebase auth events (tentative)
190207

@@ -202,7 +219,7 @@ respectively.
202219
### Firestore document events (tentative)
203220

204221
The `resource` in the GCF HTTP representation is of the form
205-
`projects/{project-id}/databases/{database-id}/documents/{path-to-document}".
222+
`projects/{project-id}/databases/{database-id}/documents/{path-to-document}`.
206223
In the CloudEvent representation, this information is split between
207224
the `source` and the `subject`:
208225

@@ -219,7 +236,7 @@ of raw JSON or a deserialized in-lanuage representation. The
219236
- `timestamp`: The date/time this event was created. (String)
220237
- `eventType`: The type of the event.
221238
For example: "google.pubsub.topic.publish". (String)
222-
- `resource": The resource that emitted the event. (The format of this
239+
- `resource`: The resource that emitted the event. (The format of this
223240
varies by language.)
224241

225242
The Java Functions Framework additionally includes an `attributes`

events/events_data.go

Lines changed: 30 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

events/generate/data/firebase-db1-cloudevent-input.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"specversion": "1.0",
33
"type": "google.firebase.database.document.v1.written",
4-
"source": "//firebasedatabase.googleapis.com/projects/_/instances/my-project-id",
4+
"source": "//firebasedatabase.googleapis.com/projects/_/locations/us-central1/instances/my-project-id",
55
"subject": "refs/gcf-test/xyz",
66
"id": "aaaaaa-1111-bbbb-2222-cccccccccccc",
77
"time": "2020-09-29T11:32:00.000Z",

events/generate/data/firebase-db1-cloudevent-output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"specversion": "1.0",
33
"type": "google.firebase.database.document.v1.written",
4-
"source": "//firebasedatabase.googleapis.com/projects/_/instances/my-project-id",
4+
"source": "//firebasedatabase.googleapis.com/projects/_/locations/us-central1/instances/my-project-id",
55
"subject": "refs/gcf-test/xyz",
66
"id": "aaaaaa-1111-bbbb-2222-cccccccccccc",
77
"time": "2020-09-29T11:32:00.000Z",

events/generate/data/firebase-db1-legacy-input.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"auth": {
77
"admin": true
88
},
9+
"domain": "firebaseio.com",
910
"data": {
1011
"data": null,
1112
"delta": {

events/generate/data/firebase-db2-cloudevent-input.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"specversion": "1.0",
33
"type": "google.firebase.database.document.v1.written",
4-
"source": "//firebasedatabase.googleapis.com/projects/_/instances/my-project-id",
4+
"source": "//firebasedatabase.googleapis.com/projects/_/locations/europe-west1/instances/my-project-id",
55
"subject": "refs/gcf-test/xyz",
66
"id": "aaaaaa-1111-bbbb-2222-cccccccccccc",
77
"time": "2020-09-29T11:32:00.000Z",

events/generate/data/firebase-db2-cloudevent-output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"specversion": "1.0",
33
"type": "google.firebase.database.document.v1.written",
4-
"source": "//firebasedatabase.googleapis.com/projects/_/instances/my-project-id",
4+
"source": "//firebasedatabase.googleapis.com/projects/_/locations/europe-west1/instances/my-project-id",
55
"subject": "refs/gcf-test/xyz",
66
"id": "aaaaaa-1111-bbbb-2222-cccccccccccc",
77
"time": "2020-09-29T11:32:00.000Z",

events/generate/data/firebase-db2-legacy-input.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"auth": {
77
"admin": true
88
},
9+
"domain":"europe-west1.firebasedatabase.app",
910
"data": {
1011
"data": {
1112
"grandchild": "other"

events/generate/data/firebase-db3-cloudevent-input.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"specversion": "1.0",
33
"type": "google.firebase.database.document.v1.written",
4-
"source": "//firebasedatabase.googleapis.com/projects/_/instances/my-project-id",
4+
"source": "//firebasedatabase.googleapis.com/projects/_/locations/us-central1/instances/my-project-id",
55
"subject": "refs/gcf-test/xyz",
66
"id": "aaaaaa-1111-bbbb-2222-cccccccccccc",
77
"time": "2020-09-29T11:32:00.000Z",

events/generate/data/firebase-db3-cloudevent-output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"specversion": "1.0",
33
"type": "google.firebase.database.document.v1.written",
4-
"source": "//firebasedatabase.googleapis.com/projects/_/instances/my-project-id",
4+
"source": "//firebasedatabase.googleapis.com/projects/_/locations/us-central1/instances/my-project-id",
55
"subject": "refs/gcf-test/xyz",
66
"id": "aaaaaa-1111-bbbb-2222-cccccccccccc",
77
"time": "2020-09-29T11:32:00.000Z",

0 commit comments

Comments
 (0)