feat: API Key pro Agent statt pro User
- Neue Tabelle agent_api_keys (user_id, agent_id, key_id) - Migration: bestehende selected_api_key_id auf alle Agents verteilt - Backend: GetAgentApiKeyRecord(userId, agentId) in Chat, Telegram, Cronjobs - Endpoints: select/selected mit ?agentId Query-Parameter - Frontend: currentAgentId aus Session, alle Key-Calls agent-aware - DeleteApiKey bereinigt agent_api_keys statt users.selected_api_key_id
This commit is contained in:
1 parent
b04b1a2cf9
commit
1effc6d00f
10 files changed
+128
-43
No files matched your search
@@ -86,10 +86,10 @@ public class CronjobService : BackgroundService
|
||||
if (ctx == null)
|
||||
throw new Exception("Session oder Agent nicht gefunden / nicht konfiguriert");
|
||||
|
||||
// API-Key des Cronjob-Owners auflösen
|
||||
var userApiKey = await _db.GetUserSelectedApiKey(job.UserId);
|
||||
// API-Key des Cronjob-Owners für diesen Agent auflösen
|
||||
var userApiKey = await _db.GetAgentApiKeyRecord(job.UserId, ctx.AgentId);
|
||||
if (userApiKey == null)
|
||||
throw new Exception($"Kein API-Key für User {job.UserId} ausgewählt");
|
||||
throw new Exception($"Kein API-Key für Agent {ctx.AgentId} zugewiesen (User {job.UserId})");
|
||||
ctx.ApiToken = userApiKey.ApiKey;
|
||||
|
||||
// History aus DB laden
|
||||
@@ -140,11 +140,11 @@ public class CronjobService : BackgroundService
|
||||
return;
|
||||
}
|
||||
|
||||
// API-Key des Cronjob-Owners auflösen
|
||||
var notifyApiKey = await _db.GetUserSelectedApiKey(job.UserId);
|
||||
// API-Key des Cronjob-Owners für Notify-Agent auflösen
|
||||
var notifyApiKey = await _db.GetAgentApiKeyRecord(job.UserId, notifyCtx.AgentId);
|
||||
if (notifyApiKey == null)
|
||||
{
|
||||
_logger.LogWarning("Kein API-Key für User {UserId} (Cronjob '{Name}' Notification)", job.UserId, job.Name);
|
||||
_logger.LogWarning("Kein API-Key für Agent {AgentId} (Cronjob '{Name}' Notification)", notifyCtx.AgentId, job.Name);
|
||||
return;
|
||||
}
|
||||
notifyCtx.ApiToken = notifyApiKey.ApiKey;
|
||||
|
||||
Reference in new issue
Block a user