Skip to content

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

fix(gateway): address review feedback on rename

bernie-gd8fd4775bb11
diff --git a/backend/src/ee/routes/v3/gateway-router.ts b/backend/src/ee/routes/v3/gateway-router.ts
index 085136eabd..0e4d89a9bf 100644
--- a/backend/src/ee/routes/v3/gateway-router.ts
+++ b/backend/src/ee/routes/v3/gateway-router.ts
@@ -385,27 +385,30 @@ export const registerGatewayV3Router = async (server: FastifyZodProvider) => {
});
}
+ // Held onto for the response: it comes from the primary, and a lagging replica read
+ // would hand back the old name.
+ let renamed;
if (req.body.name) {
- // Use the row from the primary; a lagging replica read would hide the rename.
- const { gateway: renamed, previousName } = await server.services.gatewayV2.renameGateway({
+ const result = await server.services.gatewayV2.renameGateway({
orgPermission: req.permission,
gatewayId: req.params.gatewayId,
name: req.body.name
});
+ renamed = result.gateway;
- if (previousName !== renamed.name) {
+ if (result.previousName !== renamed.name) {
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
orgId: req.permission.orgId,
event: {
type: EventType.GATEWAY_UPDATE,
- metadata: { gatewayId: renamed.id, name: renamed.name, previousName }
+ metadata: { gatewayId: renamed.id, name: renamed.name, previousName: result.previousName }
}
});
}
}
- const gateway = await server.services.gatewayV2.getGatewayById({ gatewayId: req.params.gatewayId });
+ const gateway = renamed ?? (await server.services.gatewayV2.getGatewayById({ gatewayId: req.params.gatewayId }));
const view = await server.services.resourceAuthMethod.getByGatewayId({
resource: { type: "gateway", id: req.params.gatewayId },
actor: req.permission
diff --git a/frontend/src/hooks/api/auditLogs/constants.tsx b/frontend/src/hooks/api/auditLogs/constants.tsx
index d299c3b32a..fa7793a6c0 100644
--- a/frontend/src/hooks/api/auditLogs/constants.tsx
+++ b/frontend/src/hooks/api/auditLogs/constants.tsx
@@ -437,6 +437,8 @@ export const eventToNameMap: { [K in EventType]: string } = {
[EventType.EXTERNAL_MIGRATION_DELETE]: "Delete External Migration",
[EventType.IMPORT_VAULT_SECRETS]: "Import Vault secrets",
[EventType.GATEWAY_CREATE]: "Create gateway",
+ [EventType.GATEWAY_UPDATE]: "Update gateway",
+ [EventType.GATEWAY_DELETE]: "Delete gateway",
[EventType.GATEWAY_ENROLL]: "Enroll gateway (legacy)",
[EventType.GATEWAY_CONNECT]: "Gateway connect",
[EventType.GATEWAY_ENROLLMENT_TOKEN_CREATE]: "Generate gateway enrollment token",
diff --git a/frontend/src/hooks/api/auditLogs/enums.tsx b/frontend/src/hooks/api/auditLogs/enums.tsx
index 16120fd641..e7aee8583a 100644
--- a/frontend/src/hooks/api/auditLogs/enums.tsx
+++ b/frontend/src/hooks/api/auditLogs/enums.tsx
@@ -433,6 +433,8 @@ export enum EventType {
// Gateway
GATEWAY_CREATE = "gateway-create",
+ GATEWAY_UPDATE = "gateway-update",
+ GATEWAY_DELETE = "gateway-delete",
GATEWAY_ENROLL = "gateway-enroll",
GATEWAY_CONNECT = "gateway-connect",
GATEWAY_ENROLLMENT_TOKEN_CREATE = "gateway-enrollment-token-create",
diff --git a/frontend/src/pages/organization/NetworkingPage/components/RenameGatewayModal.tsx b/frontend/src/pages/organization/NetworkingPage/components/RenameGatewayModal.tsx
index 9194c52ca8..ac573ef417 100644
--- a/frontend/src/pages/organization/NetworkingPage/components/RenameGatewayModal.tsx
+++ b/frontend/src/pages/organization/NetworkingPage/components/RenameGatewayModal.tsx
@@ -36,12 +36,7 @@ type Props = {
export const RenameGatewayModal = ({ isOpen, onToggle, gateway }: Props) => {
const updateGateway = useUpdateGateway();
- const {
- control,
- handleSubmit,
- reset,
- formState: { isSubmitting }
- } = useForm<TFormData>({
+ const { control, handleSubmit, reset } = useForm<TFormData>({
resolver: zodResolver(formSchema),
defaultValues: { name: gateway.name }
});
@@ -50,20 +45,21 @@ export const RenameGatewayModal = ({ isOpen, onToggle, gateway }: Props) => {
if (isOpen) reset({ name: gateway.name });
}, [isOpen, gateway.name, reset]);
- const onFormSubmit = async ({ name }: TFormData) => {
+ const onFormSubmit = ({ name }: TFormData) => {
if (name === gateway.name) {
onToggle(false);
return;
}
- try {
- await updateGateway.mutateAsync({ gatewayId: gateway.id, name });
- createNotification({ type: "success", text: "Gateway renamed" });
- onToggle(false);
- } catch (err: unknown) {
- const message = err instanceof Error ? err.message : "Failed to rename gateway";
- createNotification({ type: "error", text: message });
- }
+ updateGateway.mutate(
+ { gatewayId: gateway.id, name },
+ {
+ onSuccess: () => {
+ createNotification({ type: "success", text: "Gateway renamed" });
+ onToggle(false);
+ }
+ }
+ );
};
return (
@@ -97,7 +93,12 @@ export const RenameGatewayModal = ({ isOpen, onToggle, gateway }: Props) => {
Cancel
</Button>
</DialogClose>
- <Button variant="org" type="submit" isPending={isSubmitting} isDisabled={isSubmitting}>
+ <Button
+ variant="org"
+ type="submit"
+ isPending={updateGateway.isPending}
+ isDisabled={updateGateway.isPending}
+ >
Save Changes
</Button>
</DialogFooter>