communication: switch atlasbot to MAS login

This commit is contained in:
Brad Stein 2025-12-31 17:26:37 -03:00
parent be2c2ba33e
commit bfd1c5dd49
2 changed files with 9 additions and 6 deletions

View File

@ -9,6 +9,7 @@ data:
from urllib import request, parse, error from urllib import request, parse, error
BASE = os.environ.get("MATRIX_BASE", "http://othrys-synapse-matrix-synapse:8008") BASE = os.environ.get("MATRIX_BASE", "http://othrys-synapse-matrix-synapse:8008")
AUTH_BASE = os.environ.get("AUTH_BASE", "http://matrix-authentication-service:8080")
USER = os.environ["BOT_USER"] USER = os.environ["BOT_USER"]
PASSWORD = os.environ["BOT_PASS"] PASSWORD = os.environ["BOT_PASS"]
ROOM_ALIAS = "#othrys:live.bstein.dev" ROOM_ALIAS = "#othrys:live.bstein.dev"
@ -16,8 +17,8 @@ data:
MODEL = os.environ.get("OLLAMA_MODEL", "qwen2.5-coder:7b-instruct-q4_0") MODEL = os.environ.get("OLLAMA_MODEL", "qwen2.5-coder:7b-instruct-q4_0")
API_KEY = os.environ.get("CHAT_API_KEY", "") API_KEY = os.environ.get("CHAT_API_KEY", "")
def req(method: str, path: str, token: str | None = None, body=None, timeout=60): def req(method: str, path: str, token: str | None = None, body=None, timeout=60, base: str | None = None):
url = BASE + path url = (base or BASE) + path
data = None data = None
headers = {} headers = {}
if body is not None: if body is not None:
@ -36,7 +37,7 @@ data:
"identifier": {"type": "m.id.user", "user": USER}, "identifier": {"type": "m.id.user", "user": USER},
"password": PASSWORD, "password": PASSWORD,
} }
res = req("POST", "/_matrix/client/v3/login", body=payload) res = req("POST", "/_matrix/client/v3/login", body=payload, base=AUTH_BASE)
return res["access_token"] return res["access_token"]
def resolve_alias(token: str, alias: str) -> str: def resolve_alias(token: str, alias: str) -> str:

View File

@ -28,13 +28,15 @@ spec:
env: env:
- name: MATRIX_BASE - name: MATRIX_BASE
value: http://othrys-synapse-matrix-synapse:8008 value: http://othrys-synapse-matrix-synapse:8008
- name: AUTH_BASE
value: http://matrix-authentication-service:8080
- name: BOT_USER - name: BOT_USER
value: atlasbot value: atlas
- name: BOT_PASS - name: BOT_PASS
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: atlasbot-credentials-runtime name: atlasbot-mas-credentials-runtime
key: bot-password key: password
- name: CHAT_API_KEY - name: CHAT_API_KEY
valueFrom: valueFrom:
secretKeyRef: secretKeyRef: