Skip to content

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

checkpoint

Daniel Hougaard46248ac2e34e
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index 808595c382..bda9d681d6 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -440,6 +440,7 @@ export enum EventType {
DELETE_APP_CONNECTION = "delete-app-connection",
GET_APP_CONNECTION_USAGE = "get-app-connection-usage",
MIGRATE_APP_CONNECTION = "migrate-app-connection",
+ ROTATE_APP_CONNECTION_CREDENTIALS = "rotate-app-connection-credentials",
CREATE_SHARED_SECRET = "create-shared-secret",
CREATE_SECRET_REQUEST = "create-secret-request",
DELETE_SHARED_SECRET = "delete-shared-secret",
@@ -3322,6 +3323,13 @@ interface DeleteAppConnectionEvent {
};
}
+interface RotateAppConnectionCredentialsEvent {
+ type: EventType.ROTATE_APP_CONNECTION_CREDENTIALS;
+ metadata: {
+ connectionId: string;
+ };
+}
+
interface CreateSharedSecretEvent {
type: EventType.CREATE_SHARED_SECRET;
metadata: {
@@ -5324,6 +5332,7 @@ export type Event =
| DeleteAppConnectionEvent
| GetAppConnectionUsageEvent
| MigrateAppConnectionEvent
+ | RotateAppConnectionCredentialsEvent
| GetSshHostGroupEvent
| CreateSshHostGroupEvent
| UpdateSshHostGroupEvent
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index e8c911a3ef..0dbce363d2 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -2483,6 +2483,9 @@ export const AppConnections = {
DELETE: (app: AppConnection) => ({
connectionId: `The ID of the ${APP_CONNECTION_NAME_MAP[app]} Connection to be deleted.`
}),
+ ROTATE_CREDENTIALS: (app: AppConnection) => ({
+ connectionId: `The ID of the ${APP_CONNECTION_NAME_MAP[app]} Connection to rotate credentials for.`
+ }),
CREDENTIALS: {
AUTH0_CONNECTION: {
domain: "The domain of the Auth0 instance to connect to.",
diff --git a/backend/src/server/routes/v1/app-connection-routers/app-connection-endpoints.ts b/backend/src/server/routes/v1/app-connection-routers/app-connection-endpoints.ts
index 77bb2de1eb..a2db74b031 100644
--- a/backend/src/server/routes/v1/app-connection-routers/app-connection-endpoints.ts
+++ b/backend/src/server/routes/v1/app-connection-routers/app-connection-endpoints.ts
@@ -416,6 +416,52 @@ export const registerAppConnectionEndpoints = <T extends TAppConnection, I exten
}
});
+ server.route({
+ method: "POST",
+ url: "/:connectionId/rotate-credentials",
+ config: {
+ rateLimit: writeLimit
+ },
+ schema: {
+ hide: false,
+ operationId: `rotate${appNameForOpId}AppConnectionCredentials`,
+ tags: [ApiDocsTags.AppConnections],
+ description: `Rotate the credentials for the specified ${appName} Connection.`,
+ params: z.object({
+ connectionId: z.string().uuid().describe(AppConnections.ROTATE_CREDENTIALS(app).connectionId)
+ }),
+ response: {
+ 200: z.object({ appConnection: sanitizedResponseSchema })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
+ handler: async (req) => {
+ const { connectionId } = req.params;
+
+ await server.services.appConnection.triggerCredentialRotation({ app, connectionId }, req.permission);
+
+ const appConnection = (await server.services.appConnection.findAppConnectionById(
+ app,
+ connectionId,
+ req.permission
+ )) as T;
+
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ orgId: req.permission.orgId,
+ projectId: appConnection.projectId ?? undefined,
+ event: {
+ type: EventType.ROTATE_APP_CONNECTION_CREDENTIALS,
+ metadata: {
+ connectionId
+ }
+ }
+ });
+
+ return { appConnection };
+ }
+ });
+
// scott: we will need this once we have individual app connection page and may want to expose to API
// server.route({
// method: "GET",
diff --git a/backend/src/services/app-connection/app-connection-dal.ts b/backend/src/services/app-connection/app-connection-dal.ts
index cd2984b226..9b6c38c6fd 100644
--- a/backend/src/services/app-connection/app-connection-dal.ts
+++ b/backend/src/services/app-connection/app-connection-dal.ts
@@ -28,7 +28,12 @@ export const appConnectionDALFactory = (db: TDbClient) => {
.select(
db.ref("rotationInterval").withSchema(TableName.AppConnectionCredentialRotation).as("rotationInterval"),
db.ref("rotateAtUtc").withSchema(TableName.AppConnectionCredentialRotation).as("rotateAtUtc"),
- db.ref("rotationStatus").withSchema(TableName.AppConnectionCredentialRotation).as("rotationStatus")
+ db.ref("rotationStatus").withSchema(TableName.AppConnectionCredentialRotation).as("rotationStatus"),
+ db
+ .ref("encryptedLastRotationMessage")
+ .withSchema(TableName.AppConnectionCredentialRotation)
+ .as("encryptedLastRotationMessage"),
+ db.ref("nextRotationAt").withSchema(TableName.AppConnectionCredentialRotation).as("nextRotationAt")
)
.select(
// project
@@ -45,7 +50,12 @@ export const appConnectionDALFactory = (db: TDbClient) => {
const connections = await query;
return connections.map(({ projectName, projectSlug, projectType, projectId, ...connection }) => {
- let rotation: TAppConnection["rotation"] | undefined;
+ let rotation:
+ | (Omit<NonNullable<TAppConnection["rotation"]>, "lastRotationMessage"> & {
+ encryptedLastRotationMessage?: Buffer | null;
+ })
+ | undefined
+ | null;
if (connection.isAutoRotationEnabled && connection.rotateAtUtc) {
const parsedRotationAtUtc = AppConnectionCredentialRotationRotateAtUtcSchema.safeParse(connection.rotateAtUtc);
@@ -53,6 +63,8 @@ export const appConnectionDALFactory = (db: TDbClient) => {
if (parsedRotationAtUtc.success) {
rotation = {
rotationInterval: connection.rotationInterval,
+ nextRotationAt: connection.nextRotationAt,
+ encryptedLastRotationMessage: connection.encryptedLastRotationMessage,
rotationStatus: connection.rotationStatus as AppConnectionCredentialRotationStatus,
rotateAtUtc: parsedRotationAtUtc.data
};
diff --git a/backend/src/services/app-connection/app-connection-fns.ts b/backend/src/services/app-connection/app-connection-fns.ts
index 45a71de67e..459048dfde 100644
--- a/backend/src/services/app-connection/app-connection-fns.ts
+++ b/backend/src/services/app-connection/app-connection-fns.ts
@@ -84,6 +84,8 @@ import {
getCloudflareConnectionListItem,
validateCloudflareConnectionCredentials
} from "./cloudflare/cloudflare-connection-fns";
+import { AppConnectionCredentialRotationStatus } from "./credential-rotation";
+import { decryptRotationMessage } from "./credential-rotation/app-connection-credential-rotation-fns";
import { DatabricksConnectionMethod } from "./databricks";
import {
getDatabricksConnectionListItem,
@@ -486,7 +488,13 @@ export const getAppConnectionMethodName = (method: TAppConnection["method"]) =>
export const decryptAppConnection = async (
appConnection: TAppConnections & {
- rotation?: { rotationInterval: number; rotateAtUtc: { hours: number; minutes: number } };
+ rotation?: {
+ nextRotationAt?: Date | null;
+ encryptedLastRotationMessage?: Buffer;
+ rotationInterval: number;
+ rotateAtUtc: { hours: number; minutes: number };
+ rotationStatus: AppConnectionCredentialRotationStatus;
+ };
project?: { name: string; id: string; type: string; slug: string } | null;
},
kmsService: TAppConnectionServiceFactoryDep["kmsService"]
@@ -495,8 +503,14 @@ export const decryptAppConnection = async (
...appConnection,
rotation: appConnection.rotation
? {
- rotationInterval: appConnection.rotation.rotationInterval,
- rotateAtUtc: appConnection.rotation.rotateAtUtc
+ ...appConnection.rotation,
+ lastRotationMessage: appConnection.rotation.encryptedLastRotationMessage
+ ? await decryptRotationMessage({
+ orgId: appConnection.orgId,
+ encryptedLastRotationMessage: appConnection.rotation.encryptedLastRotationMessage,
+ kmsService
+ })
+ : null
}
: undefined,
credentials: await decryptAppConnectionCredentials({
diff --git a/backend/src/services/app-connection/app-connection-schemas.ts b/backend/src/services/app-connection/app-connection-schemas.ts
index f7d65b92de..b178c108f7 100644
--- a/backend/src/services/app-connection/app-connection-schemas.ts
+++ b/backend/src/services/app-connection/app-connection-schemas.ts
@@ -17,7 +17,9 @@ export const BaseAppConnectionSchema = AppConnectionsSchema.omit({
}).extend({
rotation: z
.object({
+ lastRotationMessage: z.string().optional().nullable(),
rotationInterval: z.number(),
+ nextRotationAt: z.date().nullable().optional(),
rotationStatus: z.nativeEnum(AppConnectionCredentialRotationStatus),
rotateAtUtc: z.object({
hours: z.number(),
diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.ts
index 969a0e1b36..4277f90744 100644
--- a/backend/src/services/app-connection/app-connection-service.ts
+++ b/backend/src/services/app-connection/app-connection-service.ts
@@ -899,6 +899,50 @@ export const appConnectionServiceFactory = ({
return projectUsage;
};
+ const triggerCredentialRotation = async (
+ { app, connectionId }: { app: AppConnection; connectionId: string },
+ actor: OrgServiceActor
+ ) => {
+ const appConnection = await appConnectionDAL.findById(connectionId);
+
+ if (!appConnection) throw new NotFoundError({ message: `Could not find App Connection with ID ${connectionId}` });
+
+ if (appConnection.app !== app)
+ throw new BadRequestError({ message: `App Connection with ID ${connectionId} is not for App "${app}"` });
+
+ if (appConnection.projectId) {
+ const { permission } = await permissionService.getProjectPermission({
+ actor: actor.type,
+ actorId: actor.id,
+ projectId: appConnection.projectId,
+ actorAuthMethod: actor.authMethod,
+ actorOrgId: actor.orgId,
+ actionProjectType: ActionProjectType.Any
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(
+ ProjectPermissionAppConnectionActions.Edit,
+ subject(ProjectPermissionSub.AppConnections, { connectionId })
+ );
+ } else {
+ const { permission } = await permissionService.getOrgPermission({
+ actorId: actor.id,
+ actor: actor.type,
+ orgId: appConnection.orgId,
+ actorOrgId: actor.orgId,
+ actorAuthMethod: actor.authMethod,
+ scope: OrganizationActionScope.Any
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionAppConnectionActions.Edit,
+ subject(OrgPermissionSubjects.AppConnections, { connectionId })
+ );
+ }
+
+ return appConnectionCredentialRotationService.triggerRotation({ connectionId });
+ };
+
return {
listAppConnectionOptions,
listAppConnections,
@@ -911,6 +955,7 @@ export const appConnectionServiceFactory = ({
validateAppConnectionUsageById,
listAvailableAppConnectionsForUser,
findAppConnectionUsageById,
+ triggerCredentialRotation,
github: githubConnectionService(connectAppConnectionById, gatewayService, gatewayV2Service),
githubRadar: githubRadarConnectionService(connectAppConnectionById),
gcp: gcpConnectionService(connectAppConnectionById),
diff --git a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-fns.ts b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-fns.ts
index a7ae55b8b8..42dc4188f4 100644
--- a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-fns.ts
+++ b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-fns.ts
@@ -205,6 +205,27 @@ export const encryptRotationMessage = async ({
return cipherTextBlob;
};
+export const decryptRotationMessage = async ({
+ orgId,
+ encryptedLastRotationMessage,
+ kmsService
+}: {
+ orgId: string;
+ encryptedLastRotationMessage: Buffer;
+ kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
+}) => {
+ const { decryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.Organization,
+ orgId
+ });
+
+ const decryptedPlainTextBlob = decryptor({
+ cipherTextBlob: encryptedLastRotationMessage
+ });
+
+ return decryptedPlainTextBlob.toString();
+};
+
export const expandCredentialRotation = async (
{ encryptedLastRotationMessage, ...rotation }: TAppConnectionCredentialRotationRaw,
orgId: string,
diff --git a/frontend/src/hooks/api/appConnections/mutations.tsx b/frontend/src/hooks/api/appConnections/mutations.tsx
index cee433462b..1e60bc609f 100644
--- a/frontend/src/hooks/api/appConnections/mutations.tsx
+++ b/frontend/src/hooks/api/appConnections/mutations.tsx
@@ -6,6 +6,7 @@ import {
TAppConnectionResponse,
TCreateAppConnectionDTO,
TDeleteAppConnectionDTO,
+ TRotateAppConnectionCredentialsDTO,
TUpdateAppConnectionDTO
} from "@app/hooks/api/appConnections/types";
@@ -46,6 +47,23 @@ export const useUpdateAppConnection = () => {
});
};
+export const useRotateAppConnectionCredentials = () => {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: async ({ connectionId, app }: TRotateAppConnectionCredentialsDTO) => {
+ const { data } = await apiRequest.post<TAppConnectionResponse>(
+ `/api/v1/app-connections/${app}/${connectionId}/rotate-credentials`
+ );
+
+ return data.appConnection;
+ },
+ onSuccess: (_, { projectId, app }) => {
+ queryClient.invalidateQueries({ queryKey: appConnectionKeys.list(projectId) });
+ queryClient.invalidateQueries({ queryKey: appConnectionKeys.listAvailable(app, projectId) });
+ }
+ });
+};
+
export const useDeleteAppConnection = () => {
const queryClient = useQueryClient();
return useMutation({
diff --git a/frontend/src/hooks/api/appConnections/types/index.ts b/frontend/src/hooks/api/appConnections/types/index.ts
index 1f5bde1c4b..954df4959f 100644
--- a/frontend/src/hooks/api/appConnections/types/index.ts
+++ b/frontend/src/hooks/api/appConnections/types/index.ts
@@ -189,6 +189,12 @@ export type TDeleteAppConnectionDTO = {
connectionId: string;
};
+export type TRotateAppConnectionCredentialsDTO = {
+ app: AppConnection;
+ connectionId: string;
+ projectId?: string;
+};
+
// scott: we will need this once we have individual app connection page
// export type TAppConnectionMap = {
// [AppConnection.AWS]: TAwsConnection;
diff --git a/frontend/src/hooks/api/appConnections/types/root-connection-enums.ts b/frontend/src/hooks/api/appConnections/types/root-connection-enums.ts
new file mode 100644
index 0000000000..76238fc073
--- /dev/null
+++ b/frontend/src/hooks/api/appConnections/types/root-connection-enums.ts
@@ -0,0 +1,4 @@
+export enum AppConnectionCredentialRotationStatus {
+ Success = "success",
+ Failed = "failed"
+}
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/shared/CrededentialRotationBadge.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/shared/CrededentialRotationBadge.tsx
index ffd1fafc24..4ca2cec877 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/shared/CrededentialRotationBadge.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/shared/CrededentialRotationBadge.tsx
@@ -1,7 +1,7 @@
import { faXmark } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { format, formatDistanceToNow } from "date-fns";
-import { BanIcon, RefreshCwIcon, XIcon } from "lucide-react";
+import { RefreshCwIcon, XIcon } from "lucide-react";
import { Tooltip } from "@app/components/v2";
import { Badge } from "@app/components/v3";
@@ -15,17 +15,17 @@ type Props = {
export const CrededentialRotationStatusBadge = ({ appConnection }: Props) => {
const { isAutoRotationEnabled, rotation } = appConnection;
- if (!rotation) {
+ if (!rotation || !isAutoRotationEnabled) {
return null;
}
if (rotation.rotationStatus === AppConnectionCredentialRotationStatus.Failed) {
- let errorMessage = lastRotationMessage;
- if (lastRotationMessage) {
+ let errorMessage = rotation.lastRotationMessage;
+ if (rotation.lastRotationMessage) {
try {
- errorMessage = JSON.stringify(JSON.parse(lastRotationMessage), null, 2);
+ errorMessage = JSON.stringify(JSON.parse(rotation.lastRotationMessage), null, 2);
} catch {
- errorMessage = lastRotationMessage;
+ errorMessage = rotation.lastRotationMessage;
}
}
@@ -44,10 +44,10 @@ export const CrededentialRotationStatusBadge = ({ appConnection }: Props) => {
{errorMessage}
</div>
</div>
- {nextRotationAt && (
+ {rotation.nextRotationAt && (
<span className="text-xs text-mineshaft-300">
- Next rotation attempt on {format(nextRotationAt, "MM/dd/yyyy")} at{" "}
- {format(nextRotationAt, "h:mm aa")}.
+ Next rotation attempt on {format(rotation.nextRotationAt, "MM/dd/yyyy")} at{" "}
+ {format(rotation.nextRotationAt, "h:mm aa")}.
</span>
)}
</div>
@@ -61,17 +61,8 @@ export const CrededentialRotationStatusBadge = ({ appConnection }: Props) => {
);
}
- if (!isAutoRotationEnabled) {
- return (
- <Badge variant="neutral">
- <BanIcon />
- Auto-Rotation Disabled
- </Badge>
- );
- }
-
const daysToRotation =
- (new Date(nextRotationAt).getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24);
+ (new Date(rotation.nextRotationAt).getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24);
return (
<Tooltip
@@ -79,7 +70,8 @@ export const CrededentialRotationStatusBadge = ({ appConnection }: Props) => {
content={
<>
<span>
- Rotates on {format(nextRotationAt, "MM/dd/yyyy")} at {format(nextRotationAt, "h:mm aa")}
+ Rotates on {format(rotation.nextRotationAt, "MM/dd/yyyy")} at{" "}
+ {format(rotation.nextRotationAt, "h:mm aa")}
</span>{" "}
<span className="text-mineshaft-300">(Local Time)</span>
</>
@@ -90,7 +82,7 @@ export const CrededentialRotationStatusBadge = ({ appConnection }: Props) => {
<RefreshCwIcon />
{daysToRotation < 0
? "Rotating"
- : `Rotates ${formatDistanceToNow(nextRotationAt, { addSuffix: true })}`}
+ : `Rotates ${formatDistanceToNow(rotation.nextRotationAt, { addSuffix: true })}`}
</Badge>
</Tooltip>
);
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx
index 1cd3a6e2ca..9c1146b264 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx
@@ -8,12 +8,13 @@ import {
faEdit,
faEllipsisV,
faInfoCircle,
+ faRotate,
faTable,
faTrash
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Link } from "@tanstack/react-router";
-import { ClockIcon, ServerIcon } from "lucide-react";
+import { ServerIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
import { createNotification } from "@app/components/notifications";
@@ -37,11 +38,14 @@ import { getProjectBaseURL } from "@app/helpers/project";
import { useToggle } from "@app/hooks";
import { TAppConnection } from "@app/hooks/api/appConnections";
+import { CrededentialRotationStatusBadge } from "./AppConnectionForm/shared/CrededentialRotationBadge";
+
type Props = {
appConnection: TAppConnection;
onDelete: (appConnection: TAppConnection) => void;
onEditCredentials: (appConnection: TAppConnection) => void;
onEditDetails: (appConnection: TAppConnection) => void;
+ onRotateCredentials: (appConnection: TAppConnection) => void;
isProjectView: boolean;
};
@@ -50,6 +54,7 @@ export const AppConnectionRow = ({
onDelete,
onEditCredentials,
onEditDetails,
+ onRotateCredentials,
isProjectView
}: Props) => {
const { currentOrg } = useOrganization();
@@ -176,17 +181,7 @@ export const AppConnectionRow = ({
)}
{isAutoRotationEnabled && (
- <Tooltip
- side="left"
- content="This connection's credentials are automatically rotated by Infisical."
- >
- <div>
- <Badge variant="org">
- <ClockIcon />
- Automatic Credential Rotation
- </Badge>
- </div>
- </Tooltip>
+ <CrededentialRotationStatusBadge appConnection={appConnection} />
)}
<Tooltip className="max-w-sm text-center" content="Options">
@@ -264,6 +259,35 @@ export const AppConnectionRow = ({
</DropdownMenuItem>
)}
</VariablePermissionCan>
+ {isAutoRotationEnabled && (
+ <VariablePermissionCan
+ type={isProjectView ? "project" : "org"}
+ I={
+ isProjectView
+ ? ProjectPermissionAppConnectionActions.Edit
+ : OrgPermissionAppConnectionActions.Edit
+ }
+ a={
+ isProjectView
+ ? subject(ProjectPermissionSub.AppConnections, {
+ connectionId: id
+ })
+ : subject(OrgPermissionSubjects.AppConnections, {
+ connectionId: id
+ })
+ }
+ >
+ {(isAllowed: boolean) => (
+ <DropdownMenuItem
+ isDisabled={!isAllowed}
+ icon={<FontAwesomeIcon icon={faRotate} />}
+ onClick={() => onRotateCredentials(appConnection)}
+ >
+ Rotate Credentials
+ </DropdownMenuItem>
+ )}
+ </VariablePermissionCan>
+ )}
<VariablePermissionCan
type={isProjectView ? "project" : "org"}
I={
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionsTable.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionsTable.tsx
index 1af82c0c50..14f12deeea 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionsTable.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionsTable.tsx
@@ -12,6 +12,7 @@ import {
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { twMerge } from "tailwind-merge";
+import { createNotification } from "@app/components/notifications";
import { VariablePermissionCan } from "@app/components/permissions";
import {
Button,
@@ -43,7 +44,11 @@ import {
setUserTablePreference
} from "@app/helpers/userTablePreferences";
import { usePagination, usePopUp, useResetPageHelper } from "@app/hooks";
-import { TAppConnection, useListAppConnections } from "@app/hooks/api/appConnections";
+import {
+ TAppConnection,
+ useListAppConnections,
+ useRotateAppConnectionCredentials
+} from "@app/hooks/api/appConnections";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { OrderByDirection } from "@app/hooks/api/generic/types";
import { ProjectType } from "@app/hooks/api/projects/types";
@@ -80,6 +85,7 @@ type Props = {
export const AppConnectionsTable = ({ projectId, projectType }: Props) => {
const isProjectView = Boolean(projectId);
const { isPending, data: appConnections = [] } = useListAppConnections(projectId);
+ const rotateCredentials = useRotateAppConnectionCredentials();
const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp([
"addConnection",
@@ -207,6 +213,26 @@ export const AppConnectionsTable = ({ projectId, projectType }: Props) => {
const handleEditDetails = (appConnection: TAppConnection) =>
handlePopUpOpen("editDetails", appConnection);
+ const handleRotateCredentials = (appConnection: TAppConnection) => {
+ rotateCredentials.mutate(
+ { connectionId: appConnection.id, app: appConnection.app, projectId },
+ {
+ onSuccess: () => {
+ createNotification({
+ text: "Credential rotation has been triggered",
+ type: "success"
+ });
+ },
+ onError: (error) => {
+ createNotification({
+ text: `Failed to trigger credential rotation: ${error.message}`,
+ type: "error"
+ });
+ }
+ }
+ );
+ };
+
return (
<div className="rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
<div className="mb-4 flex flex-wrap items-center justify-between gap-2">
@@ -415,6 +441,7 @@ export const AppConnectionsTable = ({ projectId, projectType }: Props) => {
onDelete={handleDelete}
onEditCredentials={handleEditCredentials}
onEditDetails={handleEditDetails}
+ onRotateCredentials={handleRotateCredentials}
isProjectView={isProjectView}
/>
))}