mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
feat: resolved tiny bug secret blind indexing
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
|
||||
import knex from "knex"
|
||||
import knex from "knex";
|
||||
|
||||
export type TDbClient = ReturnType<typeof initDbConnection>;
|
||||
export const initDbConnection = (dbConnectionUri: string) => {
|
||||
|
||||
@@ -58,8 +58,36 @@ export const secretBlindIndexDALFactory = (db: TDbClient) => {
|
||||
}
|
||||
};
|
||||
|
||||
const findSecretsByProjectId = async (projectId: string, secretIds: string[], tx?: Knex) => {
|
||||
try {
|
||||
const docs = await (tx || db)(TableName.Secret)
|
||||
.leftJoin(
|
||||
TableName.SecretFolder,
|
||||
`${TableName.SecretFolder}.id`,
|
||||
`${TableName.Secret}.folderId`
|
||||
)
|
||||
.leftJoin(
|
||||
TableName.Environment,
|
||||
`${TableName.Environment}.id`,
|
||||
`${TableName.SecretFolder}.envId`
|
||||
)
|
||||
.where({ projectId })
|
||||
.whereIn(`${TableName.Secret}.id`, secretIds)
|
||||
.whereNull("secretBlindIndex")
|
||||
.select(selectAllTableCols(TableName.Secret))
|
||||
.select(
|
||||
db.ref("slug").withSchema(TableName.Environment).as("environment"),
|
||||
db.ref("projectId").withSchema(TableName.Environment).as("workspace")
|
||||
);
|
||||
return docs;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "CountOfSecretWillNullSecretBlindIndex" });
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
...secretBlindIndexOrm,
|
||||
findSecretsByProjectId,
|
||||
countOfSecretsWithNullSecretBlindIndex,
|
||||
findAllSecretsByProjectId
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
type TSecretBlindIndexServiceFactoryDep = {
|
||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||
secretBlindIndexDAL: TSecretBlindIndexDALFactory;
|
||||
secretDAL:Pick<TSecretDALFactory,'bulkUpdate'>;
|
||||
secretDAL: Pick<TSecretDALFactory, "bulkUpdate">;
|
||||
};
|
||||
|
||||
export type TSecretBlindIndexServiceFactory = ReturnType<typeof secretBlindIndexServiceFactory>;
|
||||
@@ -58,18 +58,28 @@ export const secretBlindIndexServiceFactory = ({
|
||||
if (membership?.role !== ProjectMembershipRole.Admin) {
|
||||
throw new UnauthorizedError({ message: "User must be admin" });
|
||||
}
|
||||
|
||||
const blindIndexCfg = await secretBlindIndexDAL.findOne({ projectId });
|
||||
if (!blindIndexCfg)
|
||||
throw new BadRequestError({ message: "Blind index not found", name: "CreateSecret" });
|
||||
|
||||
const operations = await Promise.all(secretsToUpdate.map(async ({secretName,secretId:id})=>{
|
||||
const secretBlindIndex = await generateSecretBlindIndexBySalt(secretName,blindIndexCfg);
|
||||
return { filter:{id},data:{secretBlindIndex} }
|
||||
}))
|
||||
const secrets = await secretBlindIndexDAL.findSecretsByProjectId(
|
||||
projectId,
|
||||
secretsToUpdate.map(({ secretId }) => secretId)
|
||||
);
|
||||
if (secrets.length !== secretsToUpdate.length)
|
||||
throw new BadRequestError({ message: "Secret not found" });
|
||||
|
||||
await secretBlindIndexDAL.transaction(async(tx)=>{
|
||||
await secretDAL.bulkUpdate(operations,tx)
|
||||
})
|
||||
const operations = await Promise.all(
|
||||
secretsToUpdate.map(async ({ secretName, secretId: id }) => {
|
||||
const secretBlindIndex = await generateSecretBlindIndexBySalt(secretName, blindIndexCfg);
|
||||
return { filter: { id }, data: { secretBlindIndex } };
|
||||
})
|
||||
);
|
||||
|
||||
await secretBlindIndexDAL.transaction(async (tx) => {
|
||||
await secretDAL.bulkUpdate(operations, tx);
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user