UnmarshalUser extracts the first User pointed by the userKey in the query response.
(resp *api.Response, userKey string)
| 82 | |
| 83 | // UnmarshalUser extracts the first User pointed by the userKey in the query response. |
| 84 | func UnmarshalUser(resp *api.Response, userKey string) (user *User, err error) { |
| 85 | m := make(map[string][]User) |
| 86 | |
| 87 | err = json.Unmarshal(resp.GetJson(), &m) |
| 88 | if err != nil { |
| 89 | return nil, fmt.Errorf("unable to unmarshal the query user response: %w", err) |
| 90 | } |
| 91 | users := m[userKey] |
| 92 | if len(users) == 0 { |
| 93 | // the user does not exist |
| 94 | return nil, nil |
| 95 | } |
| 96 | if len(users) > 1 { |
| 97 | return nil, fmt.Errorf("found multiple users: %s", resp.GetJson()) |
| 98 | } |
| 99 | return &users[0], nil |
| 100 | } |
| 101 | |
| 102 | // Acl represents the permissions in the ACL system. |
| 103 | // An Acl can have a predicate and permission for that predicate. |
no test coverage detected