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:
@@ -350,11 +350,17 @@ func (h *ContextHandler) initContextWithAPIKey(reqContext *models.ReqContext) bo
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// update api_key last used date
|
// non-blocking update api_key last used date
|
||||||
if err := h.apiKeyService.UpdateAPIKeyLastUsedDate(reqContext.Req.Context(), apikey.Id); err != nil {
|
go func(id int64) {
|
||||||
reqContext.JsonApiErr(http.StatusInternalServerError, InvalidAPIKey, errKey)
|
defer func() {
|
||||||
return true
|
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
|
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.
|
// Use the old APIkey method. This provides backwards compatibility.
|
||||||
|
|||||||
Reference in New Issue
Block a user