43
43
_event_type_updated_with_auth_context = "google.cloud.firestore.document.v1.updated.withAuthContext"
44
44
_event_type_deleted_with_auth_context = "google.cloud.firestore.document.v1.deleted.withAuthContext"
45
45
46
+ AuthType = _typing .Literal ["service_account" , "api_key" , "system" ,
47
+ "unauthenticated" , "unknown" ]
48
+
46
49
47
50
@_dataclass .dataclass (frozen = True )
48
51
class Event (_core .CloudEvent [_core .T ]):
@@ -75,6 +78,12 @@ class Event(_core.CloudEvent[_core.T]):
75
78
The document path.
76
79
"""
77
80
81
+ auth_type : _typing .Optional [AuthType ]
82
+ """The type of principal that triggered the event"""
83
+
84
+ auth_id : _typing .Optional [str ]
85
+ """The unique identifier for the principal"""
86
+
78
87
params : dict [str , str ]
79
88
"""
80
89
An dict containing the values of the path patterns.
@@ -87,26 +96,9 @@ class Event(_core.CloudEvent[_core.T]):
87
96
_C1 = _typing .Callable [[_E1 ], None ]
88
97
_C2 = _typing .Callable [[_E2 ], None ]
89
98
90
- AuthType = _typing .Literal ["service_account" , "api_key" , "system" ,
91
- "unauthenticated" , "unknown" ]
92
-
93
-
94
- @_dataclass .dataclass (frozen = True )
95
- class EventWithAuthContext (Event [_core .T ]):
96
- auth_type : AuthType
97
- """The type of principal that triggered the event"""
98
- auth_id : str
99
- """The unique identifier for the principal"""
100
-
101
-
102
- _E3 = EventWithAuthContext [Change [DocumentSnapshot | None ]]
103
- _E4 = EventWithAuthContext [DocumentSnapshot | None ]
104
- _C3 = _typing .Callable [[_E3 ], None ]
105
- _C4 = _typing .Callable [[_E4 ], None ]
106
-
107
99
108
100
def _firestore_endpoint_handler (
109
- func : _C1 | _C2 | _C3 | _C4 ,
101
+ func : _C1 | _C2 ,
110
102
event_type : str ,
111
103
document_pattern : _path_pattern .PathPattern ,
112
104
raw : _ce .CloudEvent ,
@@ -203,17 +195,19 @@ def _firestore_endpoint_handler(
203
195
data = firestore_event_data ,
204
196
subject = event_attributes ["subject" ],
205
197
params = params ,
198
+ auth_type = None ,
199
+ auth_id = None ,
206
200
)
207
201
208
202
if event_type .endswith (".withAuthContext" ):
209
- database_event_with_auth_context = EventWithAuthContext (
210
- ** vars ( database_event ),
211
- auth_type = event_auth_type ,
212
- auth_id = event_auth_id )
213
- func ( database_event_with_auth_context )
214
- else :
215
- # mypy cannot infer that the event type is correct, hence the cast
216
- _typing . cast ( _C1 | _C2 , func ) (database_event )
203
+ event_attrs = vars ( database_event ). copy ()
204
+ event_attrs . update ({
205
+ " auth_type" : event_auth_type ,
206
+ " auth_id" : event_auth_id ,
207
+ } )
208
+ database_event = Event ( ** event_attrs )
209
+
210
+ func (database_event )
217
211
218
212
219
213
@_util .copy_func_kwargs (FirestoreOptions )
@@ -277,13 +271,13 @@ def on_document_written_with_auth_context(**kwargs
277
271
.. code-block:: python
278
272
279
273
@on_document_written_with_auth_context(document="*")
280
- def example(event: EventWithAuthContext [Change[DocumentSnapshot]]) -> None:
274
+ def example(event: Event [Change[DocumentSnapshot]]) -> None:
281
275
pass
282
276
283
277
:param \\ *\\ *kwargs: Firestore options.
284
278
:type \\ *\\ *kwargs: as :exc:`firebase_functions.options.FirestoreOptions`
285
279
:rtype: :exc:`typing.Callable`
286
- \\ [ \\ [ :exc:`firebase_functions.firestore_fn.EventWithAuthContext ` \\ [
280
+ \\ [ \\ [ :exc:`firebase_functions.firestore_fn.Event ` \\ [
287
281
:exc:`firebase_functions.db.Change` \\ ] \\ ], `None` \\ ]
288
282
A function that takes a Firestore event and returns ``None``.
289
283
"""
@@ -376,13 +370,13 @@ def on_document_updated_with_auth_context(**kwargs
376
370
.. code-block:: python
377
371
378
372
@on_document_updated_with_auth_context(document="*")
379
- def example(event: EventWithAuthContext [Change[DocumentSnapshot]]) -> None:
373
+ def example(event: Event [Change[DocumentSnapshot]]) -> None:
380
374
pass
381
375
382
376
:param \\ *\\ *kwargs: Firestore options.
383
377
:type \\ *\\ *kwargs: as :exc:`firebase_functions.options.FirestoreOptions`
384
378
:rtype: :exc:`typing.Callable`
385
- \\ [ \\ [ :exc:`firebase_functions.firestore_fn.EventWithAuthContext ` \\ [
379
+ \\ [ \\ [ :exc:`firebase_functions.firestore_fn.Event ` \\ [
386
380
:exc:`firebase_functions.db.Change` \\ ] \\ ], `None` \\ ]
387
381
A function that takes a Firestore event and returns ``None``.
388
382
"""
@@ -475,13 +469,13 @@ def on_document_created_with_auth_context(**kwargs
475
469
.. code-block:: python
476
470
477
471
@on_document_created_with_auth_context(document="*")
478
- def example(event: EventWithAuthContext [DocumentSnapshot]):
472
+ def example(event: Event [DocumentSnapshot]):
479
473
pass
480
474
481
475
:param \\ *\\ *kwargs: Firestore options.
482
476
:type \\ *\\ *kwargs: as :exc:`firebase_functions.options.FirestoreOptions`
483
477
:rtype: :exc:`typing.Callable`
484
- \\ [ \\ [ :exc:`firebase_functions.firestore_fn.EventWithAuthContext ` \\ [
478
+ \\ [ \\ [ :exc:`firebase_functions.firestore_fn.Event ` \\ [
485
479
:exc:`object` \\ ] \\ ], `None` \\ ]
486
480
A function that takes a Firestore event and returns ``None``.
487
481
"""
@@ -574,13 +568,13 @@ def on_document_deleted_with_auth_context(**kwargs
574
568
.. code-block:: python
575
569
576
570
@on_document_deleted_with_auth_context(document="*")
577
- def example(event: EventWithAuthContext [DocumentSnapshot]) -> None:
571
+ def example(event: Event [DocumentSnapshot]) -> None:
578
572
pass
579
573
580
574
:param \\ *\\ *kwargs: Firestore options.
581
575
:type \\ *\\ *kwargs: as :exc:`firebase_functions.options.FirestoreOptions`
582
576
:rtype: :exc:`typing.Callable`
583
- \\ [ \\ [ :exc:`firebase_functions.firestore_fn.EventWithAuthContext ` \\ [
577
+ \\ [ \\ [ :exc:`firebase_functions.firestore_fn.Event ` \\ [
584
578
:exc:`object` \\ ] \\ ], `None` \\ ]
585
579
A function that takes a Firestore event and returns ``None``.
586
580
"""
0 commit comments