parseRequest parses the incoming request to parse out the userID, rules namespace, and rule group name and returns them in that order. It also allows users to require a namespace or group name and return an error if it they can not be parsed.
(req *http.Request, requireNamespace, requireGroup bool)
| 473 | // and returns them in that order. It also allows users to require a namespace or group name and return |
| 474 | // an error if it they can not be parsed. |
| 475 | func parseRequest(req *http.Request, requireNamespace, requireGroup bool) (string, string, string, error) { |
| 476 | userID, err := users.TenantID(req.Context()) |
| 477 | if err != nil { |
| 478 | return "", "", "", user.ErrNoOrgID |
| 479 | } |
| 480 | |
| 481 | vars := mux.Vars(req) |
| 482 | |
| 483 | namespace, err := parseNamespace(vars) |
| 484 | if err != nil { |
| 485 | if err != ErrNoNamespace || requireNamespace { |
| 486 | return "", "", "", err |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | group, err := parseGroupName(vars) |
| 491 | if err != nil { |
| 492 | if err != ErrNoGroupName || requireGroup { |
| 493 | return "", "", "", err |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | return userID, namespace, group, nil |
| 498 | } |
| 499 | |
| 500 | func (a *API) ListRules(w http.ResponseWriter, req *http.Request) { |
| 501 | logger := util_log.WithContext(req.Context(), a.logger) |
no test coverage detected