ui: settings

This commit is contained in:
Andras Bacsai
2022-07-26 12:26:45 +00:00
parent 641dc98e9c
commit e5b505b003
14 changed files with 556 additions and 507 deletions

View File

@@ -0,0 +1,16 @@
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_SshKey" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"privateKey" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"teamId" TEXT,
CONSTRAINT "SshKey_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_SshKey" ("createdAt", "id", "name", "privateKey", "updatedAt") SELECT "createdAt", "id", "name", "privateKey", "updatedAt" FROM "SshKey";
DROP TABLE "SshKey";
ALTER TABLE "new_SshKey" RENAME TO "SshKey";
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;

View File

@@ -66,6 +66,7 @@ model Team {
databaseId String?
service Service[] @relation(references: [id])
serviceId String?
SshKey SshKey[]
}
model TeamInvitation {
@@ -227,6 +228,8 @@ model SshKey {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
destinationDocker DestinationDocker[]
team Team? @relation(fields: [teamId], references: [id])
teamId String?
}
model GitSource {

View File

@@ -323,7 +323,7 @@ export async function isDomainConfigured({
id: string;
fqdn: string;
checkOwn?: boolean;
dockerId: string;
dockerId?: string;
}): Promise<boolean> {
console.log({ checkOwn, dockerId })

View File

@@ -7,8 +7,9 @@ import { CheckDNS, CheckDomain, DeleteDomain, DeleteSSHKey, SaveSettings, SaveSS
export async function listAllSettings(request: FastifyRequest) {
try {
const teamId = request.user.teamId;
const settings = await listSettings();
const sshKeys = await prisma.sshKey.findMany()
const sshKeys = await prisma.sshKey.findMany({ where: { team: { id: teamId } } })
const unencryptedKeys = []
if (sshKeys.length > 0) {
for (const key of sshKeys) {
@@ -96,6 +97,7 @@ export async function checkDNS(request: FastifyRequest<CheckDNS>) {
export async function saveSSHKey(request: FastifyRequest<SaveSSHKey>, reply: FastifyReply) {
try {
const teamId = request.user.teamId;
const { privateKey, name } = request.body;
const found = await prisma.sshKey.findMany({ where: { name } })
if (found.length > 0) {
@@ -104,7 +106,7 @@ export async function saveSSHKey(request: FastifyRequest<SaveSSHKey>, reply: Fas
}
}
const encryptedSSHKey = encrypt(privateKey)
await prisma.sshKey.create({ data: { name, privateKey: encryptedSSHKey } })
await prisma.sshKey.create({ data: { name, privateKey: encryptedSSHKey, team: { connect: { id: teamId } } } })
return reply.code(201).send()
} catch ({ status, message }) {
return errorHandler({ status, message })