@@ -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 ?
0 commit comments