1
1
# Copyright (c) Microsoft Corporation. All rights reserved.
2
2
# Licensed under the MIT License.
3
3
import json
4
- import typing
5
4
from typing import Callable , Dict , List , Optional , Union , Iterable
6
5
7
6
from azure .functions .decorators .blob import BlobTrigger , BlobInput , BlobOutput
@@ -192,29 +191,33 @@ class FunctionApp:
192
191
"""
193
192
194
193
def __init__ (self ,
195
- wsgi_app = None ,
196
- asgi_app = None ,
197
- app_kwargs : typing .Dict = {},
198
- auth_level : Union [AuthLevel , str ] = AuthLevel .FUNCTION ):
194
+ http_auth_level : Union [AuthLevel , str ] = AuthLevel .FUNCTION ,
195
+ ** kwargs ):
199
196
"""Constructor of :class:`FunctionApp` object.
200
-
201
- :param wsgi_app: wsgi app object, defaults to None.
202
- :param asgi_app: asgi app object, defaults to None.
203
- :param app_kwargs: dict of :meth:`route` param names and values for
204
- custom configuration of wsgi/asgi app, default to {}.
205
- :param auth_level: defaults to AuthLevel.FUNCTION, takes str or
206
- AuthLevel
197
+ To integrate your asgi or wsgi application into python function,
198
+ specify either of below variables as a keyword argument:
199
+ `asgi_app` - the actual asgi application to integrate into python
200
+ function.
201
+ `wsgi_app` - the actual wsgi application to integrate into python
202
+ function.
203
+
204
+ :param http_auth_level: defaults to AuthLevel.FUNCTION, takes str or
205
+ AuthLevel.
206
+ :param kwargs: Extra arguments passed to :func:`__init__`.
207
207
"""
208
208
self ._function_builders : List [FunctionBuilder ] = []
209
209
self ._app_script_file : str = SCRIPT_FILE_NAME
210
- self ._auth_level = AuthLevel [auth_level ] \
211
- if isinstance (auth_level , str ) else auth_level
210
+ self ._auth_level = AuthLevel [http_auth_level ] \
211
+ if isinstance (http_auth_level , str ) else http_auth_level
212
+
213
+ wsgi_app = kwargs .get ("wsgi_app" , None )
214
+ asgi_app = kwargs .get ("asgi_app" , None )
212
215
213
216
if wsgi_app is not None :
214
- self ._add_http_app (WsgiMiddleware (wsgi_app ), app_kwargs )
217
+ self ._add_http_app (WsgiMiddleware (wsgi_app ))
215
218
216
219
if asgi_app is not None :
217
- self ._add_http_app (AsgiMiddleware (asgi_app ), app_kwargs )
220
+ self ._add_http_app (AsgiMiddleware (asgi_app ))
218
221
219
222
@property
220
223
def app_script_file (self ) -> str :
@@ -296,28 +299,18 @@ def decorator():
296
299
return wrap
297
300
298
301
def _add_http_app (self ,
299
- http_middleware : Union [AsgiMiddleware , WsgiMiddleware ],
300
- app_kwargs : typing . Dict ) -> None :
302
+ http_middleware : Union [
303
+ AsgiMiddleware , WsgiMiddleware ] ) -> None :
301
304
"""Add a Wsgi or Asgi app integrated http function.
302
305
303
306
:param http_middleware: :class:`AsgiMiddleware` or
304
307
:class:`WsgiMiddleware` instance.
305
- :param app_kwargs: dict of :meth:`route` param names and values for
306
- custom configuration of wsgi/asgi app.
307
308
308
309
:return: None
309
310
"""
310
- methods = app_kwargs .get ('methods' , (method for method in HttpMethod ))
311
- trigger_arg_data_type = app_kwargs .get ('trigger_arg_data_type' ,
312
- None )
313
- output_arg_data_type = app_kwargs .get ('output_arg_data_type' ,
314
- None )
315
- auth_level = app_kwargs .get ('auth_level' , None )
316
-
317
- @self .route (methods = methods ,
318
- auth_level = auth_level ,
319
- trigger_arg_data_type = trigger_arg_data_type ,
320
- output_arg_data_type = output_arg_data_type ,
311
+
312
+ @self .route (methods = (method for method in HttpMethod ),
313
+ auth_level = self .auth_level ,
321
314
route = "/{*route}" )
322
315
def http_app_func (req : HttpRequest , context : Context ):
323
316
return http_middleware .handle (req , context )
@@ -326,8 +319,6 @@ def route(self,
326
319
route : Optional [str ] = None ,
327
320
trigger_arg_name : str = 'req' ,
328
321
binding_arg_name : str = '$return' ,
329
- trigger_arg_data_type : Optional [Union [DataType , str ]] = None ,
330
- output_arg_data_type : Optional [Union [DataType , str ]] = None ,
331
322
methods : Optional [
332
323
Union [Iterable [str ], Iterable [HttpMethod ]]] = None ,
333
324
auth_level : Optional [Union [AuthLevel , str ]] = None ) -> Callable :
@@ -348,10 +339,6 @@ def route(self,
348
339
defaults to 'req'.
349
340
:param binding_arg_name: Argument name for :class:`HttpResponse`,
350
341
defaults to '$return'.
351
- :param trigger_arg_data_type: Defines how Functions runtime should
352
- treat the trigger_arg_name value.
353
- :param output_arg_data_type: Defines how Functions runtime should
354
- treat the binding_arg_name value.
355
342
:param methods: A tuple of the HTTP methods to which the function
356
343
responds.
357
344
:param auth_level: Determines what keys, if any, need to be present
@@ -368,18 +355,11 @@ def decorator():
368
355
369
356
fb .add_trigger (trigger = HttpTrigger (
370
357
name = trigger_arg_name ,
371
- data_type = parse_singular_param_to_enum (
372
- trigger_arg_data_type ,
373
- DataType ),
374
358
methods = parse_iterable_param_to_enums (methods , HttpMethod ),
375
359
auth_level = parse_singular_param_to_enum (auth_level ,
376
360
AuthLevel ),
377
361
route = route ))
378
- fb .add_binding (binding = HttpOutput (
379
- name = binding_arg_name ,
380
- data_type = parse_singular_param_to_enum (
381
- output_arg_data_type ,
382
- DataType )))
362
+ fb .add_binding (binding = HttpOutput (name = binding_arg_name ))
383
363
return fb
384
364
385
365
return decorator ()
@@ -433,7 +413,7 @@ def decorator():
433
413
434
414
return wrap
435
415
436
- def on_service_bus_queue_change (
416
+ def service_bus_queue_trigger (
437
417
self ,
438
418
arg_name : str ,
439
419
connection : str ,
@@ -442,7 +422,7 @@ def on_service_bus_queue_change(
442
422
access_rights : Optional [Union [AccessRights , str ]] = None ,
443
423
is_sessions_enabled : Optional [bool ] = None ,
444
424
cardinality : Optional [Union [Cardinality , str ]] = None ) -> Callable :
445
- """The on_service_bus_queue_change decorator adds
425
+ """The service_bus_queue_trigger decorator adds
446
426
:class:`ServiceBusQueueTrigger` to the :class:`FunctionBuilder` object
447
427
for building :class:`Function` object used in worker function
448
428
indexing model. This is equivalent to defining ServiceBusQueueTrigger
@@ -537,7 +517,7 @@ def decorator():
537
517
538
518
return wrap
539
519
540
- def on_service_bus_topic_change (
520
+ def service_bus_topic_trigger (
541
521
self ,
542
522
arg_name : str ,
543
523
connection : str ,
@@ -547,7 +527,7 @@ def on_service_bus_topic_change(
547
527
access_rights : Optional [Union [AccessRights , str ]] = None ,
548
528
is_sessions_enabled : Optional [bool ] = None ,
549
529
cardinality : Optional [Union [Cardinality , str ]] = None ) -> Callable :
550
- """The on_service_bus_topic_change decorator adds
530
+ """The service_bus_topic_trigger decorator adds
551
531
:class:`ServiceBusTopicTrigger` to the :class:`FunctionBuilder` object
552
532
for building :class:`Function` object used in worker function
553
533
indexing model. This is equivalent to defining ServiceBusTopicTrigger
@@ -648,12 +628,12 @@ def decorator():
648
628
649
629
return wrap
650
630
651
- def on_queue_change (self ,
652
- arg_name : str ,
653
- queue_name : str ,
654
- connection : str ,
655
- data_type : Optional [DataType ] = None ) -> Callable :
656
- """The on_queue_change decorator adds :class:`QueueTrigger` to the
631
+ def queue_trigger (self ,
632
+ arg_name : str ,
633
+ queue_name : str ,
634
+ connection : str ,
635
+ data_type : Optional [DataType ] = None ) -> Callable :
636
+ """The queue_trigger decorator adds :class:`QueueTrigger` to the
657
637
:class:`FunctionBuilder` object
658
638
for building :class:`Function` object used in worker function
659
639
indexing model. This is equivalent to defining QueueTrigger
@@ -731,15 +711,18 @@ def decorator():
731
711
732
712
return wrap
733
713
734
- def on_event_hub_message (self ,
735
- arg_name : str ,
736
- connection : str ,
737
- event_hub_name : str ,
738
- data_type : Optional [Union [DataType , str ]] = None ,
739
- cardinality : Optional [
740
- Union [Cardinality , str ]] = None ,
741
- consumer_group : Optional [str ] = None ) -> Callable :
742
- """The on_event_hub_message decorator adds :class:`EventHubTrigger`
714
+ def event_hub_message_trigger (self ,
715
+ arg_name : str ,
716
+ connection : str ,
717
+ event_hub_name : str ,
718
+ data_type : Optional [
719
+ Union [DataType , str ]] = None ,
720
+ cardinality : Optional [
721
+ Union [Cardinality , str ]] = None ,
722
+ consumer_group : Optional [
723
+ str ] = None ) -> Callable :
724
+ """The event_hub_message_trigger decorator adds
725
+ :class:`EventHubTrigger`
743
726
to the :class:`FunctionBuilder` object
744
727
for building :class:`Function` object used in worker function
745
728
indexing model. This is equivalent to defining EventHubTrigger
@@ -825,32 +808,32 @@ def decorator():
825
808
826
809
return wrap
827
810
828
- def on_cosmos_db_update (self ,
829
- arg_name : str ,
830
- database_name : str ,
831
- collection_name : str ,
832
- connection_string_setting : str ,
833
- lease_collection_name : Optional [str ] = None ,
834
- lease_connection_string_setting : Optional [
835
- str ] = None ,
836
- lease_database_name : Optional [str ] = None ,
837
- create_lease_collection_if_not_exists : Optional [
838
- bool ] = None ,
839
- leases_collection_throughput : Optional [int ] = None ,
840
- lease_collection_prefix : Optional [str ] = None ,
841
- checkpoint_interval : Optional [int ] = None ,
842
- checkpoint_document_count : Optional [int ] = None ,
843
- feed_poll_delay : Optional [int ] = None ,
844
- lease_renew_interval : Optional [int ] = None ,
845
- lease_acquire_interval : Optional [int ] = None ,
846
- lease_expiration_interval : Optional [int ] = None ,
847
- max_items_per_invocation : Optional [int ] = None ,
848
- start_from_beginning : Optional [bool ] = None ,
849
- preferred_locations : Optional [str ] = None ,
850
- data_type : Optional [
851
- Union [DataType , str ]] = None ) -> \
811
+ def cosmos_db_trigger (self ,
812
+ arg_name : str ,
813
+ database_name : str ,
814
+ collection_name : str ,
815
+ connection_string_setting : str ,
816
+ lease_collection_name : Optional [str ] = None ,
817
+ lease_connection_string_setting : Optional [
818
+ str ] = None ,
819
+ lease_database_name : Optional [str ] = None ,
820
+ create_lease_collection_if_not_exists : Optional [
821
+ bool ] = None ,
822
+ leases_collection_throughput : Optional [int ] = None ,
823
+ lease_collection_prefix : Optional [str ] = None ,
824
+ checkpoint_interval : Optional [int ] = None ,
825
+ checkpoint_document_count : Optional [int ] = None ,
826
+ feed_poll_delay : Optional [int ] = None ,
827
+ lease_renew_interval : Optional [int ] = None ,
828
+ lease_acquire_interval : Optional [int ] = None ,
829
+ lease_expiration_interval : Optional [int ] = None ,
830
+ max_items_per_invocation : Optional [int ] = None ,
831
+ start_from_beginning : Optional [bool ] = None ,
832
+ preferred_locations : Optional [str ] = None ,
833
+ data_type : Optional [
834
+ Union [DataType , str ]] = None ) -> \
852
835
Callable :
853
- """The on_cosmos_db_update decorator adds :class:`CosmosDBTrigger`
836
+ """The cosmos_db_trigger decorator adds :class:`CosmosDBTrigger`
854
837
to the :class:`FunctionBuilder` object
855
838
for building :class:`Function` object used in worker function
856
839
indexing model. This is equivalent to defining CosmosDBTrigger
@@ -1074,13 +1057,13 @@ def decorator():
1074
1057
1075
1058
return wrap
1076
1059
1077
- def on_blob_change (self ,
1078
- arg_name : str ,
1079
- path : str ,
1080
- connection : str ,
1081
- data_type : Optional [DataType ] = None ) -> Callable :
1060
+ def blob_trigger (self ,
1061
+ arg_name : str ,
1062
+ path : str ,
1063
+ connection : str ,
1064
+ data_type : Optional [DataType ] = None ) -> Callable :
1082
1065
"""
1083
- The on_blob_change decorator adds :class:`BlobTrigger` to the
1066
+ The blob_change_trigger decorator adds :class:`BlobTrigger` to the
1084
1067
:class:`FunctionBuilder` object
1085
1068
for building :class:`Function` object used in worker function
1086
1069
indexing model. This is equivalent to defining BlobTrigger
0 commit comments