Make rotationIntervalSeconds nullable

This commit is contained in:
x032205
2025-10-21 16:21:52 -04:00
parent 65b36e6232
commit 85daaf806e
8 changed files with 12 additions and 11 deletions
@@ -10,7 +10,7 @@ export async function up(knex: Knex): Promise<void> {
) { ) {
await knex.schema.alterTable(TableName.PamAccount, (t) => { await knex.schema.alterTable(TableName.PamAccount, (t) => {
t.boolean("rotationEnabled").notNullable().defaultTo(false); t.boolean("rotationEnabled").notNullable().defaultTo(false);
t.integer("rotationIntervalSeconds").notNullable(); t.integer("rotationIntervalSeconds").nullable();
t.timestamp("lastRotatedAt").nullable(); t.timestamp("lastRotatedAt").nullable();
}); });
} }
+1 -1
View File
@@ -20,7 +20,7 @@ export const PamAccountsSchema = z.object({
createdAt: z.date(), createdAt: z.date(),
updatedAt: z.date(), updatedAt: z.date(),
rotationEnabled: z.boolean().default(false), rotationEnabled: z.boolean().default(false),
rotationIntervalSeconds: z.number().default(2592000), rotationIntervalSeconds: z.number().nullable().optional(),
lastRotatedAt: z.date().nullable().optional() lastRotatedAt: z.date().nullable().optional()
}); });
@@ -23,7 +23,7 @@ export const registerPamResourceEndpoints = <C extends TPamAccount>({
name: C["name"]; name: C["name"];
description?: C["description"]; description?: C["description"];
rotationEnabled: C["rotationEnabled"]; rotationEnabled: C["rotationEnabled"];
rotationIntervalSeconds: C["rotationIntervalSeconds"]; rotationIntervalSeconds?: C["rotationIntervalSeconds"];
}>; }>;
updateAccountSchema: z.ZodType<{ updateAccountSchema: z.ZodType<{
credentials?: C["credentials"]; credentials?: C["credentials"];
@@ -3798,7 +3798,7 @@ interface PamAccountCreateEvent {
name: string; name: string;
description?: string | null; description?: string | null;
rotationEnabled: boolean; rotationEnabled: boolean;
rotationIntervalSeconds: number; rotationIntervalSeconds?: number | null;
}; };
} }
@@ -3811,7 +3811,7 @@ interface PamAccountUpdateEvent {
name?: string; name?: string;
description?: string | null; description?: string | null;
rotationEnabled?: boolean; rotationEnabled?: boolean;
rotationIntervalSeconds?: number; rotationIntervalSeconds?: number | null;
}; };
} }
@@ -49,6 +49,7 @@ export const pamAccountDALFactory = (db: TDbClient) => {
const accounts = await dbClient(TableName.PamAccount) const accounts = await dbClient(TableName.PamAccount)
.innerJoin(TableName.PamResource, `${TableName.PamAccount}.resourceId`, `${TableName.PamResource}.id`) .innerJoin(TableName.PamResource, `${TableName.PamAccount}.resourceId`, `${TableName.PamResource}.id`)
.whereNotNull(`${TableName.PamResource}.encryptedRotationAccountCredentials`) .whereNotNull(`${TableName.PamResource}.encryptedRotationAccountCredentials`)
.whereNotNull(`${TableName.PamAccount}.rotationIntervalSeconds`)
.whereRaw( .whereRaw(
`COALESCE("${TableName.PamAccount}"."lastRotatedAt", "${TableName.PamAccount}"."createdAt") + "${TableName.PamAccount}"."rotationIntervalSeconds" * interval '1 second' < NOW()` `COALESCE("${TableName.PamAccount}"."lastRotatedAt", "${TableName.PamAccount}"."createdAt") + "${TableName.PamAccount}"."rotationIntervalSeconds" * interval '1 second' < NOW()`
) )
@@ -42,12 +42,12 @@ export const BaseCreatePamAccountSchema = z.object({
name: slugSchema({ field: "name" }), name: slugSchema({ field: "name" }),
description: z.string().max(512).nullable().optional(), description: z.string().max(512).nullable().optional(),
rotationEnabled: z.boolean(), rotationEnabled: z.boolean(),
rotationIntervalSeconds: z.number().min(3600) rotationIntervalSeconds: z.number().min(3600).nullable().optional()
}); });
export const BaseUpdatePamAccountSchema = z.object({ export const BaseUpdatePamAccountSchema = z.object({
name: slugSchema({ field: "name" }).optional(), name: slugSchema({ field: "name" }).optional(),
description: z.string().max(512).nullable().optional(), description: z.string().max(512).nullable().optional(),
rotationEnabled: z.boolean().optional(), rotationEnabled: z.boolean().optional(),
rotationIntervalSeconds: z.number().min(3600).optional() rotationIntervalSeconds: z.number().min(3600).nullable().optional()
}); });
@@ -14,7 +14,7 @@ export interface TBasePamAccount {
name: string; name: string;
description?: string | null; description?: string | null;
rotationEnabled: boolean; rotationEnabled: boolean;
rotationIntervalSeconds: number; rotationIntervalSeconds?: number | null;
lastRotatedAt?: string | null; lastRotatedAt?: string | null;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
@@ -6,7 +6,7 @@ import { FormControl, Select, SelectItem, Switch, Tooltip } from "@app/component
export const rotateAccountFieldsSchema = z.object({ export const rotateAccountFieldsSchema = z.object({
rotationEnabled: z.boolean(), rotationEnabled: z.boolean(),
rotationIntervalSeconds: z.number() rotationIntervalSeconds: z.number().nullable().optional()
}); });
export const RotateAccountFields = ({ export const RotateAccountFields = ({
@@ -16,7 +16,7 @@ export const RotateAccountFields = ({
}) => { }) => {
const { control, watch } = useFormContext<{ const { control, watch } = useFormContext<{
rotationEnabled: boolean; rotationEnabled: boolean;
rotationIntervalSeconds: number; rotationIntervalSeconds?: number | null;
}>(); }>();
const rotationEnabled = watch("rotationEnabled"); const rotationEnabled = watch("rotationEnabled");
@@ -62,7 +62,7 @@ export const RotateAccountFields = ({
className="mb-0" className="mb-0"
> >
<Select <Select
value={value.toString()} value={(value || 2592000).toString()}
onValueChange={(val) => onChange(parseInt(val, 10))} onValueChange={(val) => onChange(parseInt(val, 10))}
className="w-full border border-mineshaft-500 capitalize" className="w-full border border-mineshaft-500 capitalize"
position="popper" position="popper"