Skip to content

Commit 04ea33b

Browse files
YunchuWangpeterstone2017vrdmr
authored
Address pyspec feedback (#112)
Changes involving: 1. FunctionApp __init__ auth_level -> http_auth_level 2. FunctionApp __init__ remove app_kwargs 3. FunctionApp __init__ change asgi_app/wsgi_app to kwargs 4. Remove data type from route 5. Change all trigger decorators to noun naming Co-authored-by: peterstone2017 <[email protected]> Co-authored-by: Varad Meru <[email protected]>
1 parent 4bb65c1 commit 04ea33b

File tree

4 files changed

+175
-195
lines changed

4 files changed

+175
-195
lines changed

azure/functions/decorators/function_app.py

Lines changed: 78 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33
import json
4-
import typing
54
from typing import Callable, Dict, List, Optional, Union, Iterable
65

76
from azure.functions.decorators.blob import BlobTrigger, BlobInput, BlobOutput
@@ -192,29 +191,33 @@ class FunctionApp:
192191
"""
193192

194193
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):
199196
"""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__`.
207207
"""
208208
self._function_builders: List[FunctionBuilder] = []
209209
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)
212215

213216
if wsgi_app is not None:
214-
self._add_http_app(WsgiMiddleware(wsgi_app), app_kwargs)
217+
self._add_http_app(WsgiMiddleware(wsgi_app))
215218

216219
if asgi_app is not None:
217-
self._add_http_app(AsgiMiddleware(asgi_app), app_kwargs)
220+
self._add_http_app(AsgiMiddleware(asgi_app))
218221

219222
@property
220223
def app_script_file(self) -> str:
@@ -296,28 +299,18 @@ def decorator():
296299
return wrap
297300

298301
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:
301304
"""Add a Wsgi or Asgi app integrated http function.
302305
303306
:param http_middleware: :class:`AsgiMiddleware` or
304307
:class:`WsgiMiddleware` instance.
305-
:param app_kwargs: dict of :meth:`route` param names and values for
306-
custom configuration of wsgi/asgi app.
307308
308309
:return: None
309310
"""
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,
321314
route="/{*route}")
322315
def http_app_func(req: HttpRequest, context: Context):
323316
return http_middleware.handle(req, context)
@@ -326,8 +319,6 @@ def route(self,
326319
route: Optional[str] = None,
327320
trigger_arg_name: str = 'req',
328321
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,
331322
methods: Optional[
332323
Union[Iterable[str], Iterable[HttpMethod]]] = None,
333324
auth_level: Optional[Union[AuthLevel, str]] = None) -> Callable:
@@ -348,10 +339,6 @@ def route(self,
348339
defaults to 'req'.
349340
:param binding_arg_name: Argument name for :class:`HttpResponse`,
350341
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.
355342
:param methods: A tuple of the HTTP methods to which the function
356343
responds.
357344
:param auth_level: Determines what keys, if any, need to be present
@@ -368,18 +355,11 @@ def decorator():
368355

369356
fb.add_trigger(trigger=HttpTrigger(
370357
name=trigger_arg_name,
371-
data_type=parse_singular_param_to_enum(
372-
trigger_arg_data_type,
373-
DataType),
374358
methods=parse_iterable_param_to_enums(methods, HttpMethod),
375359
auth_level=parse_singular_param_to_enum(auth_level,
376360
AuthLevel),
377361
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))
383363
return fb
384364

385365
return decorator()
@@ -433,7 +413,7 @@ def decorator():
433413

434414
return wrap
435415

436-
def on_service_bus_queue_change(
416+
def service_bus_queue_trigger(
437417
self,
438418
arg_name: str,
439419
connection: str,
@@ -442,7 +422,7 @@ def on_service_bus_queue_change(
442422
access_rights: Optional[Union[AccessRights, str]] = None,
443423
is_sessions_enabled: Optional[bool] = None,
444424
cardinality: Optional[Union[Cardinality, str]] = None) -> Callable:
445-
"""The on_service_bus_queue_change decorator adds
425+
"""The service_bus_queue_trigger decorator adds
446426
:class:`ServiceBusQueueTrigger` to the :class:`FunctionBuilder` object
447427
for building :class:`Function` object used in worker function
448428
indexing model. This is equivalent to defining ServiceBusQueueTrigger
@@ -537,7 +517,7 @@ def decorator():
537517

538518
return wrap
539519

540-
def on_service_bus_topic_change(
520+
def service_bus_topic_trigger(
541521
self,
542522
arg_name: str,
543523
connection: str,
@@ -547,7 +527,7 @@ def on_service_bus_topic_change(
547527
access_rights: Optional[Union[AccessRights, str]] = None,
548528
is_sessions_enabled: Optional[bool] = None,
549529
cardinality: Optional[Union[Cardinality, str]] = None) -> Callable:
550-
"""The on_service_bus_topic_change decorator adds
530+
"""The service_bus_topic_trigger decorator adds
551531
:class:`ServiceBusTopicTrigger` to the :class:`FunctionBuilder` object
552532
for building :class:`Function` object used in worker function
553533
indexing model. This is equivalent to defining ServiceBusTopicTrigger
@@ -648,12 +628,12 @@ def decorator():
648628

649629
return wrap
650630

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
657637
:class:`FunctionBuilder` object
658638
for building :class:`Function` object used in worker function
659639
indexing model. This is equivalent to defining QueueTrigger
@@ -731,15 +711,18 @@ def decorator():
731711

732712
return wrap
733713

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`
743726
to the :class:`FunctionBuilder` object
744727
for building :class:`Function` object used in worker function
745728
indexing model. This is equivalent to defining EventHubTrigger
@@ -825,32 +808,32 @@ def decorator():
825808

826809
return wrap
827810

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) -> \
852835
Callable:
853-
"""The on_cosmos_db_update decorator adds :class:`CosmosDBTrigger`
836+
"""The cosmos_db_trigger decorator adds :class:`CosmosDBTrigger`
854837
to the :class:`FunctionBuilder` object
855838
for building :class:`Function` object used in worker function
856839
indexing model. This is equivalent to defining CosmosDBTrigger
@@ -1074,13 +1057,13 @@ def decorator():
10741057

10751058
return wrap
10761059

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:
10821065
"""
1083-
The on_blob_change decorator adds :class:`BlobTrigger` to the
1066+
The blob_change_trigger decorator adds :class:`BlobTrigger` to the
10841067
:class:`FunctionBuilder` object
10851068
for building :class:`Function` object used in worker function
10861069
indexing model. This is equivalent to defining BlobTrigger

0 commit comments

Comments
 (0)