swap to dedicated @coe-mirror-bot for Matrix sends
Replaces shared @intel-bot credentials with a Matrix user created specifically for this tool. Reads Infisical keys via constants COE_MIRROR_BOT_USER_KEY and COE_MIRROR_BOT_PASSWORD_KEY so test assertions track the code rather than hardcoded strings.
This commit is contained in:
+6
-3
@@ -43,6 +43,8 @@ MATRIX_ROOM = "!MBpPtYlQYMcngtpvJt:m.mealeyfamily.com" # General
|
||||
MATRIX_TOKEN_CACHE = LOG_DIR / "matrix-token.json"
|
||||
MATRIX_TIMEOUT = 8
|
||||
MATRIX_REFRESH_THRESHOLD_SECONDS = 1800 # refresh if <30 min left
|
||||
COE_MIRROR_BOT_USER_KEY = "COE_MIRROR_BOT_USER"
|
||||
COE_MIRROR_BOT_PASSWORD_KEY = "COE_MIRROR_BOT_PASSWORD"
|
||||
|
||||
# Allow env var overrides for testing and deployment flexibility
|
||||
if env_pcloud := os.getenv("COE_MIRROR_PCLOUD_TARGET"):
|
||||
@@ -344,18 +346,19 @@ def _fetch_creds() -> Optional[Tuple[str, str]]:
|
||||
"""Fetch (user, password) from Infisical via creds. Return None on failure."""
|
||||
try:
|
||||
user = subprocess.run(
|
||||
["creds", "get", "MATRIX_USER", "matrix"],
|
||||
["creds", "get", COE_MIRROR_BOT_USER_KEY, "matrix"],
|
||||
capture_output=True, text=True, timeout=5
|
||||
)
|
||||
pw = subprocess.run(
|
||||
["creds", "get", "MATRIX_PASSWORD", "matrix"],
|
||||
["creds", "get", COE_MIRROR_BOT_PASSWORD_KEY, "matrix"],
|
||||
capture_output=True, text=True, timeout=5
|
||||
)
|
||||
if user.returncode == 0 and pw.returncode == 0:
|
||||
u, p = user.stdout.strip(), pw.stdout.strip()
|
||||
if u and p:
|
||||
return u, p
|
||||
logger.warning("creds returned non-zero for MATRIX_USER/MATRIX_PASSWORD")
|
||||
logger.warning("creds returned non-zero for %s/%s",
|
||||
COE_MIRROR_BOT_USER_KEY, COE_MIRROR_BOT_PASSWORD_KEY)
|
||||
except FileNotFoundError:
|
||||
logger.warning("creds binary not found on PATH")
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -701,9 +701,9 @@ class TestMatrixTokenRefreshOn401:
|
||||
fake_result_pass.stdout = "test_pass"
|
||||
|
||||
def mock_subprocess_run(cmd, **kwargs):
|
||||
if cmd[2] == "MATRIX_USER":
|
||||
if cmd[2] == coe_mirror.COE_MIRROR_BOT_USER_KEY:
|
||||
return fake_result_user
|
||||
elif cmd[2] == "MATRIX_PASSWORD":
|
||||
elif cmd[2] == coe_mirror.COE_MIRROR_BOT_PASSWORD_KEY:
|
||||
return fake_result_pass
|
||||
return MagicMock(returncode=1, stdout="")
|
||||
|
||||
@@ -794,9 +794,9 @@ class TestMatrixLoginWritesCacheChmod600:
|
||||
fake_result_pass.stdout = "testpass"
|
||||
|
||||
def mock_subprocess_run(cmd, **kwargs):
|
||||
if cmd[2] == "MATRIX_USER":
|
||||
if cmd[2] == coe_mirror.COE_MIRROR_BOT_USER_KEY:
|
||||
return fake_result_user
|
||||
elif cmd[2] == "MATRIX_PASSWORD":
|
||||
elif cmd[2] == coe_mirror.COE_MIRROR_BOT_PASSWORD_KEY:
|
||||
return fake_result_pass
|
||||
return MagicMock(returncode=1, stdout="")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user