diff --git a/builtin/logical/ssh/path_roles.go b/builtin/logical/ssh/path_roles.go index 5044adf6788d..0387a123316f 100644 --- a/builtin/logical/ssh/path_roles.go +++ b/builtin/logical/ssh/path_roles.go @@ -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 { @@ -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) { diff --git a/logical/response.go b/logical/response.go index 6ee452b6865b..33be1a43cb67 100644 --- a/logical/response.go +++ b/logical/response.go @@ -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 +}