diff --git a/backend-pg/src/ee/services/license/license-service.ts b/backend-pg/src/ee/services/license/license-service.ts index 26ce0fe46..c8115832a 100644 --- a/backend-pg/src/ee/services/license/license-service.ts +++ b/backend-pg/src/ee/services/license/license-service.ts @@ -85,7 +85,11 @@ export const licenseServiceFactory = ({ logger.info(`Instance type: ${InstanceType.EnterpriseOnPrem}`); isValidLicense = true; } + return; } + // this means this is self hosted oss version + // else it would reach catch statement + isValidLicense = true; } catch (error) { logger.error(error); } diff --git a/backend-pg/src/ee/services/secret-snapshot/secret-snapshot-service.ts b/backend-pg/src/ee/services/secret-snapshot/secret-snapshot-service.ts index 4691c5e1c..f8ba4e187 100644 --- a/backend-pg/src/ee/services/secret-snapshot/secret-snapshot-service.ts +++ b/backend-pg/src/ee/services/secret-snapshot/secret-snapshot-service.ts @@ -19,6 +19,7 @@ import { import { TSnapshotDalFactory } from "./snapshot-dal"; import { TSnapshotFolderDalFactory } from "./snapshot-folder-dal"; import { TSnapshotSecretDalFactory } from "./snapshot-secret-dal"; +import { logger } from "@app/lib/logger"; type TSecretSnapshotServiceFactoryDep = { snapshotDal: TSnapshotDalFactory; @@ -112,44 +113,50 @@ export const secretSnapshotServiceFactory = ({ }; const performSnapshot = async (folderId: string) => { - if (!licenseService.isValidLicense) - throw new InternalServerError({ message: "Invalid license" }); + try { + if (!licenseService.isValidLicense) + throw new InternalServerError({ message: "Invalid license" }); - const snapshot = await snapshotDal.transaction(async (tx) => { - const folder = await folderDal.findById(folderId, tx); - if (!folder) throw new BadRequestError({ message: "Folder not found" }); + const snapshot = await snapshotDal.transaction(async (tx) => { + const folder = await folderDal.findById(folderId, tx); + if (!folder) throw new BadRequestError({ message: "Folder not found" }); - const secretVersions = await secretVersionDal.findLatestVersionByFolderId(folderId, tx); - const folderVersions = await folderVersionDal.findLatestVersionByFolderId(folderId, tx); - const newSnapshot = await snapshotDal.create( - { - folderId, - envId: folder.environment.envId, - parentFolderId: folder.parentId - }, - tx - ); - const snapshotSecrets = await snapshotSecretDal.insertMany( - secretVersions.map(({ id }) => ({ - secretVersionId: id, - envId: folder.environment.envId, - snapshotId: newSnapshot.id - })), - tx - ); - const snapshotFolders = await snapshotFolderDal.insertMany( - folderVersions.map(({ id }) => ({ - folderVersionId: id, - envId: folder.environment.envId, - snapshotId: newSnapshot.id - })), - tx - ); + const secretVersions = await secretVersionDal.findLatestVersionByFolderId(folderId, tx); + const folderVersions = await folderVersionDal.findLatestVersionByFolderId(folderId, tx); + const newSnapshot = await snapshotDal.create( + { + folderId, + envId: folder.environment.envId, + parentFolderId: folder.parentId + }, + tx + ); + const snapshotSecrets = await snapshotSecretDal.insertMany( + secretVersions.map(({ id }) => ({ + secretVersionId: id, + envId: folder.environment.envId, + snapshotId: newSnapshot.id + })), + tx + ); + const snapshotFolders = await snapshotFolderDal.insertMany( + folderVersions.map(({ id }) => ({ + folderVersionId: id, + envId: folder.environment.envId, + snapshotId: newSnapshot.id + })), + tx + ); - return { ...newSnapshot, secrets: snapshotSecrets, folder: snapshotFolders }; - }); + return { ...newSnapshot, secrets: snapshotSecrets, folder: snapshotFolders }; + }); - return snapshot; + return snapshot; + } catch (error) { + // this to avoid snapshot errors + logger.error("Failed to perform snasphot"); + logger.error(error); + } }; const rollbackSnapshot = async ({ id: snapshotId, actor, actorId }: TRollbackSnapshotDTO) => { diff --git a/backend-pg/src/server/routes/v1/project-router.ts b/backend-pg/src/server/routes/v1/project-router.ts index 6c226ba3b..5e8ee8b46 100644 --- a/backend-pg/src/server/routes/v1/project-router.ts +++ b/backend-pg/src/server/routes/v1/project-router.ts @@ -330,7 +330,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => { }, onRequest: verifyAuth([AuthMode.JWT]), handler: async (req) => { - const authorizations = await server.services.integration.listIntegrationByProject({ + const authorizations = await server.services.integrationAuth.listIntegrationAuthByProjectId({ actorId: req.permission.id, actor: req.permission.type, projectId: req.params.workspaceId diff --git a/backend-pg/src/server/routes/v1/sso-router.ts b/backend-pg/src/server/routes/v1/sso-router.ts index 68d3c056f..dd12ccd17 100644 --- a/backend-pg/src/server/routes/v1/sso-router.ts +++ b/backend-pg/src/server/routes/v1/sso-router.ts @@ -16,7 +16,6 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => { await server.register(fastifySession, { secret: appCfg.COOKIE_SECRET_SIGN_KEY }); await server.register(passport.initialize()); await server.register(passport.secureSession()); - // passport oauth strategy for Google const isGoogleOauthActive = Boolean( appCfg.CLIENT_ID_GOOGLE_LOGIN && appCfg.CLIENT_SECRET_GOOGLE_LOGIN @@ -123,7 +122,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => { } server.route({ - url: "/sso/redirect/google", + url: "/redirect/google", method: "GET", schema: { querystring: z.object({ @@ -144,7 +143,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => { }); server.route({ - url: "/sso/google", + url: "/google", method: "GET", preValidation: passport.authenticate("google", { session: false, @@ -169,7 +168,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => { }); server.route({ - url: "/sso/redirect/github", + url: "/redirect/github", method: "GET", schema: { querystring: z.object({ @@ -189,7 +188,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => { }); server.route({ - url: "/sso/github", + url: "/github", method: "GET", preValidation: passport.authenticate("github", { session: false, @@ -214,7 +213,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => { }); server.route({ - url: "/sso/redirect/gitlab", + url: "/redirect/gitlab", method: "GET", schema: { querystring: z.object({ @@ -234,7 +233,7 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => { }); server.route({ - url: "/sso/gitlab", + url: "/gitlab", method: "GET", preValidation: passport.authenticate("gitlab", { session: false, diff --git a/backend-pg/src/services/integration-auth/integration-list.ts b/backend-pg/src/services/integration-auth/integration-list.ts index 43cf02e1f..334a60e1d 100644 --- a/backend-pg/src/services/integration-auth/integration-list.ts +++ b/backend-pg/src/services/integration-auth/integration-list.ts @@ -102,7 +102,7 @@ export const getIntegrationOptions = async () => { isAvailable: true, type: "oauth", clientId: "", - clientSlug: appCfg.CLIENT_ID_VERCEL, + clientSlug: appCfg.CLIENT_SLUG_VERCEL, docsLink: "" }, { @@ -120,7 +120,7 @@ export const getIntegrationOptions = async () => { image: "GitHub.png", isAvailable: true, type: "oauth", - clientId: appCfg.CLIENT_ID_BITBUCKET, + clientId: appCfg.CLIENT_ID_GITHUB, docsLink: "" }, { diff --git a/backend-pg/src/services/integration/integration-dal.ts b/backend-pg/src/services/integration/integration-dal.ts index 80a9957e6..1977bad3e 100644 --- a/backend-pg/src/services/integration/integration-dal.ts +++ b/backend-pg/src/services/integration/integration-dal.ts @@ -50,7 +50,9 @@ export const integrationDalFactory = (db: TDbClient) => { const findById = async (id: string, tx?: Knex) => { try { - const doc = await integrationFindQuery(tx || db, { id }).first(); + const doc = await integrationFindQuery(tx || db, { + [`${TableName.Integration}.id` as "id"]: id + }).first(); if (!doc) return; const { envName: name, envSlug: slug, envId, ...el } = doc; diff --git a/backend-pg/src/services/secret/secret-queue.ts b/backend-pg/src/services/secret/secret-queue.ts index ed6096427..fdebd3708 100644 --- a/backend-pg/src/services/secret/secret-queue.ts +++ b/backend-pg/src/services/secret/secret-queue.ts @@ -159,7 +159,6 @@ export const secretQueueFactory = ({ }; queueService.start(QueueName.IntegrationSync, async (job) => { - logger.info("Secret integration sync started", job.data, job.id); const { environment, projectId, secretPath } = job.data; const folder = await folderDal.findBySecretPath(projectId, environment, secretPath); if (!folder) { @@ -173,6 +172,8 @@ export const secretQueueFactory = ({ isActive && isSamePath(secretPath, integrationSecPath) ); + if (!integrations.length) return; + logger.info("Secret integration sync started", job.data, job.id); for (const integration of toBeSyncedIntegrations) { const integrationAuth = { ...integration.integrationAuth, @@ -222,9 +223,7 @@ export const secretQueueFactory = ({ }); queueService.start(QueueName.SecretWebhook, async (job) => { - logger.info("Secret webhook job started", job.data, job.id); await fnTriggerWebhook({ ...job.data, projectEnvDal, webhookDal }); - logger.info("Secret webhook job ended", job.id); }); return { syncSecrets }; diff --git a/backend-pg/src/services/secret/secret-service.ts b/backend-pg/src/services/secret/secret-service.ts index 9287fe8c8..40fcce50c 100644 --- a/backend-pg/src/services/secret/secret-service.ts +++ b/backend-pg/src/services/secret/secret-service.ts @@ -569,7 +569,7 @@ export const secretServiceFactory = ({ secretDal, folderDal }); - for (let i = importedSecrets.length; i >= 0; i -= 1) { + for (let i = importedSecrets.length - 1; i >= 0; i -= 1) { for (let j = 0; j < importedSecrets[i].secrets.length; j += 1) { if (secretBlindIndex === importedSecrets[i].secrets[j].secretBlindIndex) { return importedSecrets[i].secrets[j]; diff --git a/backend-pg/src/services/webhook/webhook-fns.ts b/backend-pg/src/services/webhook/webhook-fns.ts index 0169b6a42..d661bf016 100644 --- a/backend-pg/src/services/webhook/webhook-fns.ts +++ b/backend-pg/src/services/webhook/webhook-fns.ts @@ -10,6 +10,7 @@ import { BadRequestError } from "@app/lib/errors"; import { TProjectEnvDalFactory } from "../project-env/project-env-dal"; import { TWebhookDalFactory } from "./webhook-dal"; +import { logger } from "@app/lib/logger"; const WEBHOOK_TRIGGER_TIMEOUT = 15 * 1000; export const triggerWebhookRequest = async ( @@ -93,6 +94,7 @@ export const fnTriggerWebhook = async ({ !isDisabled && picomatch.isMatch(secretPath, hookSecretPath, { strictSlashes: false }) ); if (!toBeTriggeredHooks.length) return; + logger.info("Secret webhook job started", { environment, secretPath, projectId }); const webhooksTriggered = await Promise.allSettled( toBeTriggeredHooks.map((hook) => triggerWebhookRequest( @@ -133,4 +135,5 @@ export const fnTriggerWebhook = async ({ ); } }); + logger.info("Secret webhook job ended", { environment, secretPath, projectId }); };