-Add New Interface for Credential DB
-Add Credential Name as a comment into the server authorized_key file
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import type { AuthenticatedRequest } from "../../../types/index.js";
|
import type {
|
||||||
|
AuthenticatedRequest,
|
||||||
|
CredentialBackend,
|
||||||
|
} from "../../../types/index.js";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import { db } from "../db/index.js";
|
import { db } from "../db/index.js";
|
||||||
import { sshCredentials, sshCredentialUsage, sshData } from "../db/schema.js";
|
import { sshCredentials, sshCredentialUsage, sshData } from "../db/schema.js";
|
||||||
@@ -1124,10 +1127,9 @@ router.post(
|
|||||||
|
|
||||||
async function deploySSHKeyToHost(
|
async function deploySSHKeyToHost(
|
||||||
hostConfig: Record<string, unknown>,
|
hostConfig: Record<string, unknown>,
|
||||||
publicKey: string,
|
credData: CredentialBackend,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
_credentialData: Record<string, unknown>,
|
|
||||||
): Promise<{ success: boolean; message?: string; error?: string }> {
|
): Promise<{ success: boolean; message?: string; error?: string }> {
|
||||||
|
const publicKey = credData.public_key as string;
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const conn = new Client();
|
const conn = new Client();
|
||||||
|
|
||||||
@@ -1248,7 +1250,7 @@ async function deploySSHKeyToHost(
|
|||||||
.replace(/'/g, "'\\''");
|
.replace(/'/g, "'\\''");
|
||||||
|
|
||||||
conn.exec(
|
conn.exec(
|
||||||
`printf '%s\\n' '${escapedKey}' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys`,
|
`printf '%s\\n' '${escapedKey} ${credData.name}@Termix' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys`,
|
||||||
(err, stream) => {
|
(err, stream) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
clearTimeout(addTimeout);
|
clearTimeout(addTimeout);
|
||||||
@@ -1510,7 +1512,7 @@ router.post(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const credData = credential[0];
|
const credData = credential[0] as unknown as CredentialBackend;
|
||||||
|
|
||||||
if (credData.authType !== "key") {
|
if (credData.authType !== "key") {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
@@ -1519,7 +1521,7 @@ router.post(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const publicKey = credData.public_key || credData.publicKey;
|
const publicKey = credData.public_key;
|
||||||
if (!publicKey) {
|
if (!publicKey) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
@@ -1601,7 +1603,6 @@ router.post(
|
|||||||
|
|
||||||
const deployResult = await deploySSHKeyToHost(
|
const deployResult = await deploySSHKeyToHost(
|
||||||
hostConfig,
|
hostConfig,
|
||||||
publicKey as string,
|
|
||||||
credData,
|
credData,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,28 @@ export interface Credential {
|
|||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CredentialBackend {
|
||||||
|
id: number;
|
||||||
|
userId: string;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
folder: string | null;
|
||||||
|
tags: string;
|
||||||
|
authType: "password" | "key";
|
||||||
|
username: string;
|
||||||
|
password: string | null;
|
||||||
|
key: string;
|
||||||
|
private_key?: string;
|
||||||
|
public_key?: string;
|
||||||
|
key_password: string | null;
|
||||||
|
keyType?: string;
|
||||||
|
detectedKeyType: string;
|
||||||
|
usageCount: number;
|
||||||
|
lastUsed: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface CredentialData {
|
export interface CredentialData {
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user