Skip to content

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

modify tokens

Matheus Nogueira44d2747d58ae
diff --git a/backend/src/db/migrations/20260428120000_honey-token-description.ts b/backend/src/db/migrations/20260428120000_honey-token-description.ts
new file mode 100644
index 0000000000..a1b9252e2a
--- /dev/null
+++ b/backend/src/db/migrations/20260428120000_honey-token-description.ts
@@ -0,0 +1,25 @@
+import { Knex } from "knex";
+
+import { TableName } from "@app/db/schemas";
+
+export async function up(knex: Knex): Promise<void> {
+ if (await knex.schema.hasTable(TableName.HoneyToken)) {
+ const hasDescription = await knex.schema.hasColumn(TableName.HoneyToken, "description");
+ if (!hasDescription) {
+ await knex.schema.alterTable(TableName.HoneyToken, (t) => {
+ t.string("description", 256).nullable();
+ });
+ }
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ if (await knex.schema.hasTable(TableName.HoneyToken)) {
+ const hasDescription = await knex.schema.hasColumn(TableName.HoneyToken, "description");
+ if (hasDescription) {
+ await knex.schema.alterTable(TableName.HoneyToken, (t) => {
+ t.dropColumn("description");
+ });
+ }
+ }
+}
diff --git a/backend/src/db/schemas/honey-tokens.ts b/backend/src/db/schemas/honey-tokens.ts
index e95879fff2..f5c32b08b9 100644
--- a/backend/src/db/schemas/honey-tokens.ts
+++ b/backend/src/db/schemas/honey-tokens.ts
@@ -12,6 +12,7 @@ import { TImmutableDBKeys } from "./models";
export const HoneyTokensSchema = z.object({
id: z.string().uuid(),
name: z.string(),
+ description: z.string().nullable().optional(),
type: z.string(),
status: z.string().default("active"),
projectId: z.string(),
diff --git a/backend/src/ee/routes/v1/honey-token-router.ts b/backend/src/ee/routes/v1/honey-token-router.ts
index f440306ae8..aa227b0e07 100644
--- a/backend/src/ee/routes/v1/honey-token-router.ts
+++ b/backend/src/ee/routes/v1/honey-token-router.ts
@@ -40,6 +40,7 @@ export const registerHoneyTokenRouter = async (server: FastifyZodProvider) => {
honeyToken: z.object({
id: z.string().uuid(),
name: z.string(),
+ description: z.string().nullable().optional(),
type: z.string(),
status: z.string(),
projectId: z.string(),
@@ -56,6 +57,55 @@ export const registerHoneyTokenRouter = async (server: FastifyZodProvider) => {
}
});
+ server.route({
+ url: "/:honeyTokenId",
+ method: "PATCH",
+ config: {
+ rateLimit: writeLimit
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ schema: {
+ params: z.object({
+ honeyTokenId: z.string().uuid()
+ }),
+ body: z.object({
+ projectId: z.string().trim(),
+ name: slugSchema({ field: "Name" }).optional(),
+ description: z.string().trim().max(256).nullish(),
+ secretsMapping: z.record(z.string(), z.string().min(1)).optional()
+ }),
+ response: {
+ 200: z.object({
+ honeyToken: z.object({
+ id: z.string().uuid(),
+ name: z.string(),
+ description: z.string().nullable().optional(),
+ type: z.string(),
+ status: z.string(),
+ projectId: z.string(),
+ secretsMapping: z.unknown(),
+ createdAt: z.date(),
+ updatedAt: z.date()
+ })
+ })
+ }
+ },
+ handler: async (req) => {
+ const { projectId, name, description, secretsMapping } = req.body;
+ const { honeyToken } = await server.services.honeyTokenCrud.updateHoneyToken(
+ {
+ honeyTokenId: req.params.honeyTokenId,
+ projectId,
+ name,
+ description,
+ secretsMapping
+ },
+ req.permission
+ );
+ return { honeyToken };
+ }
+ });
+
server.route({
url: "/:honeyTokenId",
method: "DELETE",
diff --git a/backend/src/ee/services/honey-token/honey-token-dal.ts b/backend/src/ee/services/honey-token/honey-token-dal.ts
index 835a579ab9..5b3f1d1ea9 100644
--- a/backend/src/ee/services/honey-token/honey-token-dal.ts
+++ b/backend/src/ee/services/honey-token/honey-token-dal.ts
@@ -17,6 +17,7 @@ export const honeyTokenDALFactory = (db: TDbClient) => {
.select(
db.ref("id").withSchema(TableName.HoneyToken),
db.ref("name").withSchema(TableName.HoneyToken),
+ db.ref("description").withSchema(TableName.HoneyToken),
db.ref("type").withSchema(TableName.HoneyToken),
db.ref("status").withSchema(TableName.HoneyToken),
db.ref("projectId").withSchema(TableName.HoneyToken),
@@ -34,6 +35,7 @@ export const honeyTokenDALFactory = (db: TDbClient) => {
return rows.map((row) => ({
id: row.id,
name: row.name,
+ description: row.description,
type: row.type,
status: row.status,
projectId: row.projectId,
diff --git a/backend/src/ee/services/honey-token/honey-token-service.ts b/backend/src/ee/services/honey-token/honey-token-service.ts
index 19256dc65b..cd81aacc7e 100644
--- a/backend/src/ee/services/honey-token/honey-token-service.ts
+++ b/backend/src/ee/services/honey-token/honey-token-service.ts
@@ -78,6 +78,7 @@ export const honeyTokenServiceFactory = ({
projectId,
type,
name,
+ description,
secretsMapping,
environment,
secretPath
@@ -85,6 +86,7 @@ export const honeyTokenServiceFactory = ({
projectId: string;
type: HoneyTokenType;
name: string;
+ description?: string | null;
secretsMapping: Record<string, string>;
environment: string;
secretPath: string;
@@ -199,6 +201,7 @@ export const honeyTokenServiceFactory = ({
const honeyToken = await honeyTokenDAL.create({
name,
+ description,
type,
status: HoneyTokenStatus.Active,
projectId,
@@ -255,6 +258,7 @@ export const honeyTokenServiceFactory = ({
honeyToken: {
id: honeyToken.id,
name: honeyToken.name,
+ description: honeyToken.description,
type: honeyToken.type,
status: honeyToken.status,
projectId: honeyToken.projectId,
@@ -265,6 +269,167 @@ export const honeyTokenServiceFactory = ({
};
};
+ const updateHoneyToken = async (
+ {
+ honeyTokenId,
+ projectId,
+ name,
+ description,
+ secretsMapping
+ }: {
+ honeyTokenId: string;
+ projectId: string;
+ name?: string;
+ description?: string | null;
+ secretsMapping?: Record<string, string>;
+ },
+ actor: OrgServiceActor
+ ) => {
+ const plan = await licenseService.getPlan(actor.orgId);
+
+ if (!plan.honeyTokens) {
+ throw new BadRequestError({
+ message: "Failed to update honey token due to plan restriction. Upgrade plan to use honey tokens."
+ });
+ }
+
+ const { permission } = await permissionService.getProjectPermission({
+ actor: actor.type,
+ actorId: actor.id,
+ actorAuthMethod: actor.authMethod,
+ actorOrgId: actor.orgId,
+ actionProjectType: ActionProjectType.SecretManager,
+ projectId
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretActions.Edit, ProjectPermissionSub.Secrets);
+
+ const honeyToken = await honeyTokenDAL.findById(honeyTokenId);
+
+ if (!honeyToken || honeyToken.projectId !== projectId) {
+ throw new NotFoundError({ message: `Honey token with ID "${honeyTokenId}" not found` });
+ }
+
+ const oldMapping = honeyToken.secretsMapping as Record<string, string>;
+
+ if (secretsMapping) {
+ const newSecretKeys = Object.values(secretsMapping);
+
+ if (new Set(newSecretKeys).size !== newSecretKeys.length) {
+ throw new BadRequestError({
+ message: `Secrets mapping keys must be unique. "${newSecretKeys.join(", ")}" contains duplicate keys.`
+ });
+ }
+
+ const changedKeys = newSecretKeys.filter((key) => !Object.values(oldMapping).includes(key));
+
+ if (changedKeys.length > 0) {
+ const conflictingSecrets = await secretDAL.find({
+ $in: {
+ [`${TableName.SecretV2}.key` as "key"]: changedKeys
+ },
+ [`${TableName.SecretV2}.folderId` as "folderId"]: honeyToken.folderId,
+ [`${TableName.SecretV2}.type` as "type"]: SecretType.Shared
+ });
+
+ if (conflictingSecrets.length) {
+ throw new BadRequestError({
+ message: `The following secrets already exist: ${conflictingSecrets.map(({ key }) => key).join(", ")}`
+ });
+ }
+ }
+
+ const oldSecretKeys = Object.values(oldMapping);
+
+ await fnSecretBulkDelete({
+ folderId: honeyToken.folderId,
+ projectId,
+ inputSecrets: oldSecretKeys.map((key) => ({ type: SecretType.Shared, secretKey: key })),
+ actorId: actor.id,
+ secretDAL,
+ secretQueueService,
+ folderCommitService,
+ secretVersionDAL
+ });
+
+ const { decryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.Organization,
+ orgId: actor.orgId
+ });
+
+ const decryptedCredentials = JSON.parse(
+ decryptor({ cipherTextBlob: honeyToken.encryptedCredentials }).toString()
+ ) as { accessKeyId: string; secretAccessKey: string; iamUserName: string };
+
+ const { encryptor: secretEncryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId
+ });
+
+ const secretEntries = [
+ { key: secretsMapping.accessKeyId, value: decryptedCredentials.accessKeyId },
+ { key: secretsMapping.secretAccessKey, value: decryptedCredentials.secretAccessKey }
+ ];
+
+ await fnSecretBulkInsert({
+ folderId: honeyToken.folderId,
+ orgId: actor.orgId,
+ inputSecrets: secretEntries.map(({ key, value }) => ({
+ key,
+ type: SecretType.Shared,
+ encryptedValue: secretEncryptor({
+ plainText: Buffer.from(value)
+ }).cipherTextBlob,
+ references: []
+ })),
+ secretDAL,
+ secretVersionDAL,
+ secretVersionTagDAL,
+ secretTagDAL,
+ folderCommitService,
+ resourceMetadataDAL,
+ actor: {
+ type: actor.type as ActorType,
+ actorId: actor.id
+ }
+ });
+ }
+
+ const updated = await honeyTokenDAL.updateById(honeyTokenId, {
+ ...(name !== undefined && { name }),
+ ...(description !== undefined && { description }),
+ ...(secretsMapping !== undefined && { secretsMapping })
+ });
+
+ await secretDAL.invalidateSecretCacheByProjectId(projectId);
+ await snapshotService.performSnapshot(honeyToken.folderId);
+
+ const [folderInfo] = await folderDAL.findSecretPathByFolderIds(projectId, [honeyToken.folderId]);
+ if (folderInfo) {
+ await secretQueueService.syncSecrets({
+ orgId: actor.orgId,
+ secretPath: folderInfo.path,
+ projectId,
+ environmentSlug: folderInfo.environmentSlug,
+ excludeReplication: true
+ });
+ }
+
+ return {
+ honeyToken: {
+ id: updated.id,
+ name: updated.name,
+ description: updated.description,
+ type: updated.type,
+ status: updated.status,
+ projectId: updated.projectId,
+ secretsMapping: updated.secretsMapping,
+ createdAt: updated.createdAt,
+ updatedAt: updated.updatedAt
+ }
+ };
+ };
+
const deleteHoneyToken = async (
{ honeyTokenId, projectId }: { honeyTokenId: string; projectId: string },
actor: OrgServiceActor
@@ -448,6 +613,7 @@ export const honeyTokenServiceFactory = ({
return {
create,
+ updateHoneyToken,
deleteHoneyToken,
getDashboardHoneyTokenCount,
getDashboardHoneyTokens
diff --git a/backend/src/server/routes/v1/dashboard-router.ts b/backend/src/server/routes/v1/dashboard-router.ts
index dcdde86c15..f819fcf288 100644
--- a/backend/src/server/routes/v1/dashboard-router.ts
+++ b/backend/src/server/routes/v1/dashboard-router.ts
@@ -118,6 +118,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
.object({
id: z.string().uuid(),
name: z.string(),
+ description: z.string().nullable().optional(),
type: z.string(),
status: z.string(),
projectId: z.string(),
@@ -741,6 +742,7 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
.object({
id: z.string().uuid(),
name: z.string(),
+ description: z.string().nullable().optional(),
type: z.string(),
status: z.string(),
projectId: z.string(),
diff --git a/frontend/src/components/honey-tokens/EditHoneyTokenModal.tsx b/frontend/src/components/honey-tokens/EditHoneyTokenModal.tsx
new file mode 100644
index 0000000000..560f3b8229
--- /dev/null
+++ b/frontend/src/components/honey-tokens/EditHoneyTokenModal.tsx
@@ -0,0 +1,33 @@
+import { HoneyTokenForm } from "@app/components/honey-tokens/forms";
+import { HoneyTokenModalHeader } from "@app/components/honey-tokens/HoneyTokenModalHeader";
+import { Modal, ModalContent } from "@app/components/v2";
+import { HoneyTokenType, TDashboardHoneyToken } from "@app/hooks/api/honeyTokens/types";
+
+type Props = {
+ honeyToken?: TDashboardHoneyToken;
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+};
+
+export const EditHoneyTokenModal = ({ isOpen, onOpenChange, honeyToken }: Props) => {
+ if (!honeyToken) return null;
+
+ return (
+ <Modal isOpen={isOpen} onOpenChange={onOpenChange}>
+ <ModalContent
+ title={<HoneyTokenModalHeader type={honeyToken.type as HoneyTokenType} isEdit />}
+ className="max-w-2xl"
+ bodyClassName="overflow-visible"
+ >
+ <HoneyTokenForm
+ onComplete={() => onOpenChange(false)}
+ onCancel={() => onOpenChange(false)}
+ honeyToken={honeyToken}
+ type={honeyToken.type as HoneyTokenType}
+ secretPath={honeyToken.folder.path}
+ environment={honeyToken.environment.slug}
+ />
+ </ModalContent>
+ </Modal>
+ );
+};
diff --git a/frontend/src/components/honey-tokens/HoneyTokenModalHeader.tsx b/frontend/src/components/honey-tokens/HoneyTokenModalHeader.tsx
index 1bfce4e47a..63312bc657 100644
--- a/frontend/src/components/honey-tokens/HoneyTokenModalHeader.tsx
+++ b/frontend/src/components/honey-tokens/HoneyTokenModalHeader.tsx
@@ -4,9 +4,10 @@ import { HoneyTokenType } from "@app/hooks/api/honeyTokens/types";
type Props = {
type: HoneyTokenType;
+ isEdit?: boolean;
};
-export const HoneyTokenModalHeader = ({ type }: Props) => {
+export const HoneyTokenModalHeader = ({ type, isEdit }: Props) => {
const details = HONEY_TOKEN_MAP[type];
return (
@@ -18,7 +19,7 @@ export const HoneyTokenModalHeader = ({ type }: Props) => {
/>
<div>
<div className="flex items-center gap-x-2 text-mineshaft-300">
- {details.name} Honey Token
+ {isEdit ? "Edit" : ""} {details.name} Honey Token
<DocumentationLinkBadge href="https://infisical.com/docs/documentation/platform/honey-tokens/overview" />
</div>
<p className="text-sm leading-4 text-mineshaft-400">
diff --git a/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx b/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx
index 3aaee3b378..b086707c16 100644
--- a/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx
+++ b/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx
@@ -7,8 +7,8 @@ import { createNotification } from "@app/components/notifications";
import { Button } from "@app/components/v2";
import { useProject } from "@app/context";
import { HONEY_TOKEN_DEFAULT_SECRET_NAMES, HONEY_TOKEN_MAP } from "@app/helpers/honeyTokens";
-import { useCreateHoneyToken } from "@app/hooks/api/honeyTokens";
-import { HoneyTokenType } from "@app/hooks/api/honeyTokens/types";
+import { useCreateHoneyToken, useUpdateHoneyToken } from "@app/hooks/api/honeyTokens";
+import { HoneyTokenType, TDashboardHoneyToken } from "@app/hooks/api/honeyTokens/types";
import { ProjectEnv } from "@app/hooks/api/projects/types";
import { fetchProjectSecrets } from "@app/hooks/api/secrets/queries";
@@ -25,9 +25,10 @@ type Props = {
secretPath: string;
environment?: string;
environments?: ProjectEnv[];
+ honeyToken?: TDashboardHoneyToken;
};
-const FORM_TABS: { name: string; key: string; fields: (keyof THoneyTokenForm)[] }[] = [
+const CREATE_TABS: { name: string; key: string; fields: (keyof THoneyTokenForm)[] }[] = [
{
name: "Configuration",
key: "configuration",
@@ -38,40 +39,69 @@ const FORM_TABS: { name: string; key: string; fields: (keyof THoneyTokenForm)[]
{ name: "Review", key: "review", fields: [] }
];
+const EDIT_TABS: { name: string; key: string; fields: (keyof THoneyTokenForm)[] }[] = [
+ { name: "Mapping", key: "mapping", fields: ["secretsMapping"] },
+ { name: "Details", key: "details", fields: ["name", "description"] },
+ { name: "Review", key: "review", fields: [] }
+];
+
export const HoneyTokenForm = ({
type,
onComplete,
onCancel,
environment: envSlug,
secretPath,
- environments
+ environments,
+ honeyToken
}: Props) => {
const createHoneyToken = useCreateHoneyToken();
+ const updateHoneyToken = useUpdateHoneyToken();
const { currentProject } = useProject();
const { name: tokenTypeName } = HONEY_TOKEN_MAP[type];
+ const isUpdate = Boolean(honeyToken);
+ const formTabs = isUpdate ? EDIT_TABS : CREATE_TABS;
+
const [selectedTabIndex, setSelectedTabIndex] = useState(0);
const formMethods = useForm<THoneyTokenForm>({
resolver: zodResolver(HoneyTokenFormSchema),
- defaultValues: {
- type,
- environment: currentProject?.environments.find((env) => env.slug === envSlug),
- secretPath,
- secretsMapping: HONEY_TOKEN_DEFAULT_SECRET_NAMES[type]
- },
+ defaultValues: honeyToken
+ ? {
+ ...honeyToken,
+ environment: currentProject?.environments.find(
+ (env) => env.slug === honeyToken.environment.slug
+ ),
+ secretPath
+ }
+ : {
+ type,
+ environment: currentProject?.environments.find((env) => env.slug === envSlug),
+ secretPath,
+ secretsMapping: HONEY_TOKEN_DEFAULT_SECRET_NAMES[type]
+ },
reValidateMode: "onChange"
});
const onSubmit = async ({ environment, ...formData }: THoneyTokenForm) => {
- await createHoneyToken.mutateAsync({
- ...formData,
- environment: environment.slug,
- projectId: currentProject.id
- });
+ if (honeyToken) {
+ await updateHoneyToken.mutateAsync({
+ honeyTokenId: honeyToken.id,
+ projectId: honeyToken.projectId,
+ name: formData.name,
+ description: formData.description,
+ secretsMapping: formData.secretsMapping
+ });
+ } else {
+ await createHoneyToken.mutateAsync({
+ ...formData,
+ environment: environment.slug,
+ projectId: currentProject.id
+ });
+ }
createNotification({
- text: `Successfully created ${tokenTypeName} Honey Token`,
+ text: `Successfully ${honeyToken ? "updated" : "created"} ${tokenTypeName} Honey Token`,
type: "success"
});
onComplete();
@@ -92,9 +122,9 @@ export const HoneyTokenForm = ({
formState: { isSubmitting }
} = formMethods;
- const isStepValid = async (index: number) => trigger(FORM_TABS[index].fields);
+ const isStepValid = async (index: number) => trigger(formTabs[index].fields);
- const isFinalStep = selectedTabIndex === FORM_TABS.length - 1;
+ const isFinalStep = selectedTabIndex === formTabs.length - 1;
const [isValidating, setIsValidating] = useState(false);
@@ -120,8 +150,9 @@ export const HoneyTokenForm = ({
secretPath
});
+ const ownKeys = honeyToken ? new Set(Object.values(honeyToken.secretsMapping)) : new Set();
const existingKeys = new Set(data.secrets.map((s) => s.secretKey));
- const conflicts = values.filter((key) => existingKeys.has(key));
+ const conflicts = values.filter((key) => existingKeys.has(key) && !ownKeys.has(key));
if (conflicts.length > 0) {
formMethods.setError("secretsMapping", {
@@ -142,7 +173,7 @@ export const HoneyTokenForm = ({
return true;
};
- const MAPPING_STEP_INDEX = 1;
+ const mappingStepIndex = formTabs.findIndex((tab) => tab.key === "mapping");
const handleNext = async () => {
if (isFinalStep) {
@@ -154,7 +185,7 @@ export const HoneyTokenForm = ({
if (!isValid) return;
- if (selectedTabIndex === MAPPING_STEP_INDEX) {
+ if (selectedTabIndex === mappingStepIndex && !isUpdate) {
const noConflicts = await checkMappingConflicts();
if (!noConflicts) return;
}
@@ -178,7 +209,7 @@ export const HoneyTokenForm = ({
<FormProvider {...formMethods}>
<Tab.Group selectedIndex={selectedTabIndex} onChange={setSelectedTabIndex}>
<Tab.List className="-pb-1 mb-6 w-full border-b-2 border-mineshaft-600">
- {FORM_TABS.map((tab, index) => (
+ {formTabs.map((tab, index) => (
<Tab
onClick={async (e) => {
e.preventDefault();
@@ -199,9 +230,11 @@ export const HoneyTokenForm = ({
))}
</Tab.List>
<Tab.Panels>
- <Tab.Panel>
- <HoneyTokenConfigurationFields environments={environments} />
- </Tab.Panel>
+ {!isUpdate && (
+ <Tab.Panel>
+ <HoneyTokenConfigurationFields environments={environments} />
+ </Tab.Panel>
+ )}
<Tab.Panel>
<HoneyTokenMappingFields />
</Tab.Panel>
@@ -222,7 +255,7 @@ export const HoneyTokenForm = ({
isDisabled={isSubmitting || isValidating}
colorSchema="secondary"
>
- {isFinalStep ? "Create Honey Token" : "Next"}
+ {isFinalStep ? `${honeyToken ? "Update" : "Create"} Honey Token` : "Next"}
</Button>
<Button onClick={handlePrev} colorSchema="secondary">
Back
diff --git a/frontend/src/components/honey-tokens/index.ts b/frontend/src/components/honey-tokens/index.ts
index 348154607f..e80b9f8a8f 100644
--- a/frontend/src/components/honey-tokens/index.ts
+++ b/frontend/src/components/honey-tokens/index.ts
@@ -1,2 +1,3 @@
export * from "./CreateHoneyTokenModal";
export * from "./DeleteHoneyTokenModal";
+export * from "./EditHoneyTokenModal";
diff --git a/frontend/src/hooks/api/honeyTokens/mutations.tsx b/frontend/src/hooks/api/honeyTokens/mutations.tsx
index 00cbdd2be3..91847a872c 100644
--- a/frontend/src/hooks/api/honeyTokens/mutations.tsx
+++ b/frontend/src/hooks/api/honeyTokens/mutations.tsx
@@ -3,7 +3,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { dashboardKeys } from "@app/hooks/api/dashboard/queries";
-import { TCreateHoneyTokenDTO, TDeleteHoneyTokenDTO, THoneyToken } from "./types";
+import { TCreateHoneyTokenDTO, TDeleteHoneyTokenDTO, THoneyToken, TUpdateHoneyTokenDTO } from "./types";
export const useCreateHoneyToken = () => {
const queryClient = useQueryClient();
@@ -20,6 +20,24 @@ export const useCreateHoneyToken = () => {
});
};
+export const useUpdateHoneyToken = () => {
+ const queryClient = useQueryClient();
+
+ return useMutation<THoneyToken, object, TUpdateHoneyTokenDTO>({
+ mutationFn: async ({ honeyTokenId, ...dto }) => {
+ const { data } = await apiRequest.patch<{ honeyToken: THoneyToken }>(
+ `/api/v1/honey-tokens/${honeyTokenId}`,
+ dto
+ );
+ return data.honeyToken;
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ["honeyTokens"] });
+ queryClient.invalidateQueries({ queryKey: dashboardKeys.all() });
+ }
+ });
+};
+
export const useDeleteHoneyToken = () => {
const queryClient = useQueryClient();
diff --git a/frontend/src/hooks/api/honeyTokens/types.ts b/frontend/src/hooks/api/honeyTokens/types.ts
index 2917e8c845..cb4651e4cc 100644
--- a/frontend/src/hooks/api/honeyTokens/types.ts
+++ b/frontend/src/hooks/api/honeyTokens/types.ts
@@ -42,6 +42,14 @@ export type TCreateHoneyTokenDTO = {
secretPath: string;
};
+export type TUpdateHoneyTokenDTO = {
+ honeyTokenId: string;
+ projectId: string;
+ name?: string;
+ description?: string | null;
+ secretsMapping?: Record<string, string>;
+};
+
export type TDeleteHoneyTokenDTO = {
honeyTokenId: string;
projectId: string;
diff --git a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
index 1c933c17e5..e345f7f0a6 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
@@ -29,7 +29,7 @@ import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
import { createNotification } from "@app/components/notifications";
import { ProjectPermissionCan } from "@app/components/permissions";
import { CreateSecretRotationV2Modal } from "@app/components/secret-rotations-v2";
-import { DeleteHoneyTokenModal } from "@app/components/honey-tokens";
+import { DeleteHoneyTokenModal, EditHoneyTokenModal } from "@app/components/honey-tokens";
import { DeleteSecretRotationV2Modal } from "@app/components/secret-rotations-v2/DeleteSecretRotationV2Modal";
import { EditSecretRotationV2Modal } from "@app/components/secret-rotations-v2/EditSecretRotationV2Modal";
import { ReconcileLocalAccountRotationModal } from "@app/components/secret-rotations-v2/ReconcileLocalAccountRotationModal";
@@ -778,6 +778,7 @@ const OverviewPageContent = () => {
"importFromVault",
"importFromDoppler",
"confirmDisableBatchMode",
+ "editHoneyToken",
"deleteHoneyToken"
] as const);
@@ -3082,7 +3083,9 @@ const OverviewPageContent = () => {
getHoneyTokenByName={getHoneyTokenByName}
tableWidth={tableWidth}
key={`overview-ht-${honeyTokenName}-${index + 1}`}
- onEdit={() => {}}
+ onEdit={(honeyToken) =>
+ handlePopUpOpen("editHoneyToken", honeyToken)
+ }
onDelete={(honeyToken) =>
handlePopUpOpen("deleteHoneyToken", honeyToken)
}
@@ -3425,6 +3428,11 @@ const OverviewPageContent = () => {
secretRotation={popUp.deleteSecretRotation.data as TSecretRotationV2}
onOpenChange={(isOpen) => handlePopUpToggle("deleteSecretRotation", isOpen)}
/>
+ <EditHoneyTokenModal
+ isOpen={popUp.editHoneyToken.isOpen}
+ honeyToken={popUp.editHoneyToken.data as TDashboardHoneyToken}
+ onOpenChange={(isOpen) => handlePopUpToggle("editHoneyToken", isOpen)}
+ />
<DeleteHoneyTokenModal
isOpen={popUp.deleteHoneyToken.isOpen}
honeyToken={popUp.deleteHoneyToken.data as TDashboardHoneyToken}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx
index 36991b6e1b..43310dccfb 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx
@@ -1,7 +1,7 @@
import {
ChevronDown,
ClipboardPasteIcon,
- CrosshairIcon,
+ SirenIcon,
FingerprintIcon,
FolderIcon,
ImportIcon,
@@ -144,7 +144,7 @@ export function AddResourceButtons({
<Tooltip open={!isHoneyTokenAvailable ? undefined : false}>
<TooltipTrigger className="block w-full">
<DropdownMenuItem onClick={onAddHoneyToken} isDisabled={!isHoneyTokenAvailable}>
- <CrosshairIcon className="text-yellow" />
+ <SirenIcon className="text-yellow" />
Add Honey Token
</DropdownMenuItem>
</TooltipTrigger>
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 2c075bc63e..44e49ae686 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/HoneyTokenTableRow/HoneyTokenTableRow.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/HoneyTokenTableRow/HoneyTokenTableRow.tsx
@@ -1,4 +1,4 @@
-import { ChevronDownIcon, CrosshairIcon, EditIcon, InfoIcon, TrashIcon } from "lucide-react";
+import { ChevronDownIcon, EditIcon, InfoIcon, SirenIcon, TrashIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
import { ProjectPermissionCan } from "@app/components/permissions";
@@ -165,7 +165,7 @@ export const HoneyTokenTableRow = ({
{!isSingleEnvView && isExpanded ? (
<ChevronDownIcon />
) : (
- <CrosshairIcon className="text-yellow" />
+ <SirenIcon className="text-yellow" />
)}
</TableCell>
<TableCell
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/HoneyTokenListView/HoneyTokenItem.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/HoneyTokenListView/HoneyTokenItem.tsx
index 97580b3946..9ac83f673b 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/HoneyTokenListView/HoneyTokenItem.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/HoneyTokenListView/HoneyTokenItem.tsx
@@ -2,7 +2,7 @@ import { useState } from "react";
import { faEdit, faInfoCircle, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { AnimatePresence, motion } from "framer-motion";
-import { CrosshairIcon } from "lucide-react";
+import { SirenIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
import { ProjectPermissionCan } from "@app/components/permissions";
@@ -48,7 +48,7 @@ export const HoneyTokenItem = ({ honeyToken, onEdit, onDelete }: Props) => {
aria-label={`${isExpanded ? "Collapse" : "Expand"} honey token secrets for ${name}`}
>
<div className="flex w-11 items-center py-2 pl-5 text-yellow">
- <CrosshairIcon className="size-4" />
+ <SirenIcon className="size-4" />
</div>
<div className="flex grow items-center py-2 pr-2 pl-4">
<div className="flex w-full flex-wrap items-center">
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/HoneyTokenListView/HoneyTokenListView.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/HoneyTokenListView/HoneyTokenListView.tsx
index ebe4ce55db..0514944ca3 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/HoneyTokenListView/HoneyTokenListView.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/HoneyTokenListView/HoneyTokenListView.tsx
@@ -1,6 +1,6 @@
import { useState } from "react";
-import { DeleteHoneyTokenModal } from "@app/components/honey-tokens";
+import { DeleteHoneyTokenModal, EditHoneyTokenModal } from "@app/components/honey-tokens";
import { TDashboardHoneyToken } from "@app/hooks/api/honeyTokens/types";
import { HoneyTokenItem } from "./HoneyTokenItem";
@@ -11,6 +11,7 @@ type Props = {
export const HoneyTokenListView = ({ honeyTokens }: Props) => {
const [deleteTarget, setDeleteTarget] = useState<TDashboardHoneyToken>();
+ const [editTarget, setEditTarget] = useState<TDashboardHoneyToken>();
return (
<>
@@ -18,10 +19,17 @@ export const HoneyTokenListView = ({ honeyTokens }: Props) => {
<HoneyTokenItem
key={honeyToken.id}
honeyToken={honeyToken}
- onEdit={() => {}}
+ onEdit={() => setEditTarget(honeyToken)}
onDelete={() => setDeleteTarget(honeyToken)}
/>
))}
+ <EditHoneyTokenModal
+ isOpen={Boolean(editTarget)}
+ onOpenChange={(isOpen) => {
+ if (!isOpen) setEditTarget(undefined);
+ }}
+ honeyToken={editTarget}
+ />
<DeleteHoneyTokenModal
isOpen={Boolean(deleteTarget)}
onOpenChange={(isOpen) => {