Skip to content

Commit e804097

Browse files
authored
make tokens optional if not running interactively (#37)
Co-authored-by: Ankit Saini <[email protected]>
1 parent 101a79a commit e804097

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

singlestoredb/apps/_config.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ def from_env(cls) -> 'AppConfig':
3535
app_token = os.environ.get('SINGLESTOREDB_APP_TOKEN')
3636
user_token = os.environ.get('SINGLESTOREDB_USER_TOKEN')
3737

38-
if is_gateway_enabled:
39-
# Make sure the required variables are present
40-
# and present useful error message if not
41-
app_token = cls._read_variable('SINGLESTOREDB_APP_TOKEN')
42-
else:
43-
user_token = cls._read_variable('SINGLESTOREDB_USER_TOKEN')
38+
# Make sure the required variables are present
39+
# and present useful error message if not
40+
if running_interactively:
41+
if is_gateway_enabled:
42+
app_token = cls._read_variable('SINGLESTOREDB_APP_TOKEN')
43+
else:
44+
user_token = cls._read_variable('SINGLESTOREDB_USER_TOKEN')
4445

4546
return cls(
4647
listen_port=int(port),
@@ -52,12 +53,11 @@ def from_env(cls) -> 'AppConfig':
5253
)
5354

5455
@property
55-
def token(self) -> str:
56+
def token(self) -> Optional[str]:
57+
"""
58+
Returns None if running non-interactively
59+
"""
5660
if self.is_gateway_enabled:
57-
# We make sure this is not null while constructing the object
58-
assert self.app_token is not None
5961
return self.app_token
6062
else:
61-
# We make sure this is not null while constructing the object
62-
assert self.user_token is not None
6363
return self.user_token
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from dataclasses import dataclass
2+
from typing import Optional
23

34

45
@dataclass
56
class ConnectionInfo:
67
url: str
7-
token: str
8+
9+
# Only present in interactive mode
10+
token: Optional[str]

0 commit comments

Comments
 (0)