- {session.startedAt && session.endedAt ? (
+
+ {search.length ? (
+
+
No logs match search criteria
+
+ ) : (
Session logs are not yet available
@@ -78,8 +139,6 @@ export const PamSessionLogsSection = ({ session }: Props) => {
If logs do not appear after some time, please contact your Gateway administrators.
- ) : (
- "No session logs"
)}
)}
diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.utils.ts b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.utils.ts
new file mode 100644
index 000000000..d76145655
--- /dev/null
+++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.utils.ts
@@ -0,0 +1,46 @@
+// This function trims top and bottom empty padding, as well as moves all relative text to the left while still respecting indentation
+export const formatLogContent = (text: string | null | undefined): string => {
+ if (!text) return "";
+
+ let lines = text.split("\n");
+
+ // Find the first and last non-empty lines to trim vertical padding
+ let firstLineIndex = -1;
+ for (let i = 0; i < lines.length; i += 1) {
+ if (lines[i].trim() !== "") {
+ firstLineIndex = i;
+ break;
+ }
+ }
+
+ if (firstLineIndex === -1) {
+ return "";
+ }
+
+ let lastLineIndex = -1;
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
+ if (lines[i].trim() !== "") {
+ lastLineIndex = i;
+ break;
+ }
+ }
+
+ lines = lines.slice(firstLineIndex, lastLineIndex + 1);
+
+ // Determine the minimum indentation of non-empty lines
+ const indentations = lines
+ .filter((line) => line.trim() !== "")
+ .map((line) => {
+ const match = line.match(/^\s*/);
+ return match ? match[0].length : 0;
+ });
+
+ const minIndentation = indentations.length > 0 ? Math.min(...indentations) : 0;
+
+ // Remove the common indentation from all lines
+ if (minIndentation > 0) {
+ lines = lines.map((line) => line.substring(minIndentation));
+ }
+
+ return lines.join("\n");
+};
diff --git a/frontend/src/pages/pam/PamSessionsPage/components/PamSessionRow.tsx b/frontend/src/pages/pam/PamSessionsPage/components/PamSessionRow.tsx
index f730e331d..8721560c4 100644
--- a/frontend/src/pages/pam/PamSessionsPage/components/PamSessionRow.tsx
+++ b/frontend/src/pages/pam/PamSessionsPage/components/PamSessionRow.tsx
@@ -27,6 +27,7 @@ import { HighlightText } from "@app/components/v2/HighlightText";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
import { PAM_RESOURCE_TYPE_MAP, TPamSession } from "@app/hooks/api/pam";
+import { formatLogContent } from "../../PamSessionsByIDPage/components/PamSessionLogsSection.utils";
import { PamSessionStatusBadge } from "./PamSessionStatusBadge";
type Props = {
@@ -159,21 +160,28 @@ export const PamSessionRow = ({ session, search, filteredCommandLogs }: Props) =
{filteredCommandLogs.length > 0 && (
- {logsToShow.map((log) => (
-
-
-
- {new Date(log.timestamp).toLocaleString()}
-
+ {logsToShow.map((log) => {
+ const formattedInput = formatLogContent(log.input);
-
-
+ return (
+
+
+
+ {new Date(log.timestamp).toLocaleString()}
+
+
+
+
+
+
+
+
-
-
-
-
- ))}
+ );
+ })}
{filteredCommandLogs.length > LOGS_TO_SHOW && (
|