(ctx context.Context, user, pw string)
| 142 | } |
| 143 | |
| 144 | func (a *API) cachedTokenAuthnCheck(ctx context.Context, user, pw string) error { |
| 145 | a.tokenMu.Lock() |
| 146 | res, ok := a.tokenMap[user+pw] |
| 147 | a.tokenMu.Unlock() |
| 148 | if !ok || time.Now().After(res.lastLookup.Add(tokenExpiry)) { |
| 149 | valid, err := a.tokenAuthnCheck(ctx, user, pw) |
| 150 | if err != nil { |
| 151 | return errors.Wrap(err) |
| 152 | } |
| 153 | res = tokenResult{valid: valid, lastLookup: time.Now()} |
| 154 | a.tokenMu.Lock() |
| 155 | a.tokenMap[user+pw] = res |
| 156 | a.tokenMu.Unlock() |
| 157 | } |
| 158 | if !res.valid { |
| 159 | return errors.New("invalid token") |
| 160 | } |
| 161 | return nil |
| 162 | } |
no test coverage detected