File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 55import os
66import platform
77import random
8+ import subprocess
89import sys
910import time
1011import traceback
@@ -425,7 +426,8 @@ def __init__(
425426 with open (config_file ) as f :
426427 config .read_file (f , config_file )
427428 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 )
429431 if email is None :
430432 email = config .get ("api" , "email" )
431433 if site is None and config .has_option ("api" , "site" ):
@@ -512,6 +514,14 @@ def __init__(
512514 self .feature_level : int = server_settings .get ("zulip_feature_level" , 0 )
513515 assert self .zulip_version is not None
514516
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+
515525 def ensure_session (self ) -> None :
516526 # Check if the session has been created already, and return
517527 # immediately if so.
You can’t perform that action at this time.
0 commit comments