Skip to content

Commit b0bcbb1

Browse files
authored
SA: Create list of authzIDs earlier in NewOrderAndAuthzs (#7744)
Creating the list of authzIDs earlier in NewOrderAndAuthzs: - Saves a `for` loop with duplicated code; we no longer need to range over two different slices, just one. - Allows us to create the Order PB later, after more of the data collection logic, without interrupting it. This makes the order of operations slightly easier to follow.
1 parent 37b85fb commit b0bcbb1

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

sa/sa.go

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -549,17 +549,13 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
549549
}
550550

551551
// Third, insert all of the orderToAuthz relations.
552+
// Have to combine the already-associated and newly-created authzs.
553+
allAuthzIds := append(req.NewOrder.V2Authorizations, newAuthzIDs...)
552554
inserter, err := db.NewMultiInserter("orderToAuthz2", []string{"orderID", "authzID"}, "")
553555
if err != nil {
554556
return nil, err
555557
}
556-
for _, id := range req.NewOrder.V2Authorizations {
557-
err := inserter.Add([]interface{}{orderID, id})
558-
if err != nil {
559-
return nil, err
560-
}
561-
}
562-
for _, id := range newAuthzIDs {
558+
for _, id := range allAuthzIds {
563559
err := inserter.Add([]interface{}{orderID, id})
564560
if err != nil {
565561
return nil, err
@@ -576,6 +572,22 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
576572
return nil, err
577573
}
578574

575+
if req.NewOrder.ReplacesSerial != "" {
576+
// Update the replacementOrders table to indicate that this order
577+
// replaces the provided certificate serial.
578+
err := addReplacementOrder(ctx, tx, req.NewOrder.ReplacesSerial, orderID, req.NewOrder.Expires.AsTime())
579+
if err != nil {
580+
return nil, err
581+
}
582+
}
583+
584+
// Get the partial Authorization objects for the order
585+
authzValidityInfo, err := getAuthorizationStatuses(ctx, tx, allAuthzIds)
586+
// If there was an error getting the authorizations, return it immediately
587+
if err != nil {
588+
return nil, err
589+
}
590+
579591
// Finally, build the overall Order PB.
580592
res := &corepb.Order{
581593
// ID and Created were auto-populated on the order model when it was inserted.
@@ -585,8 +597,8 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
585597
RegistrationID: req.NewOrder.RegistrationID,
586598
Expires: req.NewOrder.Expires,
587599
DnsNames: req.NewOrder.DnsNames,
588-
// Have to combine the already-associated and newly-reacted authzs.
589-
V2Authorizations: append(req.NewOrder.V2Authorizations, newAuthzIDs...),
600+
// This includes both reused and newly created authz IDs.
601+
V2Authorizations: allAuthzIds,
590602
// A new order is never processing because it can't be finalized yet.
591603
BeganProcessing: false,
592604
// An empty string is allowed. When the RA retrieves the order and
@@ -595,22 +607,6 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
595607
CertificateProfileName: req.NewOrder.CertificateProfileName,
596608
}
597609

598-
if req.NewOrder.ReplacesSerial != "" {
599-
// Update the replacementOrders table to indicate that this order
600-
// replaces the provided certificate serial.
601-
err := addReplacementOrder(ctx, tx, req.NewOrder.ReplacesSerial, orderID, req.NewOrder.Expires.AsTime())
602-
if err != nil {
603-
return nil, err
604-
}
605-
}
606-
607-
// Get the partial Authorization objects for the order
608-
authzValidityInfo, err := getAuthorizationStatuses(ctx, tx, res.V2Authorizations)
609-
// If there was an error getting the authorizations, return it immediately
610-
if err != nil {
611-
return nil, err
612-
}
613-
614610
// Calculate the order status before returning it. Since it may have reused
615611
// all valid authorizations the order may be "born" in a ready status.
616612
status, err := statusForOrder(res, authzValidityInfo, ssa.clk.Now())

0 commit comments

Comments
 (0)