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

View File

@@ -10,7 +10,7 @@ export async function up(knex: Knex): Promise<void> {
) {
await knex.schema.alterTable(TableName.PamAccount, (t) => {
t.boolean("rotationEnabled").notNullable().defaultTo(false);
t.integer("rotationIntervalSeconds").notNullable();
t.integer("rotationIntervalSeconds").nullable();
t.timestamp("lastRotatedAt").nullable();
});
}

View File

@@ -20,7 +20,7 @@ export const PamAccountsSchema = z.object({
createdAt: z.date(),
updatedAt: z.date(),
rotationEnabled: z.boolean().default(false),
rotationIntervalSeconds: z.number().default(2592000),
rotationIntervalSeconds: z.number().nullable().optional(),
lastRotatedAt: z.date().nullable().optional()
});

View File

@@ -23,7 +23,7 @@ export const registerPamResourceEndpoints = <C extends TPamAccount>({
name: C["name"];
description?: C["description"];
rotationEnabled: C["rotationEnabled"];
rotationIntervalSeconds: C["rotationIntervalSeconds"];
rotationIntervalSeconds?: C["rotationIntervalSeconds"];
}>;
updateAccountSchema: z.ZodType<{
credentials?: C["credentials"];

View File

@@ -3798,7 +3798,7 @@ interface PamAccountCreateEvent {
name: string;
description?: string | null;
rotationEnabled: boolean;
rotationIntervalSeconds: number;
rotationIntervalSeconds?: number | null;
};
}
@@ -3811,7 +3811,7 @@ interface PamAccountUpdateEvent {
name?: string;
description?: string | null;
rotationEnabled?: boolean;
rotationIntervalSeconds?: number;
rotationIntervalSeconds?: number | null;
};
}

View File

@@ -49,6 +49,7 @@ export const pamAccountDALFactory = (db: TDbClient) => {
const accounts = await dbClient(TableName.PamAccount)
.innerJoin(TableName.PamResource, `${TableName.PamAccount}.resourceId`, `${TableName.PamResource}.id`)
.whereNotNull(`${TableName.PamResource}.encryptedRotationAccountCredentials`)
.whereNotNull(`${TableName.PamAccount}.rotationIntervalSeconds`)
.whereRaw(
`COALESCE("${TableName.PamAccount}"."lastRotatedAt", "${TableName.PamAccount}"."createdAt") + "${TableName.PamAccount}"."rotationIntervalSeconds" * interval '1 second' < NOW()`
)

View File

@@ -42,12 +42,12 @@ export const BaseCreatePamAccountSchema = z.object({
name: slugSchema({ field: "name" }),
description: z.string().max(512).nullable().optional(),
rotationEnabled: z.boolean(),
rotationIntervalSeconds: z.number().min(3600)
rotationIntervalSeconds: z.number().min(3600).nullable().optional()
});
export const BaseUpdatePamAccountSchema = z.object({
name: slugSchema({ field: "name" }).optional(),
description: z.string().max(512).nullable().optional(),
rotationEnabled: z.boolean().optional(),
rotationIntervalSeconds: z.number().min(3600).optional()
rotationIntervalSeconds: z.number().min(3600).nullable().optional()
});

View File

@@ -14,7 +14,7 @@ export interface TBasePamAccount {
name: string;
description?: string | null;
rotationEnabled: boolean;
rotationIntervalSeconds: number;
rotationIntervalSeconds?: number | null;
lastRotatedAt?: string | null;
createdAt: string;
updatedAt: string;

View File

@@ -6,7 +6,7 @@ import { FormControl, Select, SelectItem, Switch, Tooltip } from "@app/component
export const rotateAccountFieldsSchema = z.object({
rotationEnabled: z.boolean(),
rotationIntervalSeconds: z.number()
rotationIntervalSeconds: z.number().nullable().optional()
});
export const RotateAccountFields = ({
@@ -16,7 +16,7 @@ export const RotateAccountFields = ({
}) => {
const { control, watch } = useFormContext<{
rotationEnabled: boolean;
rotationIntervalSeconds: number;
rotationIntervalSeconds?: number | null;
}>();
const rotationEnabled = watch("rotationEnabled");
@@ -62,7 +62,7 @@ export const RotateAccountFields = ({
className="mb-0"
>
<Select
value={value.toString()}
value={(value || 2592000).toString()}
onValueChange={(val) => onChange(parseInt(val, 10))}
className="w-full border border-mineshaft-500 capitalize"
position="popper"