Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return role info for each role on pathRoleList #3532

Merged
merged 4 commits into from
Nov 3, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not initialize result map in parseRole, refactor ListResponseWithInfo
  • Loading branch information
calvn committed Nov 3, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6e9e88cc41bbb01de9942c104c861d36c5fff648
10 changes: 6 additions & 4 deletions builtin/logical/ssh/path_roles.go
Original file line number Diff line number Diff line change
@@ -489,10 +489,10 @@ func (b *backend) getRole(s logical.Storage, n string) (*sshRole, error) {
}

// parseRole converts a sshRole object into its map[string]interface representation,
// with appropriate values for each keyType. If the keyType is invalid, it will retun
// with appropriate values for each KeyType. If the KeyType is invalid, it will retun
// an error.
func (b *backend) parseRole(role *sshRole) (map[string]interface{}, error) {
result := map[string]interface{}{}
var result map[string]interface{}

switch role.KeyType {
case KeyTypeOTP:
@@ -589,8 +589,10 @@ func (b *backend) pathRoleList(req *logical.Request, d *framework.FieldData) (*l
continue
}

keyInfo[entry] = map[string]interface{}{
"key_type": roleInfo["key_type"],
if keyType, ok := roleInfo["key_type"]; ok {
keyInfo[entry] = map[string]interface{}{
"key_type": keyType,
}
}
}

9 changes: 7 additions & 2 deletions logical/response.go
Original file line number Diff line number Diff line change
@@ -116,12 +116,17 @@ func ListResponse(keys []string) *Response {
func ListResponseWithInfo(keys []string, keyInfo map[string]interface{}) *Response {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh interesting.

resp := ListResponse(keys)

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

if len(keyInfoData) > 0 {
resp.Data["key_info"] = keyInfoData
}

return resp
}