Chore: Remove result field from API keys commands and queries (#65055)
* Chore: remove result field from api keys * fix shadowing * actually shadowing was all right
This commit is contained in:
+8
-6
@@ -29,13 +29,14 @@ import (
|
||||
func (hs *HTTPServer) GetAPIKeys(c *contextmodel.ReqContext) response.Response {
|
||||
query := apikey.GetApiKeysQuery{OrgID: c.OrgID, User: c.SignedInUser, IncludeExpired: c.QueryBool("includeExpired")}
|
||||
|
||||
if err := hs.apiKeyService.GetAPIKeys(c.Req.Context(), &query); err != nil {
|
||||
keys, err := hs.apiKeyService.GetAPIKeys(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
return response.Error(500, "Failed to list api keys", err)
|
||||
}
|
||||
|
||||
ids := map[string]bool{}
|
||||
result := make([]*dtos.ApiKeyDTO, len(query.Result))
|
||||
for i, t := range query.Result {
|
||||
result := make([]*dtos.ApiKeyDTO, len(keys))
|
||||
for i, t := range keys {
|
||||
ids[strconv.FormatInt(t.ID, 10)] = true
|
||||
var expiration *time.Time = nil
|
||||
if t.Expires != nil {
|
||||
@@ -134,7 +135,8 @@ func (hs *HTTPServer) AddAPIKey(c *contextmodel.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
cmd.Key = newKeyInfo.HashedKey
|
||||
if err := hs.apiKeyService.AddAPIKey(c.Req.Context(), &cmd); err != nil {
|
||||
key, err := hs.apiKeyService.AddAPIKey(c.Req.Context(), &cmd)
|
||||
if err != nil {
|
||||
if errors.Is(err, apikey.ErrInvalidExpiration) {
|
||||
return response.Error(400, err.Error(), nil)
|
||||
}
|
||||
@@ -145,8 +147,8 @@ func (hs *HTTPServer) AddAPIKey(c *contextmodel.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
result := &dtos.NewApiKeyResult{
|
||||
ID: cmd.Result.ID,
|
||||
Name: cmd.Result.Name,
|
||||
ID: key.ID,
|
||||
Name: key.Name,
|
||||
Key: newKeyInfo.ClientSecret,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user