Skip to content

Commit 91fcece

Browse files
author
Corentin
committed
Add automatic TLS certificate check+download
1 parent 1f9e413 commit 91fcece

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

snippet.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
import os
2+
from pathlib import Path
3+
import urllib.request
4+
15
from pyarrow import flight
26

3-
client = flight.connect('grpc+tls://flight.spiceai.io')
47

8+
# Check for gRPC required Google certificate file
9+
tls_root_certs = None
10+
if not Path('/usr', 'share', 'grpc', 'roots.pem').exists():
11+
env_name = 'GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'
12+
if env_name in os.environ and not Path(os.environ[env_name]).exists():
13+
print('Downloading gRPS root certificates')
14+
tls_root_certs = './roots.pem'
15+
urllib.request.urlretrieve('https://pki.google.com/roots.pem', tls_root_certs)
16+
17+
client = flight.connect('grpc+tls://flight.spiceai.io', tls_root_certs=tls_root_certs)
518
headers = [client.authenticate_basic_token('', 'API_KEY')]
619
options = flight.FlightCallOptions(headers=headers)
720

0 commit comments

Comments
 (0)