(w http.ResponseWriter, req *http.Request)
| 498 | } |
| 499 | |
| 500 | func (a *API) ListRules(w http.ResponseWriter, req *http.Request) { |
| 501 | logger := util_log.WithContext(req.Context(), a.logger) |
| 502 | |
| 503 | userID, namespace, _, err := parseRequest(req, false, false) |
| 504 | if err != nil { |
| 505 | util_api.RespondError(logger, w, v1.ErrBadData, err.Error(), http.StatusBadRequest) |
| 506 | return |
| 507 | } |
| 508 | |
| 509 | level.Debug(logger).Log("msg", "retrieving rule groups with namespace", "userID", userID, "namespace", namespace) |
| 510 | rgs, err := a.store.ListRuleGroupsForUserAndNamespace(req.Context(), userID, namespace) |
| 511 | if err != nil { |
| 512 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 513 | return |
| 514 | } |
| 515 | |
| 516 | if len(rgs) == 0 { |
| 517 | level.Info(logger).Log("msg", "no rule groups found", "userID", userID) |
| 518 | http.Error(w, ErrNoRuleGroups.Error(), http.StatusNotFound) |
| 519 | return |
| 520 | } |
| 521 | |
| 522 | _, err = a.store.LoadRuleGroups(req.Context(), map[string]rulespb.RuleGroupList{userID: rgs}) |
| 523 | if err != nil { |
| 524 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 525 | return |
| 526 | } |
| 527 | |
| 528 | level.Debug(logger).Log("msg", "retrieved rule groups from rule store", "userID", userID, "num_namespaces", len(rgs)) |
| 529 | |
| 530 | formatted := rgs.Formatted() |
| 531 | marshalAndSend(formatted, w, logger) |
| 532 | } |
| 533 | |
| 534 | func (a *API) GetRuleGroup(w http.ResponseWriter, req *http.Request) { |
| 535 | logger := util_log.WithContext(req.Context(), a.logger) |
nothing calls this directly
no test coverage detected