client: correctly unmarshal roles in ListRoles

This commit is contained in:
Anthony Romano
2016-03-05 10:29:52 -08:00
parent 2a0d64bb4a
commit 9809da95da
2 changed files with 38 additions and 6 deletions

View File

@@ -118,13 +118,17 @@ func (r *httpAuthRoleAPI) ListRoles(ctx context.Context) ([]string, error) {
if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil {
return nil, err
}
var userList struct {
Roles []string `json:"roles"`
var roleList struct {
Roles []Role `json:"roles"`
}
if err = json.Unmarshal(body, &userList); err != nil {
if err = json.Unmarshal(body, &roleList); err != nil {
return nil, err
}
return userList.Roles, nil
ret := make([]string, 0, len(roleList.Roles))
for _, r := range roleList.Roles {
ret = append(ret, r.Role)
}
return ret, nil
}
func (r *httpAuthRoleAPI) AddRole(ctx context.Context, rolename string) error {