mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 19:26:38 +00:00
Handle processing status for order sync
This commit is contained in:
@@ -26,12 +26,13 @@ export const pkiAcmeOrderDALFactory = (db: TDbClient) => {
|
|||||||
.leftJoin(
|
.leftJoin(
|
||||||
TableName.CertificateRequests,
|
TableName.CertificateRequests,
|
||||||
`${TableName.PkiAcmeOrder}.id`,
|
`${TableName.PkiAcmeOrder}.id`,
|
||||||
`${TableName.CertificateRequests}.certificateId`
|
`${TableName.CertificateRequests}.acmeOrderId`
|
||||||
)
|
)
|
||||||
.select(
|
.select(
|
||||||
selectAllTableCols(TableName.PkiAcmeOrder),
|
selectAllTableCols(TableName.PkiAcmeOrder),
|
||||||
db.ref("id").withSchema(TableName.CertificateRequests).as("certificateRequestId"),
|
db.ref("id").withSchema(TableName.CertificateRequests).as("certificateRequestId"),
|
||||||
db.ref("status").withSchema(TableName.CertificateRequests).as("certificateRequestStatus")
|
db.ref("status").withSchema(TableName.CertificateRequests).as("certificateRequestStatus"),
|
||||||
|
db.ref("certificateId").withSchema(TableName.CertificateRequests).as("certificateId")
|
||||||
)
|
)
|
||||||
.forUpdate(TableName.PkiAcmeOrder)
|
.forUpdate(TableName.PkiAcmeOrder)
|
||||||
.where(`${TableName.PkiAcmeOrder}.id`, id)
|
.where(`${TableName.PkiAcmeOrder}.id`, id)
|
||||||
@@ -39,15 +40,15 @@ export const pkiAcmeOrderDALFactory = (db: TDbClient) => {
|
|||||||
if (!order) {
|
if (!order) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
const { certificateRequestId, certificateRequestStatus, certificateId, ...details } = order;
|
||||||
return {
|
return {
|
||||||
...order,
|
...details,
|
||||||
certificateRequest:
|
certificateRequest:
|
||||||
order.certificateRequestId && order.certificateRequestStatus
|
certificateRequestId && certificateRequestStatus && certificateId
|
||||||
? {
|
? {
|
||||||
id: order.certificateRequestId,
|
id: certificateRequestId,
|
||||||
status: order.certificateRequestStatus as CertificateRequestStatus,
|
status: certificateRequestStatus as CertificateRequestStatus,
|
||||||
// The certificate id for async certificate request is the same as the order id
|
certificateId
|
||||||
certificateId: order.id
|
|
||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -378,7 +378,8 @@ export const pkiAcmeServiceFactory = ({
|
|||||||
if (!order) {
|
if (!order) {
|
||||||
throw new NotFoundError({ message: "ACME order not found" });
|
throw new NotFoundError({ message: "ACME order not found" });
|
||||||
}
|
}
|
||||||
if (order.status !== AcmeOrderStatus.Ready) {
|
if (order.status !== AcmeOrderStatus.Processing) {
|
||||||
|
// We only care about processing orders, as they are the ones that have async certificate requests
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
return acmeOrderDAL.transaction(async (tx) => {
|
return acmeOrderDAL.transaction(async (tx) => {
|
||||||
@@ -387,8 +388,9 @@ export const pkiAcmeServiceFactory = ({
|
|||||||
if (!orderWithCertificateRequest) {
|
if (!orderWithCertificateRequest) {
|
||||||
throw new NotFoundError({ message: "ACME order not found" });
|
throw new NotFoundError({ message: "ACME order not found" });
|
||||||
}
|
}
|
||||||
|
// Check the status again after we have acquired the lock, as things may have changed since we last checked
|
||||||
if (
|
if (
|
||||||
orderWithCertificateRequest.status !== AcmeOrderStatus.Ready ||
|
orderWithCertificateRequest.status !== AcmeOrderStatus.Processing ||
|
||||||
!orderWithCertificateRequest.certificateRequest
|
!orderWithCertificateRequest.certificateRequest
|
||||||
) {
|
) {
|
||||||
return orderWithCertificateRequest;
|
return orderWithCertificateRequest;
|
||||||
@@ -896,6 +898,7 @@ export const pkiAcmeServiceFactory = ({
|
|||||||
notBefore: updatedCertificateRequest.notBefore,
|
notBefore: updatedCertificateRequest.notBefore,
|
||||||
notAfter: updatedCertificateRequest.notAfter,
|
notAfter: updatedCertificateRequest.notAfter,
|
||||||
status: CertificateRequestStatus.PENDING,
|
status: CertificateRequestStatus.PENDING,
|
||||||
|
acmeOrderId: orderId,
|
||||||
tx
|
tx
|
||||||
});
|
});
|
||||||
const csrObj = new x509.Pkcs10CertificateRequest(csr);
|
const csrObj = new x509.Pkcs10CertificateRequest(csr);
|
||||||
|
|||||||
@@ -2332,6 +2332,8 @@ export const registerRoutes = async (
|
|||||||
licenseService,
|
licenseService,
|
||||||
certificateV3Service,
|
certificateV3Service,
|
||||||
certificateTemplateV2Service,
|
certificateTemplateV2Service,
|
||||||
|
certificateRequestService,
|
||||||
|
certificateIssuanceQueue,
|
||||||
acmeChallengeService,
|
acmeChallengeService,
|
||||||
pkiAcmeQueueService,
|
pkiAcmeQueueService,
|
||||||
auditLogService
|
auditLogService
|
||||||
|
|||||||
Reference in New Issue
Block a user