convertToOrganizationRoles converts a set of scoped role names to their unique scoped names. The database stores roles as an array of strings, and needs to be converted. TODO: Maybe make `[]rbac.RoleIdentifier` a custom type that implements a sql scanner to remove the need for these converters?
(organizationID uuid.UUID, names []string)
| 1191 | // TODO: Maybe make `[]rbac.RoleIdentifier` a custom type that implements a sql scanner |
| 1192 | // to remove the need for these converters? |
| 1193 | func (*querier) convertToOrganizationRoles(organizationID uuid.UUID, names []string) ([]rbac.RoleIdentifier, error) { |
| 1194 | uniques := make([]rbac.RoleIdentifier, 0, len(names)) |
| 1195 | for _, name := range names { |
| 1196 | // This check is a developer safety check. Old code might try to invoke this code path with |
| 1197 | // organization id suffixes. Catch this and return a nice error so it can be fixed. |
| 1198 | if strings.Contains(name, ":") { |
| 1199 | return nil, xerrors.Errorf("attempt to assign a role %q, remove the ':<organization_id> suffix", name) |
| 1200 | } |
| 1201 | |
| 1202 | uniques = append(uniques, rbac.RoleIdentifier{Name: name, OrganizationID: organizationID}) |
| 1203 | } |
| 1204 | |
| 1205 | return uniques, nil |
| 1206 | } |
| 1207 | |
| 1208 | // convertToDeploymentRoles converts string role names into deployment wide roles. |
| 1209 | func (*querier) convertToDeploymentRoles(names []string) []rbac.RoleIdentifier { |
no test coverage detected