mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Auth: Fix correct error for updateapikey in context handler (#61544)
* fix: correct error for updateapikey * refactor: send the correct err forward * update: based on review
This commit is contained in:
parent
997105c20d
commit
07bbc0716c
@ -350,11 +350,17 @@ func (h *ContextHandler) initContextWithAPIKey(reqContext *models.ReqContext) bo
|
||||
return true
|
||||
}
|
||||
|
||||
// update api_key last used date
|
||||
if err := h.apiKeyService.UpdateAPIKeyLastUsedDate(reqContext.Req.Context(), apikey.Id); err != nil {
|
||||
reqContext.JsonApiErr(http.StatusInternalServerError, InvalidAPIKey, errKey)
|
||||
return true
|
||||
}
|
||||
// non-blocking update api_key last used date
|
||||
go func(id int64) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
reqContext.Logger.Error("api key authentication panic", "err", err)
|
||||
}
|
||||
}()
|
||||
if err := h.apiKeyService.UpdateAPIKeyLastUsedDate(context.Background(), id); err != nil {
|
||||
reqContext.Logger.Warn("failed to update last use date for api key", "id", id)
|
||||
}
|
||||
}(apikey.Id)
|
||||
|
||||
if apikey.ServiceAccountId == nil || *apikey.ServiceAccountId < 1 { //There is no service account attached to the apikey
|
||||
// Use the old APIkey method. This provides backwards compatibility.
|
||||
|
Loading…
Reference in New Issue
Block a user