Skip to content

Scheduling infrastructure for absolutely everyone.

feat: Enable SCIM logging that can be configured through constant (#18043)

Hariom Balhara6de26b3c431d
diff --git a/.env.example b/.env.example
index 1a9addf5408..8c8990c58a9 100644
--- a/.env.example
+++ b/.env.example
@@ -414,3 +414,6 @@ NEXT_PUBLIC_LOGGER_LEVEL=
# Used to use Replexica SDK, a tool for real-time AI-powered localization
REPLEXICA_API_KEY=
+
+# Comma-separated list of DSyncData.directoryId to log SCIM API requests for. It can be enabled temporarily for debugging the requests being sent to SCIM server.
+DIRECTORY_IDS_TO_LOG=
diff --git a/apps/web/pages/api/scim/v2.0/[...directory].ts b/apps/web/pages/api/scim/v2.0/[...directory].ts
index 25098f42371..52d6dc3d6fd 100644
--- a/apps/web/pages/api/scim/v2.0/[...directory].ts
+++ b/apps/web/pages/api/scim/v2.0/[...directory].ts
@@ -4,6 +4,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
import handleGroupEvents from "@calcom/features/ee/dsync/lib/handleGroupEvents";
import handleUserEvents from "@calcom/features/ee/dsync/lib/handleUserEvents";
import jackson from "@calcom/features/ee/sso/lib/jackson";
+import { DIRECTORY_IDS_TO_LOG } from "@calcom/lib/constants";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import prisma from "@calcom/prisma";
@@ -13,18 +14,22 @@ const log = logger.getSubLogger({ prefix: ["[scim]"] });
// This is the handler for the SCIM API requests
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { dsyncController } = await jackson();
- log.debug("Request from SCIM", {
- method: req.method,
- url: req.url,
- headers: req.headers,
- query: req.query,
- body: req.body,
- cookies: req.cookies,
- });
+
const { method, query, body } = req;
const [directoryId, path, resourceId] = query.directory as string[];
-
+ const shouldLog = DIRECTORY_IDS_TO_LOG.includes(directoryId);
+ if (shouldLog) {
+ console.log(
+ "SCIM API request",
+ safeStringify({
+ method: req.method,
+ url: req.url,
+ query: req.query,
+ body: req.body,
+ })
+ );
+ }
let responseBody: object | undefined = undefined;
if (body) {
try {
@@ -51,10 +56,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { status, data } = await dsyncController.requests.handle(request, handleEvents);
- log.debug("Response to SCIM", {
- status,
- data,
- });
+ if (shouldLog) {
+ console.log(
+ "Response to SCIM",
+ safeStringify({
+ status,
+ data,
+ })
+ );
+ }
res.status(status).json(data);
}
diff --git a/packages/lib/constants.ts b/packages/lib/constants.ts
index 42fa9085f20..95a6db6ff4d 100644
--- a/packages/lib/constants.ts
+++ b/packages/lib/constants.ts
@@ -197,3 +197,4 @@ export const GOOGLE_CALENDAR_SCOPES = [
"https://www.googleapis.com/auth/calendar.events",
"https://www.googleapis.com/auth/calendar.readonly",
];
+export const DIRECTORY_IDS_TO_LOG = process.env.DIRECTORY_IDS_TO_LOG?.split(",") || [];
diff --git a/turbo.json b/turbo.json
index 7f90661544e..86d271ced36 100644
--- a/turbo.json
+++ b/turbo.json
@@ -462,6 +462,7 @@
"NEXT_PUBLIC_POSTHOG_HOST",
"VAPID_PRIVATE_KEY",
"HUDDLE01_API_TOKEN",
- "REPLEXICA_API_KEY"
+ "REPLEXICA_API_KEY",
+ "DIRECTORY_IDS_TO_LOG"
]
}