Skip to content

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

add rotation status

Daniel Hougaard63f8191aa0b8
diff --git a/backend/src/services/app-connection/app-connection-dal.ts b/backend/src/services/app-connection/app-connection-dal.ts
index 0f375e531e..cd2984b226 100644
--- a/backend/src/services/app-connection/app-connection-dal.ts
+++ b/backend/src/services/app-connection/app-connection-dal.ts
@@ -6,6 +6,7 @@ import { buildFindFilter, ormify, prependTableNameToFindFilter, selectAllTableCo
import { transformUsageToProjects } from "@app/services/app-connection/app-connection-fns";
import { TAppConnection } from "./app-connection-types";
+import { AppConnectionCredentialRotationStatus } from "./credential-rotation";
import { AppConnectionCredentialRotationRotateAtUtcSchema } from "./credential-rotation/app-connection-credential-rotation-schemas";
export type TAppConnectionDALFactory = ReturnType<typeof appConnectionDALFactory>;
@@ -26,7 +27,8 @@ export const appConnectionDALFactory = (db: TDbClient) => {
.select(selectAllTableCols(TableName.AppConnection))
.select(
db.ref("rotationInterval").withSchema(TableName.AppConnectionCredentialRotation).as("rotationInterval"),
- db.ref("rotateAtUtc").withSchema(TableName.AppConnectionCredentialRotation).as("rotateAtUtc")
+ db.ref("rotateAtUtc").withSchema(TableName.AppConnectionCredentialRotation).as("rotateAtUtc"),
+ db.ref("rotationStatus").withSchema(TableName.AppConnectionCredentialRotation).as("rotationStatus")
)
.select(
// project
@@ -51,6 +53,7 @@ export const appConnectionDALFactory = (db: TDbClient) => {
if (parsedRotationAtUtc.success) {
rotation = {
rotationInterval: connection.rotationInterval,
+ rotationStatus: connection.rotationStatus as AppConnectionCredentialRotationStatus,
rotateAtUtc: parsedRotationAtUtc.data
};
}
diff --git a/backend/src/services/app-connection/app-connection-schemas.ts b/backend/src/services/app-connection/app-connection-schemas.ts
index 3b1dd78172..f7d65b92de 100644
--- a/backend/src/services/app-connection/app-connection-schemas.ts
+++ b/backend/src/services/app-connection/app-connection-schemas.ts
@@ -7,6 +7,7 @@ import { APP_CONNECTION_NAME_MAP } from "@app/services/app-connection/app-connec
import { TAppConnectionBaseConfig } from "@app/services/app-connection/app-connection-types";
import { AppConnection } from "./app-connection-enums";
+import { AppConnectionCredentialRotationStatus } from "./credential-rotation/app-connection-credential-rotation-enums";
import { CreateAppConnectionCredentialRotationSchema } from "./credential-rotation/app-connection-credential-rotation-schemas";
export const BaseAppConnectionSchema = AppConnectionsSchema.omit({
@@ -17,6 +18,7 @@ export const BaseAppConnectionSchema = AppConnectionsSchema.omit({
rotation: z
.object({
rotationInterval: z.number(),
+ rotationStatus: z.nativeEnum(AppConnectionCredentialRotationStatus),
rotateAtUtc: z.object({
hours: z.number(),
minutes: z.number()
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
new file mode 100644
index 0000000000..ffd1fafc24
--- /dev/null
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/shared/CrededentialRotationBadge.tsx
@@ -0,0 +1,97 @@
+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 { Tooltip } from "@app/components/v2";
+import { Badge } from "@app/components/v3";
+import { TAppConnection } from "@app/hooks/api/appConnections";
+import { AppConnectionCredentialRotationStatus } from "@app/hooks/api/appConnections/types/root-connection-enums";
+
+type Props = {
+ appConnection: TAppConnection;
+};
+
+export const CrededentialRotationStatusBadge = ({ appConnection }: Props) => {
+ const { isAutoRotationEnabled, rotation } = appConnection;
+
+ if (!rotation) {
+ return null;
+ }
+
+ if (rotation.rotationStatus === AppConnectionCredentialRotationStatus.Failed) {
+ let errorMessage = lastRotationMessage;
+ if (lastRotationMessage) {
+ try {
+ errorMessage = JSON.stringify(JSON.parse(lastRotationMessage), null, 2);
+ } catch {
+ errorMessage = lastRotationMessage;
+ }
+ }
+
+ return (
+ <Tooltip
+ position="left"
+ className="max-w-sm select-text"
+ content={
+ <div className="flex flex-col gap-2 py-1 whitespace-normal">
+ <div>
+ <div className="mb-2 flex self-start text-red">
+ <FontAwesomeIcon icon={faXmark} className="ml-1 pt-0.5 pr-1.5 text-sm" />
+ <div className="text-xs">Failure Reason</div>
+ </div>
+ <div className="rounded-sm bg-mineshaft-600 p-2 text-xs break-words">
+ {errorMessage}
+ </div>
+ </div>
+ {nextRotationAt && (
+ <span className="text-xs text-mineshaft-300">
+ Next rotation attempt on {format(nextRotationAt, "MM/dd/yyyy")} at{" "}
+ {format(nextRotationAt, "h:mm aa")}.
+ </span>
+ )}
+ </div>
+ }
+ >
+ <Badge variant="danger">
+ <XIcon />
+ Rotation Failed
+ </Badge>
+ </Tooltip>
+ );
+ }
+
+ if (!isAutoRotationEnabled) {
+ return (
+ <Badge variant="neutral">
+ <BanIcon />
+ Auto-Rotation Disabled
+ </Badge>
+ );
+ }
+
+ const daysToRotation =
+ (new Date(nextRotationAt).getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24);
+
+ return (
+ <Tooltip
+ className="max-w-lg"
+ content={
+ <>
+ <span>
+ Rotates on {format(nextRotationAt, "MM/dd/yyyy")} at {format(nextRotationAt, "h:mm aa")}
+ </span>{" "}
+ <span className="text-mineshaft-300">(Local Time)</span>
+ </>
+ }
+ asChild
+ >
+ <Badge variant={daysToRotation >= 7 ? "info" : "warning"} className="capitalize">
+ <RefreshCwIcon />
+ {daysToRotation < 0
+ ? "Rotating"
+ : `Rotates ${formatDistanceToNow(nextRotationAt, { addSuffix: true })}`}
+ </Badge>
+ </Tooltip>
+ );
+};