Skip to content

Commit 8584011

Browse files
committed
s/txWithCtx/tx/g
1 parent d0d0280 commit 8584011

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed

db/transaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package db
33
import "context"
44

55
// txFunc represents a function that does work in the context of a transaction.
6-
type txFunc func(txWithCtx Executor) (interface{}, error)
6+
type txFunc func(tx Executor) (interface{}, error)
77

88
// WithTransaction runs the given function in a transaction, rolling back if it
99
// returns an error and committing if not. The provided context is also attached

sa/model.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ const regFields = "id, jwk, jwk_sha256, contact, agreement, initialIP, createdAt
6565
// there are multiple email addresses present, it does not modify other ones. If the email
6666
// address is not present, it does not modify the registration and will return a nil error.
6767
func ClearEmail(ctx context.Context, dbMap db.DatabaseMap, regID int64, email string) error {
68-
_, overallError := db.WithTransaction(ctx, dbMap, func(txWithCtx db.Executor) (interface{}, error) {
69-
curr, err := selectRegistration(ctx, txWithCtx, "id", regID)
68+
_, overallError := db.WithTransaction(ctx, dbMap, func(tx db.Executor) (interface{}, error) {
69+
curr, err := selectRegistration(ctx, tx, "id", regID)
7070
if err != nil {
7171
return nil, err
7272
}
@@ -94,7 +94,7 @@ func ClearEmail(ctx context.Context, dbMap db.DatabaseMap, regID int64, email st
9494
return nil, err
9595
}
9696

97-
return txWithCtx.Update(ctx, newModel)
97+
return tx.Update(ctx, newModel)
9898
})
9999
if overallError != nil {
100100
return overallError

sa/sa.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,20 @@ func (ssa *SQLStorageAuthority) AddPrecertificate(ctx context.Context, req *sapb
222222
Expires: parsed.NotAfter,
223223
}
224224

225-
_, overallError := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
225+
_, overallError := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
226226
// Select to see if precert exists
227227
var row struct {
228228
Count int64
229229
}
230-
err := txWithCtx.SelectOne(ctx, &row, "SELECT COUNT(*) as count FROM precertificates WHERE serial=?", serialHex)
230+
err := tx.SelectOne(ctx, &row, "SELECT COUNT(*) as count FROM precertificates WHERE serial=?", serialHex)
231231
if err != nil {
232232
return nil, err
233233
}
234234
if row.Count > 0 {
235235
return nil, berrors.DuplicateError("cannot add a duplicate cert")
236236
}
237237

238-
err = txWithCtx.Insert(ctx, preCertModel)
238+
err = tx.Insert(ctx, preCertModel)
239239
if err != nil {
240240
return nil, err
241241
}
@@ -268,18 +268,18 @@ func (ssa *SQLStorageAuthority) AddPrecertificate(ctx context.Context, req *sapb
268268
// not for the purpose of rate limiting is the least of our troubles.
269269
isRenewal, err := ssa.checkFQDNSetExists(
270270
ctx,
271-
txWithCtx.SelectOne,
271+
tx.SelectOne,
272272
parsed.DNSNames)
273273
if err != nil {
274274
return nil, err
275275
}
276276

277-
err = addIssuedNames(ctx, txWithCtx, parsed, isRenewal)
277+
err = addIssuedNames(ctx, tx, parsed, isRenewal)
278278
if err != nil {
279279
return nil, err
280280
}
281281

282-
err = addKeyHash(ctx, txWithCtx, parsed)
282+
err = addKeyHash(ctx, tx, parsed)
283283
if err != nil {
284284
return nil, err
285285
}
@@ -315,12 +315,12 @@ func (ssa *SQLStorageAuthority) AddCertificate(ctx context.Context, req *sapb.Ad
315315
Expires: parsedCertificate.NotAfter,
316316
}
317317

318-
isRenewalRaw, overallError := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
318+
isRenewalRaw, overallError := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
319319
// Select to see if cert exists
320320
var row struct {
321321
Count int64
322322
}
323-
err := txWithCtx.SelectOne(ctx, &row, "SELECT COUNT(*) as count FROM certificates WHERE serial=?", serial)
323+
err := tx.SelectOne(ctx, &row, "SELECT COUNT(*) as count FROM certificates WHERE serial=?", serial)
324324
if err != nil {
325325
return nil, err
326326
}
@@ -329,7 +329,7 @@ func (ssa *SQLStorageAuthority) AddCertificate(ctx context.Context, req *sapb.Ad
329329
}
330330

331331
// Save the final certificate
332-
err = txWithCtx.Insert(ctx, cert)
332+
err = tx.Insert(ctx, cert)
333333
if err != nil {
334334
return nil, err
335335
}
@@ -342,7 +342,7 @@ func (ssa *SQLStorageAuthority) AddCertificate(ctx context.Context, req *sapb.Ad
342342
// not for the purpose of rate limiting is the least of our troubles.
343343
isRenewal, err := ssa.checkFQDNSetExists(
344344
ctx,
345-
txWithCtx.SelectOne,
345+
tx.SelectOne,
346346
parsedCertificate.DNSNames)
347347
if err != nil {
348348
return nil, err
@@ -369,12 +369,12 @@ func (ssa *SQLStorageAuthority) AddCertificate(ctx context.Context, req *sapb.Ad
369369
// for rate limits. Since the effects of failing these writes is slight
370370
// miscalculation of rate limits we choose to not fail the AddCertificate
371371
// operation if the rate limit update transaction fails.
372-
_, rlTransactionErr := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
372+
_, rlTransactionErr := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
373373
// Add to the rate limit table, but only for new certificates. Renewals
374374
// don't count against the certificatesPerName limit.
375375
if !isRenewal {
376376
timeToTheHour := parsedCertificate.NotBefore.Round(time.Hour)
377-
err := ssa.addCertificatesPerName(ctx, txWithCtx, parsedCertificate.DNSNames, timeToTheHour)
377+
err := ssa.addCertificatesPerName(ctx, tx, parsedCertificate.DNSNames, timeToTheHour)
378378
if err != nil {
379379
return nil, err
380380
}
@@ -384,7 +384,7 @@ func (ssa *SQLStorageAuthority) AddCertificate(ctx context.Context, req *sapb.Ad
384384
// limits are calculated correctly.
385385
err = addFQDNSet(
386386
ctx,
387-
txWithCtx,
387+
tx,
388388
parsedCertificate.DNSNames,
389389
core.SerialToString(parsedCertificate.SerialNumber),
390390
parsedCertificate.NotBefore,
@@ -454,7 +454,7 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
454454
return nil, errIncompleteRequest
455455
}
456456

457-
output, err := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
457+
output, err := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
458458
// First, insert all of the new authorizations and record their IDs.
459459
newAuthzIDs := make([]int64, 0)
460460
if len(req.NewAuthzs) != 0 {
@@ -488,7 +488,7 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
488488
return nil, err
489489
}
490490
}
491-
newAuthzIDs, err = inserter.Insert(ctx, txWithCtx)
491+
newAuthzIDs, err = inserter.Insert(ctx, tx)
492492
if err != nil {
493493
return nil, err
494494
}
@@ -500,7 +500,7 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
500500
Expires: time.Unix(0, req.NewOrder.Expires),
501501
Created: ssa.clk.Now(),
502502
}
503-
err := txWithCtx.Insert(ctx, order)
503+
err := tx.Insert(ctx, order)
504504
if err != nil {
505505
return nil, err
506506
}
@@ -522,7 +522,7 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
522522
return nil, err
523523
}
524524
}
525-
_, err = inserter.Insert(ctx, txWithCtx)
525+
_, err = inserter.Insert(ctx, tx)
526526
if err != nil {
527527
return nil, err
528528
}
@@ -538,13 +538,13 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
538538
return nil, err
539539
}
540540
}
541-
_, err = inserter.Insert(ctx, txWithCtx)
541+
_, err = inserter.Insert(ctx, tx)
542542
if err != nil {
543543
return nil, err
544544
}
545545

546546
// Fifth, insert the FQDNSet entry for the order.
547-
err = addOrderFQDNSet(ctx, txWithCtx, req.NewOrder.Names, order.ID, order.RegistrationID, order.Expires)
547+
err = addOrderFQDNSet(ctx, tx, req.NewOrder.Names, order.ID, order.RegistrationID, order.Expires)
548548
if err != nil {
549549
return nil, err
550550
}
@@ -566,7 +566,7 @@ func (ssa *SQLStorageAuthority) NewOrderAndAuthzs(ctx context.Context, req *sapb
566566

567567
// Calculate the order status before returning it. Since it may have reused
568568
// all valid authorizations the order may be "born" in a ready status.
569-
status, err := statusForOrder(ctx, txWithCtx, res, ssa.clk.Now())
569+
status, err := statusForOrder(ctx, tx, res, ssa.clk.Now())
570570
if err != nil {
571571
return nil, err
572572
}
@@ -599,8 +599,8 @@ func (ssa *SQLStorageAuthority) SetOrderProcessing(ctx context.Context, req *sap
599599
if req.Id == 0 {
600600
return nil, errIncompleteRequest
601601
}
602-
_, overallError := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
603-
result, err := txWithCtx.ExecContext(ctx, `
602+
_, overallError := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
603+
result, err := tx.ExecContext(ctx, `
604604
UPDATE orders
605605
SET beganProcessing = ?
606606
WHERE id = ?
@@ -630,7 +630,7 @@ func (ssa *SQLStorageAuthority) SetOrderError(ctx context.Context, req *sapb.Set
630630
if req.Id == 0 || req.Error == nil {
631631
return nil, errIncompleteRequest
632632
}
633-
_, overallError := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
633+
_, overallError := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
634634
om, err := orderToModel(&corepb.Order{
635635
Id: req.Id,
636636
Error: req.Error,
@@ -639,7 +639,7 @@ func (ssa *SQLStorageAuthority) SetOrderError(ctx context.Context, req *sapb.Set
639639
return nil, err
640640
}
641641

642-
result, err := txWithCtx.ExecContext(ctx, `
642+
result, err := tx.ExecContext(ctx, `
643643
UPDATE orders
644644
SET error = ?
645645
WHERE id = ?`,
@@ -670,8 +670,8 @@ func (ssa *SQLStorageAuthority) FinalizeOrder(ctx context.Context, req *sapb.Fin
670670
if req.Id == 0 || req.CertificateSerial == "" {
671671
return nil, errIncompleteRequest
672672
}
673-
_, overallError := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
674-
result, err := txWithCtx.ExecContext(ctx, `
673+
_, overallError := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
674+
result, err := tx.ExecContext(ctx, `
675675
UPDATE orders
676676
SET certificateSerial = ?
677677
WHERE id = ? AND
@@ -689,7 +689,7 @@ func (ssa *SQLStorageAuthority) FinalizeOrder(ctx context.Context, req *sapb.Fin
689689

690690
// Delete the orderFQDNSet row for the order now that it has been finalized.
691691
// We use this table for order reuse and should not reuse a finalized order.
692-
err = deleteOrderFQDNSet(ctx, txWithCtx, req.Id)
692+
err = deleteOrderFQDNSet(ctx, tx, req.Id)
693693
if err != nil {
694694
return nil, err
695695
}
@@ -942,9 +942,9 @@ func (ssa *SQLStorageAuthority) LeaseCRLShard(ctx context.Context, req *sapb.Lea
942942
// leased or are previously-unknown indices are considered older than any other
943943
// shard. It returns an error if all shards for the issuer are already leased.
944944
func (ssa *SQLStorageAuthority) leaseOldestCRLShard(ctx context.Context, req *sapb.LeaseCRLShardRequest) (*sapb.LeaseCRLShardResponse, error) {
945-
shardIdx, err := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
945+
shardIdx, err := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
946946
var shards []*crlShardModel
947-
_, err := txWithCtx.Select(
947+
_, err := tx.Select(
948948
ctx,
949949
&shards,
950950
`SELECT id, issuerID, idx, thisUpdate, nextUpdate, leasedUntil
@@ -993,15 +993,15 @@ func (ssa *SQLStorageAuthority) leaseOldestCRLShard(ctx context.Context, req *sa
993993
}
994994

995995
if needToInsert {
996-
_, err = txWithCtx.ExecContext(ctx,
996+
_, err = tx.ExecContext(ctx,
997997
`INSERT INTO crlShards (issuerID, idx, leasedUntil)
998998
VALUES (?, ?, ?)`,
999999
req.IssuerNameID,
10001000
shardIdx,
10011001
req.Until.AsTime(),
10021002
)
10031003
} else {
1004-
_, err = txWithCtx.ExecContext(ctx,
1004+
_, err = tx.ExecContext(ctx,
10051005
`UPDATE crlShards
10061006
SET leasedUntil = ?
10071007
WHERE issuerID = ?
@@ -1036,8 +1036,8 @@ func (ssa *SQLStorageAuthority) leaseSpecificCRLShard(ctx context.Context, req *
10361036
return nil, fmt.Errorf("request must identify a single shard index: %d != %d", req.MinShardIdx, req.MaxShardIdx)
10371037
}
10381038

1039-
_, err := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
1040-
res, err := txWithCtx.ExecContext(ctx,
1039+
_, err := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
1040+
res, err := tx.ExecContext(ctx,
10411041
`UPDATE crlShards
10421042
SET leasedUntil = ?
10431043
WHERE issuerID = ?
@@ -1088,8 +1088,8 @@ func (ssa *SQLStorageAuthority) UpdateCRLShard(ctx context.Context, req *sapb.Up
10881088
return nil, errIncompleteRequest
10891089
}
10901090

1091-
_, err := db.WithTransaction(ctx, ssa.dbMap, func(txWithCtx db.Executor) (interface{}, error) {
1092-
res, err := txWithCtx.ExecContext(ctx,
1091+
_, err := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
1092+
res, err := tx.ExecContext(ctx,
10931093
`UPDATE crlShards
10941094
SET thisUpdate = ?, nextUpdate = ?
10951095
WHERE issuerID = ?

sa/saro.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@ func (ssa *SQLStorageAuthorityRO) GetOrder(ctx context.Context, req *sapb.OrderR
666666
return nil, errIncompleteRequest
667667
}
668668

669-
txn := func(txWithCtx db.Executor) (interface{}, error) {
670-
omObj, err := txWithCtx.Get(ctx, orderModel{}, req.Id)
669+
txn := func(tx db.Executor) (interface{}, error) {
670+
omObj, err := tx.Get(ctx, orderModel{}, req.Id)
671671
if err != nil {
672672
if db.IsNoRows(err) {
673673
return nil, berrors.NotFoundError("no order found for ID %d", req.Id)
@@ -688,13 +688,13 @@ func (ssa *SQLStorageAuthorityRO) GetOrder(ctx context.Context, req *sapb.OrderR
688688
return nil, berrors.NotFoundError("no order found for ID %d", req.Id)
689689
}
690690

691-
v2AuthzIDs, err := authzForOrder(ctx, txWithCtx, order.Id)
691+
v2AuthzIDs, err := authzForOrder(ctx, tx, order.Id)
692692
if err != nil {
693693
return nil, err
694694
}
695695
order.V2Authorizations = v2AuthzIDs
696696

697-
names, err := namesForOrder(ctx, txWithCtx, order.Id)
697+
names, err := namesForOrder(ctx, tx, order.Id)
698698
if err != nil {
699699
return nil, err
700700
}
@@ -708,7 +708,7 @@ func (ssa *SQLStorageAuthorityRO) GetOrder(ctx context.Context, req *sapb.OrderR
708708
order.Names = reversedNames
709709

710710
// Calculate the status for the order
711-
status, err := statusForOrder(ctx, txWithCtx, order, ssa.clk.Now())
711+
status, err := statusForOrder(ctx, tx, order, ssa.clk.Now())
712712
if err != nil {
713713
return nil, err
714714
}

0 commit comments

Comments
 (0)