Skip to content

Commit 4a9bf9e

Browse files
add ssl support for realtime api (nvidia-riva#148)
* add ssl support for realtime api * add option to open aio channel * add websockets to requirements
1 parent 94845c3 commit 4a9bf9e

File tree

4 files changed

+166
-128
lines changed

4 files changed

+166
-128
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
setuptools==78.1.1
22
grpcio==1.67.1
33
grpcio-tools==1.67.1
4+
websockets==15.0.1

riva/client/auth.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def create_channel(
1515
uri: str = "localhost:50051",
1616
metadata: Optional[List[Tuple[str, str]]] = None,
1717
options: Optional[List[Tuple[str, str]]] = [],
18+
use_aio: Optional[bool] = False,
1819
) -> grpc.Channel:
1920
def metadata_callback(context, callback):
2021
callback(metadata, None)
@@ -39,9 +40,15 @@ def metadata_callback(context, callback):
3940
if metadata:
4041
auth_creds = grpc.metadata_call_credentials(metadata_callback)
4142
creds = grpc.composite_channel_credentials(creds, auth_creds)
42-
channel = grpc.secure_channel(uri, creds, options=options)
43+
if use_aio:
44+
channel = grpc.aio.secure_channel(uri, creds, options=options)
45+
else:
46+
channel = grpc.secure_channel(uri, creds, options=options)
4347
else:
44-
channel = grpc.insecure_channel(uri, options=options)
48+
if use_aio:
49+
channel = grpc.aio.insecure_channel(uri, options=options)
50+
else:
51+
channel = grpc.insecure_channel(uri, options=options)
4552
return channel
4653

4754

@@ -55,6 +62,7 @@ def __init__(
5562
ssl_client_cert: Optional[Union[str, os.PathLike]] = None,
5663
ssl_client_key: Optional[Union[str, os.PathLike]] = None,
5764
options: Optional[List[Tuple[str, str]]] = [],
65+
use_aio: bool = False,
5866
) -> None:
5967
"""
6068
Initialize the Auth class for establishing secure connections with a server.
@@ -76,6 +84,7 @@ def __init__(
7684
Used for mutual TLS authentication. Defaults to None.
7785
options (Optional[List[Tuple[str, str]]], optional): Additional gRPC channel options.
7886
Each tuple should contain (option_name, option_value). Defaults to [].
87+
use_aio (bool, optional): Whether to use asyncio for the channel. Defaults to False.
7988
8089
Raises:
8190
ValueError: If any metadata argument doesn't contain exactly 2 elements (key-value pair).
@@ -111,7 +120,14 @@ def __init__(
111120
)
112121
self.metadata.append(tuple(meta))
113122
self.channel: grpc.Channel = create_channel(
114-
self.ssl_root_cert, self.ssl_client_cert, self.ssl_client_key, self.use_ssl, self.uri, self.metadata, options=options
123+
self.ssl_root_cert,
124+
self.ssl_client_cert,
125+
self.ssl_client_key,
126+
self.use_ssl,
127+
self.uri,
128+
self.metadata,
129+
options=options,
130+
use_aio=use_aio,
115131
)
116132

117133
def get_auth_metadata(self) -> List[Tuple[str, str]]:

0 commit comments

Comments
 (0)