mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 15:15:24 +00:00
feat: store rdp, vnc and telnet logins in a generic per-protocol table
This commit is contained in:
1 parent
e0c30a4e6f
commit
bba06f7ff6
107 files changed
+18750
-1224
No files matched your search
@@ -1,12 +1,18 @@
|
||||
import { and, eq, inArray, or } from "drizzle-orm";
|
||||
import { hostAccess, hosts, sharedHostSecrets } from "../db/schema.js";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import {
|
||||
hostAccess,
|
||||
hostProtocolAuth,
|
||||
hosts,
|
||||
sharedHostSecrets,
|
||||
} from "../db/schema.js";
|
||||
import type { DatabaseContext } from "./database-context.js";
|
||||
import { rowsAffected } from "./mutation-result.js";
|
||||
|
||||
export type SharedHostSecretRecord = typeof sharedHostSecrets.$inferSelect;
|
||||
export type NewSharedHostSecretRecord = typeof sharedHostSecrets.$inferInsert;
|
||||
|
||||
export type ShareProtocol = "ssh" | "rdp" | "vnc" | "telnet";
|
||||
/** "ssh", or a protocol id a plugin declares. */
|
||||
export type ShareProtocol = string;
|
||||
|
||||
export class SharedHostSecretsRepository {
|
||||
constructor(
|
||||
@@ -178,19 +184,20 @@ export class SharedHostSecretsRepository {
|
||||
const rows = await this.context.drizzle
|
||||
.select({ id: hosts.id })
|
||||
.from(hosts)
|
||||
.where(
|
||||
and(eq(hosts.userId, ownerId), eq(hosts.credentialId, credentialId)),
|
||||
);
|
||||
const protocolRows = await this.context.drizzle
|
||||
.select({ id: hostProtocolAuth.hostId })
|
||||
.from(hostProtocolAuth)
|
||||
.where(
|
||||
and(
|
||||
eq(hosts.userId, ownerId),
|
||||
or(
|
||||
eq(hosts.credentialId, credentialId),
|
||||
eq(hosts.rdpCredentialId, credentialId),
|
||||
eq(hosts.vncCredentialId, credentialId),
|
||||
eq(hosts.telnetCredentialId, credentialId),
|
||||
),
|
||||
eq(hostProtocolAuth.userId, ownerId),
|
||||
eq(hostProtocolAuth.credentialId, credentialId),
|
||||
),
|
||||
);
|
||||
|
||||
return rows.map((row) => row.id);
|
||||
return Array.from(new Set([...rows, ...protocolRows].map((row) => row.id)));
|
||||
}
|
||||
|
||||
private async afterWrite(): Promise<void> {
|
||||
|
||||
Reference in new issue
Block a user