Skip to content

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

credentials using fields

Matheus Nogueirafc0e50310c3c
diff --git a/frontend/src/components/honey-tokens/ViewHoneyTokenCredentials/AwsHoneyTokenCredentials.tsx b/frontend/src/components/honey-tokens/ViewHoneyTokenCredentials/AwsHoneyTokenCredentials.tsx
index 09089307e5..78c0617852 100644
--- a/frontend/src/components/honey-tokens/ViewHoneyTokenCredentials/AwsHoneyTokenCredentials.tsx
+++ b/frontend/src/components/honey-tokens/ViewHoneyTokenCredentials/AwsHoneyTokenCredentials.tsx
@@ -1,4 +1,16 @@
-import { CredentialDisplay } from "@app/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/shared/CredentialDisplay";
+import { useReducer } from "react";
+import { Check, ClipboardCopy, EyeOff } from "lucide-react";
+
+import {
+ Field,
+ FieldContent,
+ FieldLabel,
+ IconButton,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
+} from "@app/components/v3";
+import { useTimedReset } from "@app/hooks";
import { TAwsHoneyToken } from "@app/hooks/api/honeyTokens/types";
type Props = {
@@ -11,18 +23,65 @@ const CREDENTIAL_FIELDS: { key: keyof TAwsHoneyToken["secretsMapping"]; label: s
{ key: "secretAccessKey", label: "Secret Access Key" }
];
+const CredentialField = ({ label, value }: { label: string; value?: string }) => {
+ const [showCredential, toggleShowCredential] = useReducer((prev) => !prev, false);
+ const [, isCopied, setCopied] = useTimedReset<string>({
+ initialState: ""
+ });
+
+ if (!value) return null;
+
+ return (
+ <Field>
+ <FieldLabel>{label}</FieldLabel>
+ <FieldContent>
+ <div className="flex w-full min-w-0 items-center gap-1">
+ <span className="min-w-0 flex-1 truncate font-mono text-sm" title={showCredential ? value : undefined}>
+ {showCredential ? value : "****************************"}
+ </span>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <IconButton
+ variant="ghost"
+ size="xs"
+ onClick={() => {
+ setCopied(value);
+ navigator.clipboard.writeText(value);
+ }}
+ aria-label={`Copy ${label}`}
+ >
+ {isCopied ? <Check className="size-3.5" /> : <ClipboardCopy className="size-3.5" />}
+ </IconButton>
+ </TooltipTrigger>
+ <TooltipContent>Copy {label}</TooltipContent>
+ </Tooltip>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <IconButton
+ variant="ghost"
+ size="xs"
+ onClick={toggleShowCredential}
+ aria-label={`${showCredential ? "Hide" : "Show"} ${label}`}
+ >
+ <EyeOff className="size-3.5" />
+ </IconButton>
+ </TooltipTrigger>
+ <TooltipContent>{showCredential ? "Hide" : "Show"} {label}</TooltipContent>
+ </Tooltip>
+ </div>
+ </FieldContent>
+ </Field>
+ );
+};
+
export const AwsHoneyTokenCredentials = ({ secretsMapping, credentials }: Props) => {
return (
- <div className="flex flex-col gap-x-8 gap-y-2 rounded-sm border border-mineshaft-600 bg-mineshaft-700 p-2">
+ <div className="flex flex-col gap-4">
{CREDENTIAL_FIELDS.map(({ key, label }) => {
const secretName = secretsMapping[key];
const value = secretName ? credentials[secretName] : undefined;
- return (
- <CredentialDisplay key={key} label={label} isSensitive>
- {value}
- </CredentialDisplay>
- );
+ return <CredentialField key={key} label={label} value={value} />;
})}
</div>
);
diff --git a/frontend/src/pages/secret-manager/HoneyTokenDetailsByIDPage/HoneyTokenDetailsByIDPage.tsx b/frontend/src/pages/secret-manager/HoneyTokenDetailsByIDPage/HoneyTokenDetailsByIDPage.tsx
index 41303ab475..cdf4ad039a 100644
--- a/frontend/src/pages/secret-manager/HoneyTokenDetailsByIDPage/HoneyTokenDetailsByIDPage.tsx
+++ b/frontend/src/pages/secret-manager/HoneyTokenDetailsByIDPage/HoneyTokenDetailsByIDPage.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useState } from "react";
+import { useEffect, useReducer, useState } from "react";
import { Helmet } from "react-helmet";
import { useNavigate, useParams } from "@tanstack/react-router";
import { format, formatDistanceToNow } from "date-fns";
@@ -6,8 +6,11 @@ import {
AlertTriangle,
BanIcon,
CalendarIcon,
+ Check,
ChevronLeftIcon,
+ ClipboardCopy,
ClockIcon,
+ EyeOff,
KeyIcon,
MapPinIcon,
RotateCcw,
@@ -17,7 +20,6 @@ import { twMerge } from "tailwind-merge";
import { createNotification } from "@app/components/notifications";
import { ProjectPermissionCan } from "@app/components/permissions";
-import { CredentialDisplay } from "@app/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/shared/CredentialDisplay";
import {
AlertDialog,
AlertDialogAction,
@@ -36,6 +38,7 @@ import {
Field,
FieldContent,
FieldLabel,
+ IconButton,
Input,
PageLoader,
Skeleton,
@@ -47,6 +50,7 @@ import { ROUTE_PATHS } from "@app/const/routes";
import { ProjectPermissionSub } from "@app/context";
import { ProjectPermissionSecretActions } from "@app/context/ProjectPermissionContext/types";
import { HONEY_TOKEN_CREDENTIAL_FIELDS, HONEY_TOKEN_MAP } from "@app/helpers/honeyTokens";
+import { useTimedReset } from "@app/hooks";
import { HoneyTokenStatus, HoneyTokenType } from "@app/hooks/api/honeyTokens/enums";
import { useResetHoneyToken, useRevokeHoneyToken } from "@app/hooks/api/honeyTokens/mutations";
import {
@@ -56,6 +60,64 @@ import {
import { HoneyTokenEventsSection } from "./components";
+const CredentialField = ({ label, value }: { label: string; value?: string }) => {
+ const [showCredential, toggleShowCredential] = useReducer((prev) => !prev, false);
+ const [, isCopied, setCopied] = useTimedReset<string>({ initialState: "" });
+
+ if (!value) return null;
+
+ return (
+ <Field>
+ <FieldLabel>{label}</FieldLabel>
+ <FieldContent>
+ <div className="flex w-full min-w-0 items-center gap-1">
+ <span
+ className="min-w-0 flex-1 truncate font-mono text-sm"
+ title={showCredential ? value : undefined}
+ >
+ {showCredential ? value : "****************************"}
+ </span>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <IconButton
+ variant="ghost"
+ size="xs"
+ onClick={() => {
+ setCopied(value);
+ navigator.clipboard.writeText(value);
+ }}
+ aria-label={`Copy ${label}`}
+ >
+ {isCopied ? (
+ <Check className="size-3.5" />
+ ) : (
+ <ClipboardCopy className="size-3.5" />
+ )}
+ </IconButton>
+ </TooltipTrigger>
+ <TooltipContent>Copy {label}</TooltipContent>
+ </Tooltip>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <IconButton
+ variant="ghost"
+ size="xs"
+ onClick={toggleShowCredential}
+ aria-label={`${showCredential ? "Hide" : "Show"} ${label}`}
+ >
+ <EyeOff className="size-3.5" />
+ </IconButton>
+ </TooltipTrigger>
+ <TooltipContent>
+ {showCredential ? "Hide" : "Show"} {label}
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </FieldContent>
+ </Field>
+ );
+};
+
const PageContent = () => {
const navigate = useNavigate();
const { honeyTokenId, projectId, orgId } = useParams({
@@ -268,18 +330,14 @@ const PageContent = () => {
</div>
)}
{!isCredentialsPending && credentials && (
- <div className="flex flex-col gap-x-8 gap-y-2 rounded-sm border border-mineshaft-600 bg-mineshaft-700 p-2">
+ <div className="flex flex-col gap-4">
{(
HONEY_TOKEN_CREDENTIAL_FIELDS[honeyToken.type as HoneyTokenType] ?? []
).map(({ key, label }) => {
const mapping = honeyToken.secretsMapping as Record<string, string>;
const secretName = mapping[key];
const value = secretName ? credentials[secretName] : undefined;
- return (
- <CredentialDisplay key={key} label={label} isSensitive>
- {value}
- </CredentialDisplay>
- );
+ return <CredentialField key={key} label={label} value={value} />;
})}
</div>
)}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/HoneyTokenTableRow/HoneyTokenTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/HoneyTokenTableRow/HoneyTokenTableRow.tsx
index 092b5d68d1..4e97c446c5 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/HoneyTokenTableRow/HoneyTokenTableRow.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/HoneyTokenTableRow/HoneyTokenTableRow.tsx
@@ -185,7 +185,7 @@ export const HoneyTokenTableRow = ({
);
};
- const renderHoneyTokenDetails = (honeyToken: TDashboardHoneyToken) => {
+ const renderHoneyTokenInlineDetails = (honeyToken: TDashboardHoneyToken) => {
const tokenInfo = HONEY_TOKEN_MAP[honeyToken.type as HoneyTokenType];
const mappedKeys = Object.values(honeyToken.secretsMapping || {});
@@ -201,11 +201,6 @@ export const HoneyTokenTableRow = ({
{tokenInfo.name} Honey Token
</Badge>
)}
- <Badge variant={STATUS_BADGE_VARIANT[honeyToken.status] ?? "neutral"} className="mx-1">
- {honeyToken.status === HoneyTokenStatus.Active && "Active"}
- {honeyToken.status === HoneyTokenStatus.Triggered && "Triggered"}
- {honeyToken.status === HoneyTokenStatus.Revoked && "Revoked"}
- </Badge>
{mappedKeys.length > 0 && (
<Tooltip>
<TooltipTrigger asChild>
@@ -218,6 +213,14 @@ export const HoneyTokenTableRow = ({
);
};
+ const renderStatusBadge = (honeyToken: TDashboardHoneyToken) => (
+ <Badge variant={STATUS_BADGE_VARIANT[honeyToken.status] ?? "neutral"}>
+ {honeyToken.status === HoneyTokenStatus.Active && "Active"}
+ {honeyToken.status === HoneyTokenStatus.Triggered && "Triggered"}
+ {honeyToken.status === HoneyTokenStatus.Revoked && "Revoked"}
+ </Badge>
+ );
+
return (
<>
<TableRow
@@ -255,13 +258,15 @@ export const HoneyTokenTableRow = ({
{isSingleEnvView && singleEnvToken ? (
<div className="relative flex w-full items-center">
<span className="truncate">{honeyTokenName}</span>
- {renderHoneyTokenDetails(singleEnvToken)}
+ {renderHoneyTokenInlineDetails(singleEnvToken)}
<div
className={twMerge(
"ml-auto flex items-center transition-[margin] duration-300",
- "group-hover:mr-20"
+ "group-hover:mr-32"
)}
- />
+ >
+ {renderStatusBadge(singleEnvToken)}
+ </div>
<div className="absolute top-1/2 -right-2.5 z-20 -translate-y-1/2">
{renderActionButtons(singleEnvToken)}
</div>
@@ -310,15 +315,17 @@ export const HoneyTokenTableRow = ({
return (
<TableRow key={slug} className="group relative hover:z-10">
<TableCell colSpan={2}>
- <div className="relative flex w-full flex-wrap items-center">
+ <div className="relative flex w-full items-center">
<span>{envName}</span>
- {renderHoneyTokenDetails(honeyToken)}
+ {renderHoneyTokenInlineDetails(honeyToken)}
<div
className={twMerge(
"ml-auto flex items-center transition-[margin] duration-300",
- "group-hover:mr-20"
+ "group-hover:mr-32"
)}
- />
+ >
+ {renderStatusBadge(honeyToken)}
+ </div>
<div className="absolute top-1/2 -right-1.5 z-20 -translate-y-1/2">
{renderActionButtons(honeyToken)}
</div>