11# Copyright (c) Microsoft Corporation. All rights reserved.
22# Licensed under the MIT License.
3+ import abc
34import json
45import logging
56from abc import ABC
@@ -254,8 +255,7 @@ def app_script_file(self) -> str:
254255 return self ._app_script_file
255256
256257 def _validate_type (self ,
257- func : Union [Callable [..., Any ],
258- FunctionBuilder ]) \
258+ func : Union [Callable [..., Any ], FunctionBuilder ]) \
259259 -> FunctionBuilder :
260260 """Validate the type of the function object and return the created
261261 :class:`FunctionBuilder` object.
@@ -817,7 +817,7 @@ def cosmos_db_trigger_v3(self,
817817 lease_collection_name = lease_collection_name ,
818818 lease_connection_string_setting = lease_connection_string_setting ,
819819 lease_database_name = lease_database_name ,
820- create_lease_collection_if_not_exists = create_lease_collection_if_not_exists , # NoQA
820+ create_lease_collection_if_not_exists = create_lease_collection_if_not_exists , # NoQA
821821 leases_collection_throughput = leases_collection_throughput ,
822822 lease_collection_prefix = lease_collection_prefix ,
823823 checkpoint_interval = checkpoint_interval ,
@@ -2014,7 +2014,24 @@ class Blueprint(TriggerApi, BindingApi):
20142014 pass
20152015
20162016
2017- class AsgiFunctionApp (FunctionRegister , TriggerApi ):
2017+ class ExternalHttpFunctionApp (FunctionRegister , TriggerApi , ABC ):
2018+ """Interface to extend for building third party http function apps."""
2019+
2020+ @abc .abstractmethod
2021+ def _add_http_app (self ,
2022+ http_middleware : Union [
2023+ AsgiMiddleware , WsgiMiddleware ]) -> None :
2024+ """Add a Wsgi or Asgi app integrated http function.
2025+
2026+ :param http_middleware: :class:`WsgiMiddleware`
2027+ or class:`AsgiMiddleware` instance.
2028+
2029+ :return: None
2030+ """
2031+ raise NotImplementedError ()
2032+
2033+
2034+ class AsgiFunctionApp (ExternalHttpFunctionApp ):
20182035 def __init__ (self , app ,
20192036 http_auth_level : Union [AuthLevel , str ] = AuthLevel .FUNCTION ):
20202037 """Constructor of :class:`AsgiFunctionApp` object.
@@ -2027,13 +2044,21 @@ def __init__(self, app,
20272044 super ().__init__ (auth_level = http_auth_level )
20282045 self ._add_http_app (AsgiMiddleware (app ))
20292046
2030- def _add_http_app (self , asgi_middleware : AsgiMiddleware ) -> None :
2047+ def _add_http_app (self ,
2048+ http_middleware : Union [
2049+ AsgiMiddleware , WsgiMiddleware ]) -> None :
20312050 """Add an Asgi app integrated http function.
20322051
2033- :param asgi_middleware: :class:`AsgiMiddleware` instance.
2052+ :param http_middleware: :class:`WsgiMiddleware`
2053+ or class:`AsgiMiddleware` instance.
20342054
20352055 :return: None
20362056 """
2057+ if not isinstance (http_middleware , AsgiMiddleware ):
2058+ raise TypeError ("Please pass AsgiMiddleware instance"
2059+ " as parameter." )
2060+
2061+ asgi_middleware : AsgiMiddleware = http_middleware
20372062
20382063 @self .http_type (http_type = 'asgi' )
20392064 @self .route (methods = (method for method in HttpMethod ),
@@ -2043,7 +2068,7 @@ async def http_app_func(req: HttpRequest, context: Context):
20432068 return await asgi_middleware .handle_async (req , context )
20442069
20452070
2046- class WsgiFunctionApp (FunctionRegister , TriggerApi ):
2071+ class WsgiFunctionApp (ExternalHttpFunctionApp ):
20472072 def __init__ (self , app ,
20482073 http_auth_level : Union [AuthLevel , str ] = AuthLevel .FUNCTION ):
20492074 """Constructor of :class:`WsgiFunctionApp` object.
@@ -2054,13 +2079,20 @@ def __init__(self, app,
20542079 self ._add_http_app (WsgiMiddleware (app ))
20552080
20562081 def _add_http_app (self ,
2057- wsgi_middleware : WsgiMiddleware ) -> None :
2082+ http_middleware : Union [
2083+ AsgiMiddleware , WsgiMiddleware ]) -> None :
20582084 """Add a Wsgi app integrated http function.
20592085
2060- :param wsgi_middleware: :class:`WsgiMiddleware` instance.
2086+ :param http_middleware: :class:`WsgiMiddleware`
2087+ or class:`AsgiMiddleware` instance.
20612088
20622089 :return: None
20632090 """
2091+ if not isinstance (http_middleware , WsgiMiddleware ):
2092+ raise TypeError ("Please pass WsgiMiddleware instance"
2093+ " as parameter." )
2094+
2095+ wsgi_middleware : WsgiMiddleware = http_middleware
20642096
20652097 @self .http_type (http_type = 'wsgi' )
20662098 @self .route (methods = (method for method in HttpMethod ),
0 commit comments