From 2d6772456fb24cd344fc25e3eb4591d1a42eda71 Mon Sep 17 00:00:00 2001 From: lvliang-intel Date: Mon, 15 Jul 2024 14:13:59 +0800 Subject: [PATCH] Support https for microservice (#293) * Support https for microservice Signed-off-by: lvliang-intel --------- Signed-off-by: lvliang-intel Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- comps/cores/mega/micro_service.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/comps/cores/mega/micro_service.py b/comps/cores/mega/micro_service.py index e1ac0d8a2..659bf495d 100644 --- a/comps/cores/mega/micro_service.py +++ b/comps/cores/mega/micro_service.py @@ -23,6 +23,8 @@ def __init__( protocol: str = "http", host: str = "localhost", port: int = 8080, + ssl_keyfile: Optional[str] = None, + ssl_certfile: Optional[str] = None, endpoint: Optional[str] = "/", input_datatype: Type[Any] = TextDoc, output_datatype: Type[Any] = TextDoc, @@ -42,6 +44,13 @@ def __init__( self.input_datatype = input_datatype self.output_datatype = output_datatype self.use_remote_service = use_remote_service + self.uvicorn_kwargs = {} + + if ssl_keyfile: + self.uvicorn_kwargs["ssl_keyfile"] = ssl_keyfile + + if ssl_certfile: + self.uvicorn_kwargs["ssl_certfile"] = ssl_certfile if not use_remote_service: self.replicas = replicas @@ -81,7 +90,7 @@ def _get_server(self): "description": "OPEA Microservice Infrastructure", } - return HTTPService(runtime_args=runtime_args) + return HTTPService(uvicorn_kwargs=self.uvicorn_kwargs, runtime_args=runtime_args) async def _async_setup(self): """The async method setup the runtime. @@ -140,6 +149,8 @@ def register_microservice( protocol: str = "http", host: str = "localhost", port: int = 8080, + ssl_keyfile: Optional[str] = None, + ssl_certfile: Optional[str] = None, endpoint: Optional[str] = "/", input_datatype: Type[Any] = TextDoc, output_datatype: Type[Any] = TextDoc, @@ -155,6 +166,8 @@ def decorator(func): protocol=protocol, host=host, port=port, + ssl_keyfile=ssl_keyfile, + ssl_certfile=ssl_certfile, endpoint=endpoint, input_datatype=input_datatype, output_datatype=output_datatype,