| 432 | } |
| 433 | |
| 434 | func preparePerms(mgr definitionLookuper, r requestParser, |
| 435 | method, path string) ([]string, error) { |
| 436 | perm := restPermsMap[method+":"+path] |
| 437 | if perm == "" { |
| 438 | perm = restPermDefault |
| 439 | } else if perm == "none" { |
| 440 | return nil, nil |
| 441 | } else if strings.Index(perm, "{}") >= 0 { |
| 442 | return nil, nil // Need dynamic post-filtering of REST response. |
| 443 | } |
| 444 | if strings.Index(perm, "<sourceName>") >= 0 { |
| 445 | sourceNames, err := sourceNamesFromReq(mgr, r, method, path) |
| 446 | if err != nil { |
| 447 | return nil, err |
| 448 | } |
| 449 | |
| 450 | perms := make([]string, 0, len(sourceNames)) |
| 451 | for _, sourceName := range sourceNames { |
| 452 | perms = append(perms, |
| 453 | decoratePermStrings(perm, sourceName)) |
| 454 | } |
| 455 | return perms, nil |
| 456 | } |
| 457 | |
| 458 | return []string{perm}, nil |
| 459 | } |
| 460 | |
| 461 | func decoratePermStrings(perm, sourceName string) string { |
| 462 | // If the RBAC settings are done at the scope or collection |