diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 2e1eefff0..6c3bac117 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -28,9 +28,6 @@ const customConfig: Config = { length: 3 }; -export const defaultProxyImage = `coolify-haproxy-alpine:latest`; -export const defaultProxyImageTcp = `coolify-haproxy-tcp-alpine:latest`; -export const defaultProxyImageHttp = `coolify-haproxy-http-alpine:latest`; export const defaultTraefikImage = `traefik:v2.8`; export function getAPIUrl() { if (process.env.GITPOD_WORKSPACE_URL) { diff --git a/apps/api/src/lib/services/common.ts b/apps/api/src/lib/services/common.ts index 528e4ef12..0d7cec42e 100644 --- a/apps/api/src/lib/services/common.ts +++ b/apps/api/src/lib/services/common.ts @@ -1,5 +1,5 @@ -import { prisma } from '../common'; +import { decrypt, prisma } from '../common'; export async function removeService({ id }: { id: string }): Promise { await prisma.serviceSecret.deleteMany({ where: { serviceId: id } }); @@ -22,4 +22,18 @@ export async function removeService({ id }: { id: string }): Promise { await prisma.taiga.deleteMany({ where: { serviceId: id } }); await prisma.service.delete({ where: { id } }); +} +export async function verifyAndDecryptServiceSecrets(id: string) { + const secrets = await prisma.serviceSecret.findMany({ where: { serviceId: id } }) + let decryptedSecrets = secrets.map(secret => { + const { name, value } = secret + if (value) { + let rawValue = decrypt(value) + rawValue = rawValue.replaceAll(/\$/gi, '$$$') + return { name, value: rawValue } + } + return { name, value } + + }) + return decryptedSecrets } \ No newline at end of file diff --git a/apps/api/src/lib/services/handlers.ts b/apps/api/src/lib/services/handlers.ts index 270cce2cf..ec015ea4f 100644 --- a/apps/api/src/lib/services/handlers.ts +++ b/apps/api/src/lib/services/handlers.ts @@ -7,6 +7,7 @@ import { parseAndFindServiceTemplates } from '../../routes/api/v1/services/handl import { ServiceStartStop } from '../../routes/api/v1/services/types'; import { OnlyId } from '../../types'; +import { verifyAndDecryptServiceSecrets } from './common'; export async function stopService(request: FastifyRequest) { try { @@ -65,15 +66,17 @@ export async function startService(request: FastifyRequest, fa } } } - - const secrets = await prisma.serviceSecret.findMany({ where: { serviceId: id } }) + const secrets = await verifyAndDecryptServiceSecrets(id) for (const secret of secrets) { const { name, value } = secret if (value) { const foundEnv = !!template.services[s].environment?.find(env => env.startsWith(`${name}=`)) const foundNewEnv = !!newEnvironments?.find(env => env.startsWith(`${name}=`)) if (foundEnv && !foundNewEnv) { - newEnvironments.push(`${name}=${decrypt(value)}`) + newEnvironments.push(`${name}=${value}`) + } + if (!foundEnv && !foundNewEnv && s === id) { + newEnvironments.push(`${name}=${value}`) } } }