remove dispatch from apikey (#44955)
This commit is contained in:
+2
-2
@@ -256,10 +256,10 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
|
||||
// auth api keys
|
||||
apiRoute.Group("/auth/keys", func(keysRoute routing.RouteRegister) {
|
||||
keysRoute.Get("/", routing.Wrap(GetAPIKeys))
|
||||
keysRoute.Get("/", routing.Wrap(hs.GetAPIKeys))
|
||||
keysRoute.Post("/", quota("api_key"), routing.Wrap(hs.AddAPIKey))
|
||||
keysRoute.Post("/additional", quota("api_key"), routing.Wrap(hs.AdditionalAPIKey))
|
||||
keysRoute.Delete("/:id", routing.Wrap(DeleteAPIKey))
|
||||
keysRoute.Delete("/:id", routing.Wrap(hs.DeleteAPIKey))
|
||||
}, reqOrgAdmin)
|
||||
|
||||
// Preferences
|
||||
|
||||
+5
-8
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/components/apikeygen"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -16,10 +15,10 @@ import (
|
||||
)
|
||||
|
||||
// GetAPIKeys returns a list of API keys
|
||||
func GetAPIKeys(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) GetAPIKeys(c *models.ReqContext) response.Response {
|
||||
query := models.GetApiKeysQuery{OrgId: c.OrgId, IncludeExpired: c.QueryBool("includeExpired")}
|
||||
|
||||
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
|
||||
if err := hs.SQLStore.GetAPIKeys(c.Req.Context(), &query); err != nil {
|
||||
return response.Error(500, "Failed to list api keys", err)
|
||||
}
|
||||
|
||||
@@ -42,15 +41,14 @@ func GetAPIKeys(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// DeleteAPIKey deletes an API key
|
||||
func DeleteAPIKey(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) DeleteAPIKey(c *models.ReqContext) response.Response {
|
||||
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
}
|
||||
|
||||
cmd := &models.DeleteApiKeyCommand{Id: id, OrgId: c.OrgId}
|
||||
|
||||
err = bus.Dispatch(c.Req.Context(), cmd)
|
||||
err = hs.SQLStore.DeleteApiKey(c.Req.Context(), cmd)
|
||||
if err != nil {
|
||||
var status int
|
||||
if errors.Is(err, models.ErrApiKeyNotFound) {
|
||||
@@ -95,8 +93,7 @@ func (hs *HTTPServer) AddAPIKey(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
cmd.Key = newKeyInfo.HashedKey
|
||||
|
||||
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
|
||||
if err := hs.SQLStore.AddAPIKey(c.Req.Context(), &cmd); err != nil {
|
||||
if errors.Is(err, models.ErrInvalidApiKeyExpiration) {
|
||||
return response.Error(400, err.Error(), nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user