feat: release 2.5.1

This commit is contained in:
2026-09-27 10:40:50 +00:00 Unverified
parent 46d97138dc
commit 5f7509a9c5
53 changed files with 2871 additions and 370 deletions
+19 -7
View File
@@ -166,6 +166,20 @@ export class MemoryAuthStore implements AuthStore {
readonly users = new Map<string, KuberUser>();
readonly sessions = new Map<string, SessionRecord>();
readonly apiKeys = new Map<string, ApiKeyRecord>();
readonly apiKeysByTokenHash = new Map<string, ApiKeyRecord>();
private storeApiKey(key: ApiKeyRecord): void {
this.apiKeys.set(key.id, key);
this.apiKeysByTokenHash.set(key.tokenHash, key);
}
private deleteApiKey(id: string): void {
const key = this.apiKeys.get(id);
if (!key) return;
this.apiKeys.delete(id);
if (this.apiKeysByTokenHash.get(key.tokenHash) === key)
this.apiKeysByTokenHash.delete(key.tokenHash);
}
async getUser(username: string): Promise<KuberUser | undefined> {
return this.users.get(username);
@@ -208,7 +222,7 @@ export class MemoryAuthStore implements AuthStore {
async deleteUser(username: string): Promise<boolean> {
await this.revokeUserSessions(username);
for (const [id, key] of this.apiKeys)
if (key.username === username) this.apiKeys.delete(id);
if (key.username === username) this.deleteApiKey(id);
return this.users.delete(username);
}
@@ -264,9 +278,7 @@ export class MemoryAuthStore implements AuthStore {
}
async getApiKey(tokenHash: string): Promise<ApiKeyRecord | undefined> {
const key = [...this.apiKeys.values()].find(
(item) => item.tokenHash === tokenHash,
);
const key = this.apiKeysByTokenHash.get(tokenHash);
if (!key || key.disabled || Date.parse(key.expiresAt) <= Date.now()) return;
const user = this.users.get(key.username);
if (!user || user.disabled) return;
@@ -279,7 +291,7 @@ export class MemoryAuthStore implements AuthStore {
if (!user || user.disabled) throw new Error("API key user is not active");
if (this.apiKeys.has(normalized.id))
throw new Error("API key already exists");
this.apiKeys.set(normalized.id, normalized);
this.storeApiKey(normalized);
}
async listApiKeys(username: string): Promise<ApiKeyRecord[]> {
@@ -291,7 +303,7 @@ export class MemoryAuthStore implements AuthStore {
async revokeApiKey(username: string, id: string): Promise<boolean> {
const key = this.apiKeys.get(id);
if (!key || key.username !== username) return false;
this.apiKeys.delete(id);
this.deleteApiKey(id);
return true;
}
@@ -299,7 +311,7 @@ export class MemoryAuthStore implements AuthStore {
const expired = [...this.apiKeys.values()].filter(
(key) => Date.parse(key.expiresAt) <= now,
);
for (const key of expired) this.apiKeys.delete(key.id);
for (const key of expired) this.deleteApiKey(key.id);
return expired.length;
}
}