|
1 | 1 | from collections.abc import Callable, Sequence |
2 | 2 | from typing import TypeVar |
3 | 3 |
|
4 | | -from _tilebox.grpc.channel import CHANNEL_OPTIONS, ChannelInfo, add_metadata, parse_channel_info |
5 | | -from grpc import ssl_channel_credentials |
| 4 | +from _tilebox.grpc.channel import CHANNEL_OPTIONS, ChannelInfo, ChannelProtocol, add_metadata, parse_channel_info |
| 5 | +from grpc import Compression, ssl_channel_credentials |
6 | 6 | from grpc.aio import ( |
7 | 7 | Channel, |
8 | 8 | ClientCallDetails, |
@@ -34,11 +34,28 @@ def open_channel(url: str, auth_token: str | None = None) -> Channel: |
34 | 34 |
|
35 | 35 |
|
36 | 36 | def _open_channel(channel_info: ChannelInfo, interceptors: Sequence[ClientInterceptor]) -> Channel: |
37 | | - if channel_info.use_ssl: |
38 | | - return secure_channel( |
39 | | - channel_info.address, ssl_channel_credentials(), CHANNEL_OPTIONS, interceptors=interceptors |
40 | | - ) |
41 | | - return insecure_channel(channel_info.address, CHANNEL_OPTIONS, interceptors=interceptors) |
| 37 | + match channel_info.protocol: |
| 38 | + case ChannelProtocol.HTTPS: |
| 39 | + return secure_channel( |
| 40 | + f"{channel_info.address}:{channel_info.port}", |
| 41 | + ssl_channel_credentials(), |
| 42 | + CHANNEL_OPTIONS, |
| 43 | + compression=Compression.Gzip, |
| 44 | + interceptors=interceptors, |
| 45 | + ) |
| 46 | + case ChannelProtocol.HTTP: |
| 47 | + return insecure_channel( |
| 48 | + f"{channel_info.address}:{channel_info.port}", |
| 49 | + CHANNEL_OPTIONS, |
| 50 | + compression=Compression.NoCompression, |
| 51 | + interceptors=interceptors, |
| 52 | + ) |
| 53 | + case ChannelProtocol.UNIX: |
| 54 | + return insecure_channel( |
| 55 | + channel_info.address, CHANNEL_OPTIONS, compression=Compression.NoCompression, interceptors=interceptors |
| 56 | + ) |
| 57 | + case _: |
| 58 | + raise ValueError(f"Unsupported channel protocol: {channel_info.protocol}") |
42 | 59 |
|
43 | 60 |
|
44 | 61 | RequestType = TypeVar("RequestType") |
|
0 commit comments