Fix linter and type issues, made a small fix for secret rotation platform events

This commit is contained in:
carlosmonastyrski
2025-03-06 09:10:13 -03:00
parent cd5b6da541
commit 30bcf1f204
9 changed files with 91 additions and 34 deletions
@@ -39,6 +39,7 @@ import {
secretRotationPreSetFn
} from "./secret-rotation-queue-fn";
import { TSecretRotationData, TSecretRotationDbFn, TSecretRotationEncData } from "./secret-rotation-queue-types";
import { ActorType } from "@app/services/auth/auth-type";
export type TSecretRotationQueueFactory = ReturnType<typeof secretRotationQueueFactory>;
@@ -332,6 +333,7 @@ export const secretRotationQueueFactory = ({
await secretVersionV2BridgeDAL.insertMany(
updatedSecrets.map(({ id, updatedAt, createdAt, ...el }) => ({
...el,
actorType: ActorType.PLATFORM,
secretId: id
})),
tx
@@ -34,6 +34,7 @@ import { TSnapshotFolderDALFactory } from "./snapshot-folder-dal";
import { TSnapshotSecretDALFactory } from "./snapshot-secret-dal";
import { TSnapshotSecretV2DALFactory } from "./snapshot-secret-v2-dal";
import { getFullFolderPath } from "./snapshot-service-fns";
import { ActorType } from "@app/services/auth/auth-type";
type TSecretSnapshotServiceFactoryDep = {
snapshotDAL: TSnapshotDALFactory;
@@ -414,8 +415,18 @@ export const secretSnapshotServiceFactory = ({
})),
tx
);
const userActorId = actor === ActorType.USER ? actorId : undefined;
const identityActorId = actor !== ActorType.USER ? actorId : undefined;
const actorType = actor || ActorType.PLATFORM;
const secretVersions = await secretVersionV2BridgeDAL.insertMany(
secrets.map(({ id, updatedAt, createdAt, ...el }) => ({ ...el, secretId: id })),
secrets.map(({ id, updatedAt, createdAt, ...el }) => ({
...el,
secretId: id,
userActorId,
identityActorId,
actorType
})),
tx
);
await secretVersionV2TagBridgeDAL.insertMany(
@@ -114,8 +114,8 @@ export const secretRawSchema = z.object({
updatedAt: z.date(),
actor: z
.object({
actorId: z.string().nullable(),
actorType: z.string().nullable(),
actorId: z.string().nullable().optional(),
actorType: z.string().nullable().optional(),
name: z.string().nullable().optional()
})
.optional()
@@ -94,6 +94,7 @@ export const fnSecretBulkInsert = async ({
const userActorId = actor && actor.type === ActorType.USER ? actor.actorId : undefined;
const identityActorId = actor && actor.type !== ActorType.USER ? actor.actorId : undefined;
const actorType = actor?.type || ActorType.PLATFORM;
const newSecrets = await secretDAL.insertMany(
sanitizedInputSecrets.map((el) => ({ ...el, folderId })),
@@ -113,7 +114,7 @@ export const fnSecretBulkInsert = async ({
folderId,
userActorId,
identityActorId,
actorType: actor?.type,
actorType,
secretId: newSecretGroupedByKeyName[el.key][0].id
})),
tx
@@ -170,6 +171,7 @@ export const fnSecretBulkUpdate = async ({
}: TFnSecretBulkUpdate) => {
const userActorId = actor && actor?.type === ActorType.USER ? actor?.actorId : undefined;
const identityActorId = actor && actor?.type !== ActorType.USER ? actor?.actorId : undefined;
const actorType = actor?.type || ActorType.PLATFORM;
const sanitizedInputSecrets = inputSecrets.map(
({
@@ -231,7 +233,7 @@ export const fnSecretBulkUpdate = async ({
secretId,
userActorId,
identityActorId,
actorType: actor?.type
actorType
})
),
tx
+18 -1
View File
@@ -525,6 +525,7 @@ export const fnSecretBulkInsert = async ({
secretVersionDAL,
secretTagDAL,
secretVersionTagDAL,
actor,
tx
}: TFnSecretBulkInsert) => {
const sanitizedInputSecrets = inputSecrets.map(
@@ -579,9 +580,17 @@ export const fnSecretBulkInsert = async ({
[`${TableName.Secret}Id` as const]: newSecretGroupByBlindIndex[secretBlindIndex as string][0].id
}))
);
const userActorId = actor && actor?.type === ActorType.USER ? actor?.actorId : undefined;
const identityActorId = actor && actor?.type !== ActorType.USER ? actor?.actorId : undefined;
const actorType = actor?.type || ActorType.PLATFORM;
const secretVersions = await secretVersionDAL.insertMany(
sanitizedInputSecrets.map((el) => ({
...el,
userActorId,
identityActorId,
actorType,
secretId: newSecretGroupByBlindIndex[el.secretBlindIndex as string][0].id
})),
tx
@@ -614,7 +623,8 @@ export const fnSecretBulkUpdate = async ({
secretDAL,
secretVersionDAL,
secretTagDAL,
secretVersionTagDAL
secretVersionTagDAL,
actor
}: TFnSecretBulkUpdate) => {
const sanitizedInputSecrets = inputSecrets.map(
({
@@ -664,10 +674,17 @@ export const fnSecretBulkUpdate = async ({
})
);
const userActorId = actor && actor?.type === ActorType.USER ? actor?.actorId : undefined;
const identityActorId = actor && actor?.type !== ActorType.USER ? actor?.actorId : undefined;
const actorType = actor?.type || ActorType.PLATFORM;
const newSecrets = await secretDAL.bulkUpdate(sanitizedInputSecrets, tx);
const secretVersions = await secretVersionDAL.insertMany(
newSecrets.map(({ id, createdAt, updatedAt, ...el }) => ({
...el,
userActorId,
identityActorId,
actorType,
secretId: id
})),
tx
+2 -2
View File
@@ -324,7 +324,7 @@ export type TFnSecretBulkInsert = {
secretVersionTagDAL: Pick<TSecretVersionTagDALFactory, "insertMany">;
actor?: {
type?: string;
actorId: string;
actorId?: string;
};
};
@@ -342,7 +342,7 @@ export type TFnSecretBulkUpdate = {
tx?: Knex;
actor?: {
type?: string;
actorId: string;
actorId?: string;
};
};