(r *http.Request)
| 1588 | } |
| 1589 | |
| 1590 | func (api *API) rules(r *http.Request) apiFuncResult { |
| 1591 | if err := r.ParseForm(); err != nil { |
| 1592 | return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %w", err)}, nil, nil} |
| 1593 | } |
| 1594 | |
| 1595 | queryFormToSet := func(values []string) map[string]struct{} { |
| 1596 | set := make(map[string]struct{}, len(values)) |
| 1597 | for _, v := range values { |
| 1598 | set[v] = struct{}{} |
| 1599 | } |
| 1600 | return set |
| 1601 | } |
| 1602 | |
| 1603 | rnSet := queryFormToSet(r.Form["rule_name[]"]) |
| 1604 | rgSet := queryFormToSet(r.Form["rule_group[]"]) |
| 1605 | fSet := queryFormToSet(r.Form["file[]"]) |
| 1606 | |
| 1607 | matcherSets, err := api.parseMatchersParam(r.Form["match[]"]) |
| 1608 | if err != nil { |
| 1609 | return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil} |
| 1610 | } |
| 1611 | |
| 1612 | ruleGroups := api.rulesRetriever(r.Context()).RuleGroups() |
| 1613 | res := &RuleDiscovery{RuleGroups: make([]*RuleGroup, 0, len(ruleGroups))} |
| 1614 | typ := strings.ToLower(r.URL.Query().Get("type")) |
| 1615 | |
| 1616 | if typ != "" && typ != "alert" && typ != "record" { |
| 1617 | return invalidParamError(fmt.Errorf("not supported value %q", typ), "type") |
| 1618 | } |
| 1619 | |
| 1620 | returnAlerts := typ == "" || typ == "alert" |
| 1621 | returnRecording := typ == "" || typ == "record" |
| 1622 | |
| 1623 | excludeAlerts, err := parseExcludeAlerts(r) |
| 1624 | if err != nil { |
| 1625 | return invalidParamError(err, "exclude_alerts") |
| 1626 | } |
| 1627 | |
| 1628 | maxGroups, nextToken, parseErr := parseListRulesPaginationRequest(r) |
| 1629 | if parseErr != nil { |
| 1630 | return *parseErr |
| 1631 | } |
| 1632 | |
| 1633 | rgs := make([]*RuleGroup, 0, len(ruleGroups)) |
| 1634 | |
| 1635 | foundToken := false |
| 1636 | |
| 1637 | for _, grp := range ruleGroups { |
| 1638 | if maxGroups > 0 && nextToken != "" && !foundToken { |
| 1639 | if nextToken != getRuleGroupNextToken(grp.File(), grp.Name()) { |
| 1640 | continue |
| 1641 | } |
| 1642 | foundToken = true |
| 1643 | } |
| 1644 | |
| 1645 | if len(rgSet) > 0 { |
| 1646 | if _, ok := rgSet[grp.Name()]; !ok { |
| 1647 | continue |
nothing calls this directly
no test coverage detected