File tree 1 file changed +11
-1
lines changed
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 5
5
import os
6
6
import platform
7
7
import random
8
+ import subprocess
8
9
import sys
9
10
import time
10
11
import traceback
@@ -425,7 +426,8 @@ def __init__(
425
426
with open (config_file ) as f :
426
427
config .read_file (f , config_file )
427
428
if api_key is None :
428
- api_key = config .get ("api" , "key" )
429
+ passcmd = config .get ("api" , "passcmd" )
430
+ api_key = self .get_api_key (passcmd )
429
431
if email is None :
430
432
email = config .get ("api" , "email" )
431
433
if site is None and config .has_option ("api" , "site" ):
@@ -512,6 +514,14 @@ def __init__(
512
514
self .feature_level : int = server_settings .get ("zulip_feature_level" , 0 )
513
515
assert self .zulip_version is not None
514
516
517
+ def get_api_key (self , passcmd : str ) -> Optional [str ]:
518
+ # run the passcmd command and get the API key
519
+ result = subprocess .run (passcmd .split (), capture_output = True , check = False )
520
+ if result .returncode == 0 :
521
+ return result .stdout .decode ().strip ()
522
+ else :
523
+ raise RuntimeError ("Error: Unable to retrieve API key." )
524
+
515
525
def ensure_session (self ) -> None :
516
526
# Check if the session has been created already, and return
517
527
# immediately if so.
You can’t perform that action at this time.
0 commit comments