20
20
from btrdb .exceptions import ConnectionError
21
21
from btrdb .version import get_version
22
22
from btrdb .utils .credentials import credentials_by_profile , credentials
23
+ from btrdb .utils .ray import register_serializer
23
24
from btrdb .stream import MINIMUM_TIME , MAXIMUM_TIME
25
+ from warnings import warn
24
26
25
27
##########################################################################
26
28
## Module Variables
40
42
def _connect (endpoints = None , apikey = None ):
41
43
return BTrDB (Endpoint (Connection (endpoints , apikey = apikey ).channel ))
42
44
43
- def connect (conn_str = None , apikey = None , profile = None ):
45
+ def connect (conn_str = None , apikey = None , profile = None , shareable = False ):
44
46
"""
45
47
Connect to a BTrDB server.
46
48
@@ -57,6 +59,12 @@ def connect(conn_str=None, apikey=None, profile=None):
57
59
The name of a profile containing the required connection information as
58
60
found in the user's predictive grid credentials file
59
61
`~/.predictivegrid/credentials.yaml`.
62
+ shareable: bool, default=False
63
+ Whether or not the connection can be "shared" in a distributed setting such
64
+ as Ray workers. If set to True, the connection can be serialized and sent
65
+ to other workers so that data can be retrieved in parallel; **however**, this
66
+ is less secure because it is possible for other users of the Ray cluster to
67
+ use your API key to fetch data.
60
68
61
69
Returns
62
70
-------
@@ -68,6 +76,11 @@ def connect(conn_str=None, apikey=None, profile=None):
68
76
if conn_str and profile :
69
77
raise ValueError ("Received both conn_str and profile arguments." )
70
78
79
+ # check shareable flag and register custom serializer if necessary
80
+ if shareable :
81
+ warn ("a shareable connection is potentially insecure; other users of the same cluster may be able to access your API key" )
82
+ register_serializer (conn_str = conn_str , apikey = apikey , profile = profile )
83
+
71
84
# use specific profile if requested
72
85
if profile :
73
86
return _connect (** credentials_by_profile (profile ))
0 commit comments