Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor(pam): remove resolveAccountType and resolvePamAccountType identity functions

bernie-gbbd835de8c8b
diff --git a/backend/src/db/migrations/20260603030053_pam-revamp.ts b/backend/src/db/migrations/20260603030053_pam-revamp.ts
index d85c175e25..6eb6a5fbd9 100644
--- a/backend/src/db/migrations/20260603030053_pam-revamp.ts
+++ b/backend/src/db/migrations/20260603030053_pam-revamp.ts
@@ -187,10 +187,6 @@ export async function up(knex: Knex): Promise<void> {
for (const t of templates) {
templateMap[t.type] = t.id;
}
- if (templateMap.windows && !templateMap["active-directory"]) {
- templateMap["active-directory"] = templateMap.windows;
- }
-
await knex(TableName.PamAccount).where("accountType", "active-directory").update({ accountType: "windows" });
const oldPamProjects = await knex(TableName.Project)
diff --git a/backend/src/ee/services/pam-account/pam-account-schemas.ts b/backend/src/ee/services/pam-account/pam-account-schemas.ts
index c70062835e..8a49e1da46 100644
--- a/backend/src/ee/services/pam-account/pam-account-schemas.ts
+++ b/backend/src/ee/services/pam-account/pam-account-schemas.ts
@@ -437,8 +437,7 @@ export const ACCOUNT_TYPE_CONFIGS = {
type TSupportedAccountType = keyof typeof ACCOUNT_TYPE_CONFIGS;
const getAccountTypeConfig = (accountType: PamAccountType | string) => {
- const resolved = resolveAccountType(accountType);
- const config = ACCOUNT_TYPE_CONFIGS[resolved as TSupportedAccountType];
+ const config = ACCOUNT_TYPE_CONFIGS[accountType as TSupportedAccountType];
if (!config) {
throw new Error(`Account type '${accountType}' is not supported in this phase`);
}
@@ -446,8 +445,7 @@ const getAccountTypeConfig = (accountType: PamAccountType | string) => {
};
export const validateConnectionDetails = (accountType: PamAccountType, data: unknown) => {
- const resolved = resolveAccountType(accountType);
- if (resolved === PamAccountType.Windows && data && typeof data === "object") {
+ if (accountType === PamAccountType.Windows && data && typeof data === "object") {
const raw = data as Record<string, unknown>;
if (!raw.host && raw.hostname) {
raw.host = raw.hostname;
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index d706317938..fb295115c7 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -21,7 +21,7 @@ import { KmsDataKey } from "@app/services/kms/kms-types";
import { TMembershipDALFactory } from "@app/services/membership/membership-dal";
import { TMembershipRoleDALFactory } from "@app/services/membership/membership-role-dal";
-import { PamAccountType, resolveAccountType } from "../pam/pam-enums";
+import { PamAccountType } from "../pam/pam-enums";
import {
checkAccountAccess,
checkFolderPermission,
@@ -237,8 +237,7 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
});
}
- const resolved = resolveAccountType(accountType);
- if (resolved === PamAccountType.Windows) {
+ if (accountType === PamAccountType.Windows) {
const settings = (template.settings ?? {}) as Record<string, unknown>;
if (
settings.recordingStorageBackend !== "aws-s3" ||
diff --git a/backend/src/ee/services/pam-session/pam-session-service.ts b/backend/src/ee/services/pam-session/pam-session-service.ts
index 0634c971ab..8f8e8f4523 100644
--- a/backend/src/ee/services/pam-session/pam-session-service.ts
+++ b/backend/src/ee/services/pam-session/pam-session-service.ts
@@ -20,7 +20,7 @@ import { TMfaSessionServiceFactory } from "@app/services/mfa-session/mfa-session
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { TUserDALFactory } from "@app/services/user/user-dal";
-import { PamAccessMethod, PamAccountType, PamSessionStatus, resolveAccountType } from "../pam/pam-enums";
+import { PamAccessMethod, PamAccountType, PamSessionStatus } from "../pam/pam-enums";
import { enforceMfa } from "../pam/pam-mfa";
import {
checkAccountAccess,
@@ -236,8 +236,7 @@ export const pamSessionServiceFactory = ({
};
}
- const resolved = resolveAccountType(account.accountType);
- const normalizedConnectionDetails = validateConnectionDetails(resolved, connectionDetails);
+ const normalizedConnectionDetails = validateConnectionDetails(account.accountType as PamAccountType, connectionDetails);
if (sessionStarted) {
await pamSessionDAL.activateSession(sessionId);
diff --git a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts b/backend/src/ee/services/pam-web-access/pam-web-access-service.ts
index 987f41b5d9..55cd1bf26c 100644
--- a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts
+++ b/backend/src/ee/services/pam-web-access/pam-web-access-service.ts
@@ -145,7 +145,7 @@ export const pamWebAccessServiceFactory = ({
throw new NotFoundError({ message: `Account with ID '${accountId}' not found` });
}
- if (!SESSION_HANDLERS[account.accountType]) {
+ if (!SESSION_HANDLERS[account.accountType as PamAccountType]) {
throw new BadRequestError({ message: "Web access is not supported for this account type" });
}
@@ -353,7 +353,11 @@ export const pamWebAccessServiceFactory = ({
throw new BadRequestError({ message: "Invalid account or project" });
}
+<<<<<<< HEAD
const handlerEntry = SESSION_HANDLERS[account.accountType];
+=======
+ const handlerEntry = SESSION_HANDLERS[account.accountType as PamAccountType];
+>>>>>>> 64c8bcdcd0 (refactor(pam): remove resolveAccountType and resolvePamAccountType identity functions)
if (!handlerEntry) {
throw new BadRequestError({ message: "Web access is not supported for this account type" });
}
diff --git a/backend/src/ee/services/pam/pam-enums.ts b/backend/src/ee/services/pam/pam-enums.ts
index 5a400407fd..8f840141e7 100644
--- a/backend/src/ee/services/pam/pam-enums.ts
+++ b/backend/src/ee/services/pam/pam-enums.ts
@@ -11,8 +11,6 @@ export enum PamAccountType {
Windows = "windows"
}
-export const resolveAccountType = (raw: string): PamAccountType => raw as PamAccountType;
-
export enum PamResourceRole {
Admin = "admin",
Connector = "connector",
diff --git a/frontend/src/hooks/api/pam/maps.ts b/frontend/src/hooks/api/pam/maps.ts
index efde0c4ea6..a517b60183 100644
--- a/frontend/src/hooks/api/pam/maps.ts
+++ b/frontend/src/hooks/api/pam/maps.ts
@@ -15,8 +15,6 @@ export const PAM_ACCOUNT_TYPE_MAP: Record<PamAccountType, { name: string; image:
const PAM_ACCOUNT_TYPE_FALLBACK = { name: "Unknown", image: "Windows.png" };
-export const resolvePamAccountType = (accountType: string): string => accountType;
-
export const getPamAccountTypeInfo = (accountType: string): { name: string; image: string } =>
(PAM_ACCOUNT_TYPE_MAP as Record<string, { name: string; image: string }>)[accountType] ??
PAM_ACCOUNT_TYPE_FALLBACK;
diff --git a/frontend/src/pages/pam/PamAccessPage/components/AccountPlatformIcon.tsx b/frontend/src/pages/pam/PamAccessPage/components/AccountPlatformIcon.tsx
index 440bc35aff..ee36ba8643 100644
--- a/frontend/src/pages/pam/PamAccessPage/components/AccountPlatformIcon.tsx
+++ b/frontend/src/pages/pam/PamAccessPage/components/AccountPlatformIcon.tsx
@@ -1,4 +1,4 @@
-import { PamAccountType, resolvePamAccountType, usePamAccountTypeMap } from "@app/hooks/api/pam";
+import { PamAccountType, usePamAccountTypeMap } from "@app/hooks/api/pam";
type Props = {
accountType: PamAccountType;
@@ -7,8 +7,7 @@ type Props = {
export const AccountPlatformIcon = ({ accountType, size = 28 }: Props) => {
const { map } = usePamAccountTypeMap();
- const resolved = resolvePamAccountType(accountType);
- const meta = map[resolved as PamAccountType];
+ const meta = map[accountType];
if (!meta) return null;
diff --git a/frontend/src/pages/pam/PamAccessPage/components/AccountRow.tsx b/frontend/src/pages/pam/PamAccessPage/components/AccountRow.tsx
index a0633bf302..645b2a6a75 100644
--- a/frontend/src/pages/pam/PamAccessPage/components/AccountRow.tsx
+++ b/frontend/src/pages/pam/PamAccessPage/components/AccountRow.tsx
@@ -10,7 +10,7 @@ import {
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
-import { PamAccountType, resolvePamAccountType, TAccessiblePamAccount, usePamAccountTypeMap } from "@app/hooks/api/pam";
+import { PamAccountType, TAccessiblePamAccount, usePamAccountTypeMap } from "@app/hooks/api/pam";
import { AccountPlatformIcon } from "./AccountPlatformIcon";
@@ -23,8 +23,7 @@ type Props = {
export const AccountRow = ({ account, search, onLaunch, indented }: Props) => {
const { map } = usePamAccountTypeMap();
- const resolved = resolvePamAccountType(account.accountType);
- const typeName = map[resolved as PamAccountType]?.name ?? account.accountType;
+ const typeName = map[account.accountType as PamAccountType]?.name ?? account.accountType;
const { canLaunch } = account;
return (
diff --git a/frontend/src/pages/pam/PamAccessPage/components/LaunchSessionSheet.tsx b/frontend/src/pages/pam/PamAccessPage/components/LaunchSessionSheet.tsx
index a7d55170a5..13c230fbd4 100644
--- a/frontend/src/pages/pam/PamAccessPage/components/LaunchSessionSheet.tsx
+++ b/frontend/src/pages/pam/PamAccessPage/components/LaunchSessionSheet.tsx
@@ -19,7 +19,6 @@ import {
import { useOrganization } from "@app/context";
import {
PamAccountType,
- resolvePamAccountType,
TAccessiblePamAccount,
TPamFieldDescriptor,
useGetPamAccountById,
@@ -152,8 +151,7 @@ export const LaunchSessionSheet = ({ account, isOpen, onOpenChange }: Props) =>
if (!account) return null;
- const resolved = resolvePamAccountType(account.accountType);
- const typeMeta = map[resolved as PamAccountType];
+ const typeMeta = map[account.accountType as PamAccountType];
const typeName = typeMeta?.name ?? account.accountType;
const supportsWebAccess = Boolean(typeMeta?.supportsWebAccess);
diff --git a/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx b/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
index 17e65bec15..cd6d87db1f 100644
--- a/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
+++ b/frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
@@ -3,7 +3,7 @@ import { Helmet } from "react-helmet";
import { useParams } from "@tanstack/react-router";
import { TriangleAlert } from "lucide-react";
-import { PamAccountType, resolvePamAccountType, TPamAccount, useGetPamAccountById } from "@app/hooks/api/pam";
+import { PamAccountType, TPamAccount, useGetPamAccountById } from "@app/hooks/api/pam";
import { PamDataExplorerPage } from "@app/pages/pam/PamDataExplorerPage/PamDataExplorerPage";
import { DisconnectedScreen } from "./DisconnectedScreen";
@@ -110,22 +110,20 @@ const PageContent = () => {
);
}
- const resolvedType = resolvePamAccountType(account.accountType);
-
- if (resolvedType === PamAccountType.SSH) {
- return <TerminalContent account={account} orgId={orgId!} />;
+ if (account.accountType === PamAccountType.SSH) {
+ return <TerminalContent account={account} />;
}
return (
<SessionAccessGate account={account}>
{({ reason, mfaSessionId }) => {
- if (resolvedType === PamAccountType.Postgres) {
+ if (account.accountType === PamAccountType.Postgres) {
return <PamDataExplorerPage reason={reason} mfaSessionId={mfaSessionId} />;
}
- if (resolvedType === PamAccountType.Windows) {
+ if (account.accountType === PamAccountType.Windows) {
return <RdpContent account={account} reason={reason} mfaSessionId={mfaSessionId} />;
}
- return <TerminalContent account={account} orgId={orgId!} reason={reason} mfaSessionId={mfaSessionId} />;
+ return <TerminalContent account={account} reason={reason} mfaSessionId={mfaSessionId} />;
}}
</SessionAccessGate>
);
diff --git a/frontend/src/pages/pam/PamSessionsPage/components/SessionDetailSheet.tsx b/frontend/src/pages/pam/PamSessionsPage/components/SessionDetailSheet.tsx
index e6e60431d0..be86662cbc 100644
--- a/frontend/src/pages/pam/PamSessionsPage/components/SessionDetailSheet.tsx
+++ b/frontend/src/pages/pam/PamSessionsPage/components/SessionDetailSheet.tsx
@@ -32,7 +32,6 @@ import {
PamResourcePermissionActions,
PamResourcePermissionSub,
PamSessionStatus,
- resolvePamAccountType,
useGetPamSessionById,
usePamAccountTypeMap
} from "@app/hooks/api/pam";
@@ -285,7 +284,7 @@ export const SessionDetailSheet = ({ sessionId, isOpen, onOpenChange, onTerminat
);
}
- const isRdpSession = resolvePamAccountType(session.accountType) === PamAccountType.Windows;
+ const isRdpSession = session.accountType === PamAccountType.Windows;
const tabs = isRdpSession
? [
diff --git a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
index 4d29663ba8..e76f996ce1 100644
--- a/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
+++ b/frontend/src/pages/pam/PamTemplatesPage/components/TemplateDetailSheet.tsx
@@ -34,7 +34,6 @@ import { useProject } from "@app/context";
import { AppConnection, useListAvailableAppConnections } from "@app/hooks/api/appConnections";
import {
PamAccountType,
- resolvePamAccountType,
useGetPamAccountTemplate,
usePamAccountTypeMap,
useUpdatePamAccountTemplate
@@ -91,7 +90,7 @@ const ConfigurationTab = ({
);
const isWindows =
- template?.type && resolvePamAccountType(template.type) === PamAccountType.Windows;
+ template?.type && template.type === PamAccountType.Windows;
const {
control,
@@ -124,7 +123,7 @@ const ConfigurationTab = ({
if (template) {
const settings = (template.settings ?? {}) as Record<string, unknown>;
const s3Config = (settings.recordingS3Config ?? {}) as Record<string, string>;
- const isWin = resolvePamAccountType(template.type) === PamAccountType.Windows;
+ const isWin = template.type === PamAccountType.Windows;
const savedBackend = settings.recordingStorageBackend as "postgres" | "aws-s3" | undefined;
reset({
name: template.name,