Skip to content

Commit 0e6f7af

Browse files
feat: Add function to process the passcmd for API key retrieval.
1 parent 929e71e commit 0e6f7af

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

zulip/zulip/__init__.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import platform
77
import random
8+
import subprocess
89
import sys
910
import time
1011
import 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.

0 commit comments

Comments
 (0)