Skip to content

Commit

Permalink
Change roles -> key_info, only return key_type
Browse files Browse the repository at this point in the history
  • Loading branch information
calvn committed Nov 3, 2017
1 parent 585d626 commit 13a8fd7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions builtin/logical/ssh/path_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,7 @@ func (b *backend) pathRoleList(req *logical.Request, d *framework.FieldData) (*l
return nil, err
}

listResponse := logical.ListResponse(entries)
listResponse.Data["roles"] = map[string]interface{}{}

keyInfo := map[string]interface{}{}
for _, entry := range entries {
role, err := b.getRole(req.Storage, entry)
if err != nil {
Expand All @@ -591,10 +589,12 @@ func (b *backend) pathRoleList(req *logical.Request, d *framework.FieldData) (*l
continue
}

listResponse.Data["roles"].(map[string]interface{})[entry] = roleInfo
keyInfo[entry] = map[string]interface{}{
"key_type": roleInfo["key_type"],
}
}

return listResponse, nil
return logical.ListResponseWithInfo(entries, keyInfo), nil
}

func (b *backend) pathRoleRead(req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
Expand Down
15 changes: 15 additions & 0 deletions logical/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,18 @@ func ListResponse(keys []string) *Response {
}
return resp
}

// ListResponseWithInfo is used to format a response to a list operation and
// return the keys as well as a map with corresponding key info.
func ListResponseWithInfo(keys []string, keyInfo map[string]interface{}) *Response {
resp := ListResponse(keys)

resp.Data["key_info"] = map[string]interface{}{}
for _, key := range keys {
val, ok := keyInfo[key]
if ok {
resp.Data["key_info"].(map[string]interface{})[key] = val
}
}
return resp
}

0 comments on commit 13a8fd7

Please sign in to comment.