Skip to content

Commit 17aa12f

Browse files
authored
refact acquisition/appsec: happy path (#4183)
1 parent 69c0962 commit 17aa12f

2 files changed

Lines changed: 32 additions & 24 deletions

File tree

pkg/acquisition/modules/appsec/config.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,20 +293,26 @@ func (w *Source) checkAuth(ctx context.Context, apiKey string) error {
293293
return nil
294294
}
295295

296-
if now.After(expiration) { // Key is expired, recheck the value OR keep it if we cannot contact LAPI
297-
isAuth, err := w.isValidKey(ctx, apiKey)
298-
if isAuth {
299-
w.AuthCache.Set(apiKey, now.Add(*w.config.AuthCacheDuration))
300-
} else if err != nil { // General error when querying LAPI, consider the key still valid
301-
w.logger.Errorf("Error checking auth for API key: %s, extending cache duration", err)
302-
w.AuthCache.Set(apiKey, now.Add(*w.config.AuthCacheDuration))
303-
} else { // Key is not valid, remove it from cache
304-
w.AuthCache.Delete(apiKey)
305-
return errInvalidAPIKey
306-
}
296+
if !now.After(expiration) {
297+
return nil
307298
}
308299

309-
return nil
300+
// Key is expired, recheck the value OR keep it if we cannot contact LAPI
301+
isAuth, err := w.isValidKey(ctx, apiKey)
302+
if err != nil { // General error when querying LAPI, consider the key still valid
303+
w.logger.Errorf("Error checking auth for API key: %s, extending cache duration", err)
304+
w.AuthCache.Set(apiKey, now.Add(*w.config.AuthCacheDuration))
305+
return nil
306+
}
307+
308+
if isAuth {
309+
w.AuthCache.Set(apiKey, now.Add(*w.config.AuthCacheDuration))
310+
return nil
311+
}
312+
313+
// Key is not valid, remove it from cache
314+
w.AuthCache.Delete(apiKey)
315+
return errInvalidAPIKey
310316
}
311317

312318
// should this be in the runner ?

pkg/acquisition/modules/appsec/rx_operator.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,23 @@ func newRX(options plugintypes.OperatorOptions) (plugintypes.Operator, error) {
3939
}
4040

4141
func (o *rx) Evaluate(tx plugintypes.TransactionState, value string) bool {
42-
if tx.Capturing() {
43-
match := o.re.FindStringSubmatch(value)
44-
if len(match) == 0 {
45-
return false
46-
}
47-
for i, c := range match {
48-
if i == 9 {
49-
return true
50-
}
51-
tx.CaptureField(i, c)
42+
if !tx.Capturing() {
43+
return o.re.MatchString(value)
44+
}
45+
46+
match := o.re.FindStringSubmatch(value)
47+
if len(match) == 0 {
48+
return false
49+
}
50+
51+
for i, c := range match {
52+
if i == 9 {
53+
return true
5254
}
53-
return true
55+
tx.CaptureField(i, c)
5456
}
5557

56-
return o.re.MatchString(value)
58+
return true
5759
}
5860

5961
// RegisterRX registers the rx operator using a WASI implementation instead of Go.

0 commit comments

Comments
 (0)