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

* Enable SCIM logging that can be configured through constants

* Remove example

---------

Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com>
This commit is contained in:
Hariom Balhara
2024-12-06 15:48:16 +00:00
committed by GitHub
co-authored by Joe Au-Yeung
parent 063400fcbc
commit 6de26b3c43
4 changed files with 29 additions and 14 deletions
+3
View File
@@ -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=
+23 -13
View File
@@ -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);
}
+1
View File
@@ -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(",") || [];
+2 -1
View File
@@ -462,6 +462,7 @@
"NEXT_PUBLIC_POSTHOG_HOST",
"VAPID_PRIVATE_KEY",
"HUDDLE01_API_TOKEN",
"REPLEXICA_API_KEY"
"REPLEXICA_API_KEY",
"DIRECTORY_IDS_TO_LOG"
]
}