Skip to content

Commit 2d67724

Browse files
Support https for microservice (#293)
* 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>
1 parent f164f0d commit 2d67724

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

comps/cores/mega/micro_service.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def __init__(
2323
protocol: str = "http",
2424
host: str = "localhost",
2525
port: int = 8080,
26+
ssl_keyfile: Optional[str] = None,
27+
ssl_certfile: Optional[str] = None,
2628
endpoint: Optional[str] = "/",
2729
input_datatype: Type[Any] = TextDoc,
2830
output_datatype: Type[Any] = TextDoc,
@@ -42,6 +44,13 @@ def __init__(
4244
self.input_datatype = input_datatype
4345
self.output_datatype = output_datatype
4446
self.use_remote_service = use_remote_service
47+
self.uvicorn_kwargs = {}
48+
49+
if ssl_keyfile:
50+
self.uvicorn_kwargs["ssl_keyfile"] = ssl_keyfile
51+
52+
if ssl_certfile:
53+
self.uvicorn_kwargs["ssl_certfile"] = ssl_certfile
4554

4655
if not use_remote_service:
4756
self.replicas = replicas
@@ -81,7 +90,7 @@ def _get_server(self):
8190
"description": "OPEA Microservice Infrastructure",
8291
}
8392

84-
return HTTPService(runtime_args=runtime_args)
93+
return HTTPService(uvicorn_kwargs=self.uvicorn_kwargs, runtime_args=runtime_args)
8594

8695
async def _async_setup(self):
8796
"""The async method setup the runtime.
@@ -140,6 +149,8 @@ def register_microservice(
140149
protocol: str = "http",
141150
host: str = "localhost",
142151
port: int = 8080,
152+
ssl_keyfile: Optional[str] = None,
153+
ssl_certfile: Optional[str] = None,
143154
endpoint: Optional[str] = "/",
144155
input_datatype: Type[Any] = TextDoc,
145156
output_datatype: Type[Any] = TextDoc,
@@ -155,6 +166,8 @@ def decorator(func):
155166
protocol=protocol,
156167
host=host,
157168
port=port,
169+
ssl_keyfile=ssl_keyfile,
170+
ssl_certfile=ssl_certfile,
158171
endpoint=endpoint,
159172
input_datatype=input_datatype,
160173
output_datatype=output_datatype,

0 commit comments

Comments
 (0)