Began work on hashing api keys
This commit is contained in:
+3
-5
@@ -2,10 +2,10 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/Unknwon/macaron"
|
||||
"github.com/macaron-contrib/binding"
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/macaron-contrib/binding"
|
||||
)
|
||||
|
||||
// Register adds http routes
|
||||
@@ -61,10 +61,8 @@ func Register(r *macaron.Macaron) {
|
||||
|
||||
// auth api keys
|
||||
r.Group("/auth/keys", func() {
|
||||
r.Combo("/").
|
||||
Get(GetApiKeys).
|
||||
Post(bind(m.AddApiKeyCommand{}), AddApiKey).
|
||||
Put(bind(m.UpdateApiKeyCommand{}), UpdateApiKey)
|
||||
r.Get("/", GetApiKeys)
|
||||
r.Post("/", bind(m.AddApiKeyCommand{}), AddApiKey)
|
||||
r.Delete("/:id", DeleteApiKey)
|
||||
}, reqAccountAdmin)
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ func GetApiKeys(c *middleware.Context) {
|
||||
Id: t.Id,
|
||||
Name: t.Name,
|
||||
Role: t.Role,
|
||||
Key: t.Key,
|
||||
}
|
||||
}
|
||||
c.JSON(200, result)
|
||||
@@ -59,25 +58,7 @@ func AddApiKey(c *middleware.Context, cmd m.AddApiKeyCommand) {
|
||||
Id: cmd.Result.Id,
|
||||
Name: cmd.Result.Name,
|
||||
Role: cmd.Result.Role,
|
||||
Key: cmd.Result.Key,
|
||||
}
|
||||
|
||||
c.JSON(200, result)
|
||||
}
|
||||
|
||||
func UpdateApiKey(c *middleware.Context, cmd m.UpdateApiKeyCommand) {
|
||||
if !cmd.Role.IsValid() {
|
||||
c.JsonApiErr(400, "Invalid role specified", nil)
|
||||
return
|
||||
}
|
||||
|
||||
cmd.AccountId = c.AccountId
|
||||
|
||||
err := bus.Dispatch(&cmd)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Failed to update api key", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JsonOK("API key updated")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user