@@ -100,19 +100,20 @@ type AppHandler struct {
100
100
// does additional common error and stats processing.
101
101
func (a AppHandler ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
102
102
var statusCode int
103
- label0 := a .Info .LogOrigin
103
+ label0 := a .Info .Origin
104
104
label1 := string (a .Name )
105
105
reqsCounter .Inc (label0 , label1 )
106
106
startTime := a .Info .TimeSource .Now ()
107
107
logCtx := a .Info .RequestLog .Start (r .Context ())
108
- a .Info .RequestLog .LogOrigin (logCtx , a .Info .LogOrigin )
108
+ a .Info .RequestLog .Origin (logCtx , a .Info .Origin )
109
109
defer func () {
110
110
latency := a .Info .TimeSource .Now ().Sub (startTime ).Seconds ()
111
111
rspLatency .Observe (latency , label0 , label1 , strconv .Itoa (statusCode ))
112
112
}()
113
- klog .V (2 ).Infof ("%s: request %v %q => %s" , a .Info .LogOrigin , r .Method , r .URL , a .Name )
113
+ klog .V (2 ).Infof ("%s: request %v %q => %s" , a .Info .Origin , r .Method , r .URL , a .Name )
114
+ // TODO(phboneff): add a.Method directly on the handler path and remove this test.
114
115
if r .Method != a .Method {
115
- klog .Warningf ("%s: %s wrong HTTP method: %v" , a .Info .LogOrigin , a .Name , r .Method )
116
+ klog .Warningf ("%s: %s wrong HTTP method: %v" , a .Info .Origin , a .Name , r .Method )
116
117
a .Info .SendHTTPError (w , http .StatusMethodNotAllowed , fmt .Errorf ("method not allowed: %s" , r .Method ))
117
118
a .Info .RequestLog .Status (logCtx , http .StatusMethodNotAllowed )
118
119
return
@@ -135,17 +136,17 @@ func (a AppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
135
136
var err error
136
137
statusCode , err = a .Handler (ctx , a .Info , w , r )
137
138
a .Info .RequestLog .Status (ctx , statusCode )
138
- klog .V (2 ).Infof ("%s: %s <= st=%d" , a .Info .LogOrigin , a .Name , statusCode )
139
+ klog .V (2 ).Infof ("%s: %s <= st=%d" , a .Info .Origin , a .Name , statusCode )
139
140
rspsCounter .Inc (label0 , label1 , strconv .Itoa (statusCode ))
140
141
if err != nil {
141
- klog .Warningf ("%s: %s handler error: %v" , a .Info .LogOrigin , a .Name , err )
142
+ klog .Warningf ("%s: %s handler error: %v" , a .Info .Origin , a .Name , err )
142
143
a .Info .SendHTTPError (w , statusCode , err )
143
144
return
144
145
}
145
146
146
147
// Additional check, for consistency the handler must return an error for non-200 st
147
148
if statusCode != http .StatusOK {
148
- klog .Warningf ("%s: %s handler non 200 without error: %d %v" , a .Info .LogOrigin , a .Name , statusCode , err )
149
+ klog .Warningf ("%s: %s handler non 200 without error: %d %v" , a .Info .Origin , a .Name , statusCode , err )
149
150
a .Info .SendHTTPError (w , http .StatusInternalServerError , fmt .Errorf ("http handler misbehaved, st: %d" , statusCode ))
150
151
return
151
152
}
@@ -190,8 +191,8 @@ func NewCertValidationOpts(trustedRoots *x509util.PEMCertPool, currentTime time.
190
191
191
192
// logInfo holds information for a specific log instance.
192
193
type logInfo struct {
193
- // LogOrigin identifies the log, as per https://c2sp.org/static-ct-api
194
- LogOrigin string
194
+ // Origin identifies the log, as per https://c2sp.org/static-ct-api
195
+ Origin string
195
196
// TimeSource is a TimeSource that can be injected for testing
196
197
TimeSource TimeSource
197
198
// RequestLog is a logger for various request / processing / response debug
@@ -219,7 +220,7 @@ func newLogInfo(
219
220
cfg := instanceOpts .Validated
220
221
221
222
li := & logInfo {
222
- LogOrigin : cfg .Origin ,
223
+ Origin : cfg .Origin ,
223
224
storage : storage ,
224
225
signer : signer ,
225
226
TimeSource : timeSource ,
@@ -297,7 +298,7 @@ func addChainInternal(ctx context.Context, li *logInfo, w http.ResponseWriter, r
297
298
// Check the contents of the request and convert to slice of certificates.
298
299
addChainReq , err := ParseBodyAsJSONChain (r )
299
300
if err != nil {
300
- return http .StatusBadRequest , fmt .Errorf ("%s: failed to parse add-chain body: %s" , li .LogOrigin , err )
301
+ return http .StatusBadRequest , fmt .Errorf ("%s: failed to parse add-chain body: %s" , li .Origin , err )
301
302
}
302
303
// Log the DERs now because they might not parse as valid X.509.
303
304
for _ , der := range addChainReq .Chain {
@@ -319,22 +320,22 @@ func addChainInternal(ctx context.Context, li *logInfo, w http.ResponseWriter, r
319
320
return http .StatusBadRequest , fmt .Errorf ("failed to build MerkleTreeLeaf: %s" , err )
320
321
}
321
322
322
- klog .V (2 ).Infof ("%s: %s => storage.GetCertIndex" , li .LogOrigin , method )
323
+ klog .V (2 ).Infof ("%s: %s => storage.GetCertIndex" , li .Origin , method )
323
324
sctDedupInfo , isDup , err := li .storage .GetCertDedupInfo (ctx , chain [0 ])
324
325
idx := sctDedupInfo .Idx
325
326
if err != nil {
326
327
return http .StatusInternalServerError , fmt .Errorf ("couldn't deduplicate the request: %s" , err )
327
328
}
328
329
329
330
if isDup {
330
- klog .V (3 ).Infof ("%s: %s - found duplicate entry at index %d" , li .LogOrigin , method , idx )
331
+ klog .V (3 ).Infof ("%s: %s - found duplicate entry at index %d" , li .Origin , method , idx )
331
332
entry .Timestamp = sctDedupInfo .Timestamp
332
333
} else {
333
334
if err := li .storage .AddIssuerChain (ctx , chain [1 :]); err != nil {
334
335
return http .StatusInternalServerError , fmt .Errorf ("failed to store issuer chain: %s" , err )
335
336
}
336
337
337
- klog .V (2 ).Infof ("%s: %s => storage.Add" , li .LogOrigin , method )
338
+ klog .V (2 ).Infof ("%s: %s => storage.Add" , li .Origin , method )
338
339
idx , err = li .storage .Add (ctx , entry )()
339
340
if err != nil {
340
341
if errors .Is (err , tessera .ErrPushback ) {
@@ -346,7 +347,7 @@ func addChainInternal(ctx context.Context, li *logInfo, w http.ResponseWriter, r
346
347
// We store the index for this certificate in the deduplication storage immediately.
347
348
// It might be stored again later, if a local deduplication storage is synced, potentially
348
349
// with a smaller value.
349
- klog .V (2 ).Infof ("%s: %s => storage.AddCertIndex" , li .LogOrigin , method )
350
+ klog .V (2 ).Infof ("%s: %s => storage.AddCertIndex" , li .Origin , method )
350
351
err = li .storage .AddCertDedupInfo (ctx , chain [0 ], dedup.SCTDedupInfo {Idx : idx , Timestamp : entry .Timestamp })
351
352
// TODO: block log writes if deduplication breaks
352
353
if err != nil {
@@ -381,9 +382,9 @@ func addChainInternal(ctx context.Context, li *logInfo, w http.ResponseWriter, r
381
382
// reason is logged and http status is already set
382
383
return http .StatusInternalServerError , fmt .Errorf ("failed to write response: %s" , err )
383
384
}
384
- klog .V (3 ).Infof ("%s: %s <= SCT" , li .LogOrigin , method )
385
+ klog .V (3 ).Infof ("%s: %s <= SCT" , li .Origin , method )
385
386
if sct .Timestamp == timeMillis {
386
- lastSCTTimestamp .Set (float64 (sct .Timestamp ), li .LogOrigin )
387
+ lastSCTTimestamp .Set (float64 (sct .Timestamp ), li .Origin )
387
388
}
388
389
389
390
return http .StatusOK , nil
@@ -409,14 +410,14 @@ func getRoots(_ context.Context, li *logInfo, w http.ResponseWriter, _ *http.Req
409
410
enc := json .NewEncoder (w )
410
411
err := enc .Encode (jsonMap )
411
412
if err != nil {
412
- klog .Warningf ("%s: get_roots failed: %v" , li .LogOrigin , err )
413
+ klog .Warningf ("%s: get_roots failed: %v" , li .Origin , err )
413
414
return http .StatusInternalServerError , fmt .Errorf ("get-roots failed with: %s" , err )
414
415
}
415
416
416
417
return http .StatusOK , nil
417
418
}
418
419
419
- // deadlineTime calculates the future time an RPC should expire based on our config
420
+ // deadlineTime calculates the future time a request should expire based on our config.
420
421
func deadlineTime (li * logInfo ) time.Time {
421
422
return li .TimeSource .Now ().Add (li .instanceOpts .Deadline )
422
423
}
@@ -440,9 +441,9 @@ func verifyAddChain(li *logInfo, req ct.AddChainRequest, expectingPrecert bool)
440
441
// The type of the leaf must match the one the handler expects
441
442
if isPrecert != expectingPrecert {
442
443
if expectingPrecert {
443
- klog .Warningf ("%s: Cert (or precert with invalid CT ext) submitted as precert chain: %q" , li .LogOrigin , req .Chain )
444
+ klog .Warningf ("%s: Cert (or precert with invalid CT ext) submitted as precert chain: %q" , li .Origin , req .Chain )
444
445
} else {
445
- klog .Warningf ("%s: Precert (or cert with invalid CT ext) submitted as cert chain: %q" , li .LogOrigin , req .Chain )
446
+ klog .Warningf ("%s: Precert (or cert with invalid CT ext) submitted as cert chain: %q" , li .Origin , req .Chain )
446
447
}
447
448
return nil , fmt .Errorf ("cert / precert mismatch: %T" , expectingPrecert )
448
449
}
0 commit comments