mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 19:26:38 +00:00
misc: added transaction for cert template create and update
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { TableName } from "@app/db/schemas";
|
import { TableName } from "@app/db/schemas";
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
import { DatabaseError } from "@app/lib/errors";
|
||||||
@@ -30,10 +32,9 @@ export const certificateTemplateDALFactory = (db: TDbClient) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getById = async (id: string) => {
|
const getById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const certTemplate = await db
|
const certTemplate = await (tx || db.replicaNode())(TableName.CertificateTemplate)
|
||||||
.replicaNode()(TableName.CertificateTemplate)
|
|
||||||
.join(
|
.join(
|
||||||
TableName.CertificateAuthority,
|
TableName.CertificateAuthority,
|
||||||
`${TableName.CertificateAuthority}.id`,
|
`${TableName.CertificateAuthority}.id`,
|
||||||
|
|||||||
@@ -75,23 +75,28 @@ export const certificateTemplateServiceFactory = ({
|
|||||||
ProjectPermissionSub.CertificateTemplates
|
ProjectPermissionSub.CertificateTemplates
|
||||||
);
|
);
|
||||||
|
|
||||||
const { id } = await certificateTemplateDAL.create({
|
return certificateTemplateDAL.transaction(async (tx) => {
|
||||||
caId,
|
const { id } = await certificateTemplateDAL.create(
|
||||||
pkiCollectionId,
|
{
|
||||||
name,
|
caId,
|
||||||
commonName,
|
pkiCollectionId,
|
||||||
subjectAlternativeName,
|
name,
|
||||||
ttl
|
commonName,
|
||||||
|
subjectAlternativeName,
|
||||||
|
ttl
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
|
||||||
|
const certificateTemplate = await certificateTemplateDAL.getById(id, tx);
|
||||||
|
if (!certificateTemplate) {
|
||||||
|
throw new NotFoundError({
|
||||||
|
message: "Certificate template not found"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return certificateTemplate;
|
||||||
});
|
});
|
||||||
|
|
||||||
const certificateTemplate = await certificateTemplateDAL.getById(id);
|
|
||||||
if (!certificateTemplate) {
|
|
||||||
throw new NotFoundError({
|
|
||||||
message: "Certificate template not found"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return certificateTemplate;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateCertTemplate = async ({
|
const updateCertTemplate = async ({
|
||||||
@@ -136,23 +141,29 @@ export const certificateTemplateServiceFactory = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await certificateTemplateDAL.updateById(certTemplate.id, {
|
return certificateTemplateDAL.transaction(async (tx) => {
|
||||||
caId,
|
await certificateTemplateDAL.updateById(
|
||||||
pkiCollectionId,
|
certTemplate.id,
|
||||||
commonName,
|
{
|
||||||
subjectAlternativeName,
|
caId,
|
||||||
name,
|
pkiCollectionId,
|
||||||
ttl
|
commonName,
|
||||||
|
subjectAlternativeName,
|
||||||
|
name,
|
||||||
|
ttl
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
|
||||||
|
const updatedTemplate = await certificateTemplateDAL.getById(id, tx);
|
||||||
|
if (!updatedTemplate) {
|
||||||
|
throw new NotFoundError({
|
||||||
|
message: "Certificate template not found"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return updatedTemplate;
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedTemplate = await certificateTemplateDAL.getById(id);
|
|
||||||
if (!updatedTemplate) {
|
|
||||||
throw new NotFoundError({
|
|
||||||
message: "Certificate template not found"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return updatedTemplate;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteCertTemplate = async ({ id, actorId, actorAuthMethod, actor, actorOrgId }: TDeleteCertTemplateDTO) => {
|
const deleteCertTemplate = async ({ id, actorId, actorAuthMethod, actor, actorOrgId }: TDeleteCertTemplateDTO) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user