Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
import { subject } from "@casl/ability";
import { format } from "date-fns";
import { BanIcon, CheckIcon, ClipboardListIcon, PencilIcon, VaultIcon } from "lucide-react";
import { ProjectPermissionCan } from "@app/components/permissions";
import {
Badge,
ButtonGroup,
Card,
CardAction,
CardContent,
CardDescription,
CardHeader,
CardTitle,
Detail,
DetailGroup,
DetailLabel,
DetailValue,
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
IconButton,
OrgIcon,
ProjectIcon,
SubOrgIcon,
Tooltip,
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
import { ProjectPermissionIdentityActions, ProjectPermissionSub, useProject } from "@app/context";
import { getProjectLabel, hidesProjects } from "@app/helpers/project";
import { usePopUp, useTimedReset } from "@app/hooks";
import { identityAuthToNameMap, TProjectIdentity } from "@app/hooks/api";
import { IdentityProjectMembershipV1 } from "@app/hooks/api/identities/types";
import { ProjectType } from "@app/hooks/api/projects/types";
import { ProjectIdentityModal } from "@app/pages/project/AccessControlPage/components/IdentityTab/components/ProjectIdentityModal";
type Props = {
identity: TProjectIdentity;
isOrgIdentity?: boolean;
isSubOrgIdentity?: boolean;
membership: IdentityProjectMembershipV1;
};
export const ProjectIdentityDetailsSection = ({
identity,
isOrgIdentity,
isSubOrgIdentity,
membership
}: Props) => {
const { currentProject } = useProject();
const projectsHidden = hidesProjects(currentProject?.type);
const isPam = currentProject?.type === ProjectType.PAM;
const isAgentVault = currentProject?.type === ProjectType.AgentVault;
const isSecretScanning = currentProject?.type === ProjectType.SecretScanning;
let productLabel = "Project";
if (projectsHidden) {
productLabel = getProjectLabel(currentProject?.type);
} else if (isPam) {
productLabel = "PAM";
} else if (isAgentVault) {
productLabel = "Agent Vault";
}
let joinedLabel = "Joined project";
if (projectsHidden) {
joinedLabel = `Joined ${getProjectLabel(currentProject?.type).toLowerCase()}`;
} else if (isPam) {
joinedLabel = "Joined PAM";
} else if (isAgentVault) {
joinedLabel = "Joined Agent Vault";
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, isCopyingId, setCopyTextId] = useTimedReset<string>({
initialState: "Copy ID to clipboard"
});
const { popUp, handlePopUpToggle, handlePopUpOpen } = usePopUp(["editIdentity"] as const);
return (
<>
<Card className="w-full @4xl:max-w-[24rem] @4xl:shrink-0">
<CardHeader className="border-b">
<CardTitle>Details</CardTitle>
<CardDescription>Machine identity details</CardDescription>
{!isOrgIdentity && (
<CardAction>
<ProjectPermissionCan
I={ProjectPermissionIdentityActions.Edit}
a={subject(ProjectPermissionSub.Identity, {
identityId: identity.id
})}
>
{(isAllowed) => (
<IconButton
aria-label="Edit machine identity"
isDisabled={!isAllowed}
onClick={() => {
handlePopUpOpen("editIdentity");
}}
size="xs"
variant="outline"
>
<PencilIcon />
</IconButton>
)}
</ProjectPermissionCan>
</CardAction>
)}
</CardHeader>
<CardContent>
<DetailGroup>
<Detail>
<DetailLabel>Name</DetailLabel>
<DetailValue>{identity.name}</DetailValue>
</Detail>
<Detail>
<DetailLabel>ID</DetailLabel>
<DetailValue className="flex items-center gap-x-1">
{identity.id}
<Tooltip>
<TooltipTrigger asChild>
<IconButton
aria-label="Copy machine identity ID"
onClick={() => {
navigator.clipboard.writeText(identity.id);
setCopyTextId("Copied");
}}
variant={isCopyingId ? "ghost" : "ghost-muted"}
size="xs"
>
{isCopyingId ? <CheckIcon /> : <ClipboardListIcon />}
</IconButton>
</TooltipTrigger>
<TooltipContent>
{isCopyingId ? "Machine identity ID copied" : "Copy machine identity ID"}
</TooltipContent>
</Tooltip>
</DetailValue>
</Detail>
<Detail>
<DetailLabel>Managed by</DetailLabel>
<DetailValue>
{isOrgIdentity ? (
<Badge variant={isSubOrgIdentity ? "sub-org" : "org"}>
{isSubOrgIdentity ? <SubOrgIcon /> : <OrgIcon />}
{isSubOrgIdentity ? "Sub-" : ""}Organization
</Badge>
) : (
<Badge
// eslint-disable-next-line no-nested-ternary
variant={isAgentVault ? "av" : isSecretScanning ? "ss" : "project"}
>
{isAgentVault ? <VaultIcon /> : <ProjectIcon />}
{productLabel}
</Badge>
)}
</DetailValue>
</Detail>
<Detail>
<DetailLabel>Metadata</DetailLabel>
<DetailValue className="flex flex-wrap gap-2">
{identity?.metadata?.length ? (
identity.metadata?.map((el) => (
<ButtonGroup className="min-w-0" key={el.id}>
<Badge isTruncatable>
<span>{el.key}</span>
</Badge>
<Badge variant="outline" isTruncatable>
<span>{el.value}</span>
</Badge>
</ButtonGroup>
))
) : (
<span className="text-muted">—</span>
)}
</DetailValue>
</Detail>
<Detail>
<DetailLabel>{isOrgIdentity ? joinedLabel : "Created"}</DetailLabel>
<DetailValue>{format(membership.createdAt, "PPpp")}</DetailValue>
</Detail>
{!isOrgIdentity && (
<>
<Detail>
<DetailLabel>Last Login Method</DetailLabel>
<DetailValue>
{membership.lastLoginAuthMethod ? (
identityAuthToNameMap[membership.lastLoginAuthMethod]
) : (
<span className="text-muted">—</span>
)}
</DetailValue>
</Detail>
<Detail>
<DetailLabel>Last Logged In</DetailLabel>
<DetailValue>
{membership.lastLoginTime ? (
format(membership.lastLoginTime, "PPpp")
) : (
<span className="text-muted">—</span>
)}
</DetailValue>
</Detail>
<Detail>
<DetailLabel>Delete protection</DetailLabel>
<DetailValue>
{identity.hasDeleteProtection ? (
<Badge variant="success">
<CheckIcon />
Enabled
</Badge>
) : (
<Badge variant="neutral">
<BanIcon />
Disabled
</Badge>
)}
</DetailValue>
</Detail>
</>
)}
</DetailGroup>
</CardContent>
</Card>
<Dialog
open={popUp.editIdentity.isOpen}
onOpenChange={(open) => handlePopUpToggle("editIdentity", open)}
>
<DialogContent className="max-w-xl">
<DialogHeader>
<DialogTitle>
Edit {isAgentVault || projectsHidden ? "Machine" : "Project"} Identity
</DialogTitle>
<DialogDescription>
Update the identity's name, delete protection, and metadata.
</DialogDescription>
</DialogHeader>
<ProjectIdentityModal
identity={identity}
onClose={() => handlePopUpToggle("editIdentity", false)}
/>
</DialogContent>
</Dialog>
</>
);
};