GetUserPayload will take username, password, email, channels and roles you want to assign a user and create the appropriate payload for the _user endpoint. When using the default collection, chans and roles are handled as follows to align with CBG-3883: nil: omitted from payload empty slice: "[]"
(t testing.TB, username, password, email string, collection sgbucket.DataStore, chans, roles []string)
| 1673 | // empty slice: "[]" |
| 1674 | // populated slice: "["ABC"]" |
| 1675 | func GetUserPayload(t testing.TB, username, password, email string, collection sgbucket.DataStore, chans, roles []string) string { |
| 1676 | config := PrincipalConfigForWrite{} |
| 1677 | if username != "" { |
| 1678 | config.Name = &username |
| 1679 | } |
| 1680 | if password != "" { |
| 1681 | config.Password = &password |
| 1682 | } |
| 1683 | if email != "" { |
| 1684 | config.Email = &email |
| 1685 | } |
| 1686 | |
| 1687 | if roles != nil { |
| 1688 | roleSet := base.SetOf(roles...) |
| 1689 | config.ExplicitRoleNames = &roleSet |
| 1690 | } |
| 1691 | |
| 1692 | marshalledConfig, err := addChannelsToPrincipal(config, collection, chans) |
| 1693 | require.NoError(t, err) |
| 1694 | return string(marshalledConfig) |
| 1695 | } |
| 1696 | |
| 1697 | // GetRolePayload will take roleName and channels you want to assign a particular role and return the appropriate payload for the _role endpoint |
| 1698 | // For default collection, follows same handling as GetUserPayload for chans. |