Skip to content

Commit a626fe3

Browse files
committed
Plumb through more context in cert-checker
1 parent 8584011 commit a626fe3

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

cmd/cert-checker/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func newChecker(saDbMap certDB,
125125
}
126126
}
127127

128-
func (c *certChecker) getCerts(unexpiredOnly bool) error {
128+
func (c *certChecker) getCerts(ctx context.Context, unexpiredOnly bool) error {
129129
c.issuedReport.end = c.clock.Now()
130130
c.issuedReport.begin = c.issuedReport.end.Add(-c.checkPeriod)
131131

@@ -139,7 +139,7 @@ func (c *certChecker) getCerts(unexpiredOnly bool) error {
139139
var retries int
140140
for {
141141
sni, err = c.dbMap.SelectNullInt(
142-
context.Background(),
142+
ctx,
143143
"SELECT MIN(id) FROM certificates WHERE issued >= :issued AND expires >= :now",
144144
args,
145145
)
@@ -171,7 +171,7 @@ func (c *certChecker) getCerts(unexpiredOnly bool) error {
171171

172172
for {
173173
certs, err := sa.SelectCertificates(
174-
context.Background(),
174+
ctx,
175175
c.dbMap,
176176
"WHERE id > :id AND issued >= :issued AND expires >= :now ORDER BY id LIMIT :limit",
177177
args,
@@ -201,9 +201,9 @@ func (c *certChecker) getCerts(unexpiredOnly bool) error {
201201
return nil
202202
}
203203

204-
func (c *certChecker) processCerts(wg *sync.WaitGroup, badResultsOnly bool, ignoredLints map[string]bool) {
204+
func (c *certChecker) processCerts(ctx context.Context, wg *sync.WaitGroup, badResultsOnly bool, ignoredLints map[string]bool) {
205205
for cert := range c.certs {
206-
dnsNames, problems := c.checkCert(context.Background(), cert, ignoredLints)
206+
dnsNames, problems := c.checkCert(ctx, cert, ignoredLints)
207207
valid := len(problems) == 0
208208
c.rMu.Lock()
209209
if !badResultsOnly || (badResultsOnly && !valid) {
@@ -388,7 +388,7 @@ func (c *certChecker) checkCert(ctx context.Context, cert core.Certificate, igno
388388
if err != nil {
389389
problems = append(problems, fmt.Sprintf("Couldn't parse stored certificate: %s", err))
390390
}
391-
err = c.kp.GoodKey(context.Background(), p.PublicKey)
391+
err = c.kp.GoodKey(ctx, p.PublicKey)
392392
if err != nil {
393393
problems = append(problems, fmt.Sprintf("Key Policy isn't willing to issue for public key: %s", err))
394394
}
@@ -533,7 +533,7 @@ func main() {
533533
// is finished it will close the certificate channel which allows the range
534534
// loops in checker.processCerts to break
535535
go func() {
536-
err := checker.getCerts(config.CertChecker.UnexpiredOnly)
536+
err := checker.getCerts(context.TODO(), config.CertChecker.UnexpiredOnly)
537537
cmd.FailOnError(err, "Batch retrieval of certificates failed")
538538
}()
539539

@@ -543,7 +543,7 @@ func main() {
543543
wg.Add(1)
544544
go func() {
545545
s := checker.clock.Now()
546-
checker.processCerts(wg, config.CertChecker.BadResultsOnly, ignoredLintsMap)
546+
checker.processCerts(context.TODO(), wg, config.CertChecker.BadResultsOnly, ignoredLintsMap)
547547
checkerLatency.Observe(checker.clock.Since(s).Seconds())
548548
}()
549549
}

cmd/cert-checker/main_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ func TestGetAndProcessCerts(t *testing.T) {
365365
}
366366

367367
batchSize = 2
368-
err = checker.getCerts(false)
368+
err = checker.getCerts(context.Background(), false)
369369
test.AssertNotError(t, err, "Failed to retrieve certificates")
370370
test.AssertEquals(t, len(checker.certs), 5)
371371
wg := new(sync.WaitGroup)
372372
wg.Add(1)
373-
checker.processCerts(wg, false, nil)
373+
checker.processCerts(context.Background(), wg, false, nil)
374374
test.AssertEquals(t, checker.issuedReport.BadCerts, int64(5))
375375
test.AssertEquals(t, len(checker.issuedReport.Entries), 5)
376376
}
@@ -425,7 +425,7 @@ func TestGetCertsEmptyResults(t *testing.T) {
425425
checker.dbMap = mismatchedCountDB{}
426426

427427
batchSize = 3
428-
err = checker.getCerts(false)
428+
err = checker.getCerts(context.Background(), false)
429429
test.AssertNotError(t, err, "Failed to retrieve certificates")
430430
}
431431

@@ -452,7 +452,7 @@ func TestGetCertsNullResults(t *testing.T) {
452452
checker := newChecker(saDbMap, clock.NewFake(), pa, kp, time.Hour, testValidityDurations, blog.NewMock())
453453
checker.dbMap = emptyDB{}
454454

455-
err = checker.getCerts(false)
455+
err = checker.getCerts(context.Background(), false)
456456
test.AssertError(t, err, "Should have gotten error from empty DB")
457457
}
458458

0 commit comments

Comments
 (0)