mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-10-23 08:55:25 +00:00
refactor(wss): reuse findServiceAppName from container-ownership (#5741)
This commit is contained in:
@@ -15,8 +15,6 @@ vi.mock("@dokploy/server", () => ({
|
||||
getAccessibleServerIds: mockGetAccessibleServerIds,
|
||||
}));
|
||||
|
||||
vi.mock("@dokploy/server/db", () => ({ db: {} }));
|
||||
|
||||
import {
|
||||
canAccessDockerOverWss,
|
||||
canAccessTerminalOverWss,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { getAccessibleServerIds } from "@dokploy/server";
|
||||
import { db } from "@dokploy/server/db";
|
||||
import {
|
||||
checkServiceAccess,
|
||||
findMemberByUserId,
|
||||
@@ -60,50 +59,6 @@ export const canAccessDockerOverWss = async (
|
||||
return true;
|
||||
};
|
||||
|
||||
// Returns the appName of the service with this id, whichever service type it
|
||||
// is. Service-scoped sockets use it to check that the requested container
|
||||
// belongs to the service the caller was authorized for.
|
||||
export const findServiceAppName = async (
|
||||
serviceId: string,
|
||||
): Promise<string | null> => {
|
||||
const columns = { appName: true } as const;
|
||||
const results = await Promise.all([
|
||||
db.query.applications.findFirst({
|
||||
columns,
|
||||
where: (t, { eq }) => eq(t.applicationId, serviceId),
|
||||
}),
|
||||
db.query.compose.findFirst({
|
||||
columns,
|
||||
where: (t, { eq }) => eq(t.composeId, serviceId),
|
||||
}),
|
||||
db.query.postgres.findFirst({
|
||||
columns,
|
||||
where: (t, { eq }) => eq(t.postgresId, serviceId),
|
||||
}),
|
||||
db.query.mysql.findFirst({
|
||||
columns,
|
||||
where: (t, { eq }) => eq(t.mysqlId, serviceId),
|
||||
}),
|
||||
db.query.mariadb.findFirst({
|
||||
columns,
|
||||
where: (t, { eq }) => eq(t.mariadbId, serviceId),
|
||||
}),
|
||||
db.query.mongo.findFirst({
|
||||
columns,
|
||||
where: (t, { eq }) => eq(t.mongoId, serviceId),
|
||||
}),
|
||||
db.query.redis.findFirst({
|
||||
columns,
|
||||
where: (t, { eq }) => eq(t.redisId, serviceId),
|
||||
}),
|
||||
db.query.libsql.findFirst({
|
||||
columns,
|
||||
where: (t, { eq }) => eq(t.libsqlId, serviceId),
|
||||
}),
|
||||
]);
|
||||
return results.find(Boolean)?.appName ?? null;
|
||||
};
|
||||
|
||||
// Whether a stats request for `appName` targets the service named
|
||||
// `serviceAppName`. Applications and databases run as one swarm service named
|
||||
// after the app; stack tasks are namespaced "<stack>_<service>". Compose
|
||||
|
||||
@@ -33,7 +33,7 @@ const SERVICE_TABLES = [
|
||||
{ table: libsql, id: libsql.libsqlId },
|
||||
];
|
||||
|
||||
const findServiceAppName = async (serviceId: string) => {
|
||||
export const findServiceAppName = async (serviceId: string) => {
|
||||
for (const { table, id } of SERVICE_TABLES) {
|
||||
const [row] = await db
|
||||
.select({ appName: table.appName })
|
||||
|
||||
@@ -10,11 +10,8 @@ import {
|
||||
} from "@dokploy/server";
|
||||
import { quote } from "shell-quote";
|
||||
import { WebSocketServer } from "ws";
|
||||
import {
|
||||
canAccessDockerOverWss,
|
||||
findServiceAppName,
|
||||
isServiceContainerName,
|
||||
} from "./authorize";
|
||||
import { canAccessDockerOverWss, isServiceContainerName } from "./authorize";
|
||||
import { findServiceAppName } from "./container-ownership";
|
||||
|
||||
type AppType = "application" | "stack" | "docker-compose";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user