Skip to content

Commit

Permalink
Support https for microservice (#293)
Browse files Browse the repository at this point in the history
* Support https for microservice

Signed-off-by: lvliang-intel <[email protected]>

---------

Signed-off-by: lvliang-intel <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
lvliang-intel and pre-commit-ci[bot] authored Jul 15, 2024
1 parent f164f0d commit 2d67724
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion comps/cores/mega/micro_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 2d67724

Please sign in to comment.