mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: stash
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
findSSHKeyById,
|
||||
removeSSHKeyById,
|
||||
updateSSHKeyById,
|
||||
execAsync,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const sshRouter = createTRPCRouter({
|
||||
|
||||
@@ -3,28 +3,30 @@ import { z } from "zod";
|
||||
export const sshKeyCreate = z.object({
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
publicKey: z.string().refine(
|
||||
(key) => {
|
||||
const rsaPubPattern = /^ssh-rsa\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
const ed25519PubPattern = /^ssh-ed25519\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
return rsaPubPattern.test(key) || ed25519PubPattern.test(key);
|
||||
},
|
||||
{
|
||||
message: "Invalid public key format",
|
||||
},
|
||||
),
|
||||
privateKey: z.string().refine(
|
||||
(key) => {
|
||||
const rsaPrivPattern =
|
||||
/^-----BEGIN RSA PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END RSA PRIVATE KEY-----\s*$/;
|
||||
const ed25519PrivPattern =
|
||||
/^-----BEGIN OPENSSH PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END OPENSSH PRIVATE KEY-----\s*$/;
|
||||
return rsaPrivPattern.test(key) || ed25519PrivPattern.test(key);
|
||||
},
|
||||
{
|
||||
message: "Invalid private key format",
|
||||
},
|
||||
),
|
||||
publicKey: z.string(),
|
||||
// .refine(
|
||||
// (key) => {
|
||||
// // const rsaPubPattern = /^ssh-rsa\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
// // const ed25519PubPattern = /^ssh-ed25519\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
// // return rsaPubPattern.test(key) || ed25519PubPattern.test(key);
|
||||
// },
|
||||
// {
|
||||
// message: "Invalid public key format",
|
||||
// },
|
||||
// )
|
||||
privateKey: z.string(),
|
||||
// .refine(
|
||||
// (key) => {
|
||||
// // const rsaPrivPattern =
|
||||
// // /^-----BEGIN RSA PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END RSA PRIVATE KEY-----\s*$/;
|
||||
// // const ed25519PrivPattern =
|
||||
// // /^-----BEGIN OPENSSH PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END OPENSSH PRIVATE KEY-----\s*$/;
|
||||
// // return rsaPrivPattern.test(key) || ed25519PrivPattern.test(key);
|
||||
// },
|
||||
// {
|
||||
// message: "Invalid private key format",
|
||||
// },
|
||||
// ),
|
||||
});
|
||||
|
||||
export const sshKeyUpdate = sshKeyCreate.pick({
|
||||
|
||||
@@ -2,11 +2,7 @@ import type http from "node:http";
|
||||
import { spawn } from "node-pty";
|
||||
import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import {
|
||||
findServerById,
|
||||
readSSHKey,
|
||||
validateWebSocketRequest,
|
||||
} from "@dokploy/builders";
|
||||
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
export const setupDockerContainerLogsWebSocketServer = (
|
||||
@@ -52,7 +48,6 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
const server = await findServerById(serverId);
|
||||
|
||||
if (!server.sshKeyId) return;
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const client = new Client();
|
||||
new Promise<void>((resolve, reject) => {
|
||||
client
|
||||
@@ -84,7 +79,7 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: keys.privateKey,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,11 +2,7 @@ import type http from "node:http";
|
||||
import { spawn } from "node-pty";
|
||||
import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import {
|
||||
findServerById,
|
||||
readSSHKey,
|
||||
validateWebSocketRequest,
|
||||
} from "@dokploy/builders";
|
||||
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
export const setupDockerContainerTerminalWebSocketServer = (
|
||||
@@ -53,7 +49,6 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
||||
if (!server.sshKeyId)
|
||||
throw new Error("No SSH key available for this server");
|
||||
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const conn = new Client();
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
@@ -109,7 +104,7 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: keys.privateKey,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -2,11 +2,7 @@ import { spawn } from "node:child_process";
|
||||
import type http from "node:http";
|
||||
import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import {
|
||||
findServerById,
|
||||
readSSHKey,
|
||||
validateWebSocketRequest,
|
||||
} from "@dokploy/builders";
|
||||
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
|
||||
|
||||
export const setupDeploymentLogsWebSocketServer = (
|
||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||
@@ -51,7 +47,6 @@ export const setupDeploymentLogsWebSocketServer = (
|
||||
const server = await findServerById(serverId);
|
||||
|
||||
if (!server.sshKeyId) return;
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const client = new Client();
|
||||
new Promise<void>((resolve, reject) => {
|
||||
client
|
||||
@@ -83,7 +78,7 @@ export const setupDeploymentLogsWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: keys.privateKey,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user