From 8e42203b897af8b34782e0b7052337eeef5161c8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 29 Apr 2022 22:25:37 +0200 Subject: [PATCH] feat: Database and services logs --- src/lib/components/svg/databases/Redis.svelte | 2 - src/lib/components/svg/services/Fider.svelte | 121 ++++++++++++ src/lib/database/common.ts | 5 +- src/lib/database/services.ts | 108 +++++++---- src/lib/locales/en.json | 6 +- src/routes/applications/[id]/__layout.svelte | 4 +- .../configuration/_GithubRepositories.svelte | 4 +- src/routes/applications/[id]/index.svelte | 4 + .../applications/[id]/logs/index.svelte | 4 +- src/routes/databases/[id]/__layout.svelte | 73 ++++++- .../databases/[id]/logs/_Loading.svelte | 41 ++++ src/routes/databases/[id]/logs/index.json.ts | 66 +++++++ src/routes/databases/[id]/logs/index.svelte | 179 ++++++++++++++++++ src/routes/services/[id]/__layout.svelte | 32 ++++ src/routes/services/[id]/logs/_Loading.svelte | 41 ++++ src/routes/services/[id]/logs/index.json.ts | 66 +++++++ src/routes/services/[id]/logs/index.svelte | 179 ++++++++++++++++++ 17 files changed, 882 insertions(+), 53 deletions(-) create mode 100644 src/lib/components/svg/services/Fider.svelte create mode 100644 src/routes/databases/[id]/logs/_Loading.svelte create mode 100644 src/routes/databases/[id]/logs/index.json.ts create mode 100644 src/routes/databases/[id]/logs/index.svelte create mode 100644 src/routes/services/[id]/logs/_Loading.svelte create mode 100644 src/routes/services/[id]/logs/index.json.ts create mode 100644 src/routes/services/[id]/logs/index.svelte diff --git a/src/lib/components/svg/databases/Redis.svelte b/src/lib/components/svg/databases/Redis.svelte index 2571e601d..24a7dc797 100644 --- a/src/lib/components/svg/databases/Redis.svelte +++ b/src/lib/components/svg/databases/Redis.svelte @@ -4,9 +4,7 @@ + export let isAbsolute = false; + + + diff --git a/src/lib/database/common.ts b/src/lib/database/common.ts index 968208f55..314f77b08 100644 --- a/src/lib/database/common.ts +++ b/src/lib/database/common.ts @@ -11,11 +11,12 @@ import generator from 'generate-password'; import forge from 'node-forge'; import getPort, { portNumbers } from 'get-port'; -export function generatePassword(length = 24): string { +export function generatePassword(length = 24, symbols = false): string { return generator.generate({ length, numbers: true, - strict: true + strict: true, + symbols }); } diff --git a/src/lib/database/services.ts b/src/lib/database/services.ts index 9e3d1b467..df760cf76 100644 --- a/src/lib/database/services.ts +++ b/src/lib/database/services.ts @@ -15,7 +15,8 @@ const include: Prisma.ServiceInclude = { ghost: true, meiliSearch: true, umami: true, - hasura: true + hasura: true, + fider: true }; export async function listServicesWithIncludes() { return await prisma.service.findMany({ @@ -103,6 +104,12 @@ export async function getService({ id, teamId }: { id: string; teamId: string }) if (body.hasura?.graphQLAdminPassword) body.hasura.graphQLAdminPassword = decrypt(body.hasura.graphQLAdminPassword); + if (body.fider?.postgresqlPassword) + body.fider.postgresqlPassword = decrypt(body.fider.postgresqlPassword); + if (body.fider?.jwtSecret) body.fider.jwtSecret = decrypt(body.fider.jwtSecret); + if (body.fider?.emailSmtpPassword) + body.fider.emailSmtpPassword = decrypt(body.fider.emailSmtpPassword); + const settings = await prisma.setting.findFirst(); return { ...body, settings }; @@ -268,6 +275,25 @@ export async function configureServiceType({ } } }); + } else if (type === 'fider') { + const postgresqlUser = cuid(); + const postgresqlPassword = encrypt(generatePassword()); + const postgresqlDatabase = 'fider'; + const jwtSecret = encrypt(generatePassword(64, true)); + await prisma.service.update({ + where: { id }, + data: { + type, + fider: { + create: { + postgresqlDatabase, + postgresqlPassword, + postgresqlUser, + jwtSecret + } + } + } + }); } } @@ -326,52 +352,53 @@ export async function updateService({ return await prisma.service.update({ where: { id }, data: { fqdn, name } }); } -export async function updateLanguageToolService({ +export async function updateFiderService({ id, fqdn, - name + name, + emailNoreply, + emailMailgunApiKey, + emailMailgunDomain, + emailMailgunRegion, + emailSmtpHost, + emailSmtpPort, + emailSmtpUser, + emailSmtpPassword, + emailSmtpEnableStartTls }: { id: string; fqdn: string; name: string; + emailNoreply: string; + emailMailgunApiKey: string; + emailMailgunDomain: string; + emailMailgunRegion: string; + emailSmtpHost: string; + emailSmtpPort: number; + emailSmtpUser: string; + emailSmtpPassword: string; + emailSmtpEnableStartTls: boolean; }): Promise { - return await prisma.service.update({ where: { id }, data: { fqdn, name } }); -} - -export async function updateMeiliSearchService({ - id, - fqdn, - name -}: { - id: string; - fqdn: string; - name: string; -}): Promise { - return await prisma.service.update({ where: { id }, data: { fqdn, name } }); -} - -export async function updateVaultWardenService({ - id, - fqdn, - name -}: { - id: string; - fqdn: string; - name: string; -}): Promise { - return await prisma.service.update({ where: { id }, data: { fqdn, name } }); -} - -export async function updateVsCodeServer({ - id, - fqdn, - name -}: { - id: string; - fqdn: string; - name: string; -}): Promise { - return await prisma.service.update({ where: { id }, data: { fqdn, name } }); + return await prisma.service.update({ + where: { id }, + data: { + fqdn, + name, + fider: { + update: { + emailNoreply, + emailMailgunApiKey, + emailMailgunDomain, + emailMailgunRegion, + emailSmtpHost, + emailSmtpPort, + emailSmtpUser, + emailSmtpPassword, + emailSmtpEnableStartTls + } + } + } + }); } export async function updateWordpress({ @@ -423,6 +450,7 @@ export async function updateGhostService({ export async function removeService({ id }: { id: string }): Promise { await prisma.servicePersistentStorage.deleteMany({ where: { serviceId: id } }); await prisma.meiliSearch.deleteMany({ where: { serviceId: id } }); + await prisma.fider.deleteMany({ where: { serviceId: id } }); await prisma.ghost.deleteMany({ where: { serviceId: id } }); await prisma.umami.deleteMany({ where: { serviceId: id } }); await prisma.hasura.deleteMany({ where: { serviceId: id } }); diff --git a/src/lib/locales/en.json b/src/lib/locales/en.json index a5d6cbd50..22c7adf38 100644 --- a/src/lib/locales/en.json +++ b/src/lib/locales/en.json @@ -228,7 +228,8 @@ "permission_denied_start_database": "You do not have permission to start the database.", "delete_database": "Delete Database", "permission_denied_delete_database": "You do not have permission to delete a Database", - "no_databases_found": "No databases found" + "no_databases_found": "No databases found", + "logs": "Database Logs" }, "destination": { "delete_destination": "Delete Destination", @@ -293,7 +294,8 @@ "permission_denied_start_service": "You do not have permission to start the service.", "delete_service": "Delete Service", "permission_denied_delete_service": "You do not have permission to delete a service.", - "no_service": "No services found" + "no_service": "No services found", + "logs": "Service Logs" }, "setting": { "change_language": "Change Language", diff --git a/src/routes/applications/[id]/__layout.svelte b/src/routes/applications/[id]/__layout.svelte index bf634edde..cc8c19c19 100644 --- a/src/routes/applications/[id]/__layout.svelte +++ b/src/routes/applications/[id]/__layout.svelte @@ -394,7 +394,7 @@ >