(ctx ParserContext, policy *Policy, r *Rule, node *yaml.Node)
| 903 | } |
| 904 | |
| 905 | func (p *parserImpl) parseMatchInternal(ctx ParserContext, policy *Policy, r *Rule, node *yaml.Node) *Match { |
| 906 | m, id := ctx.NewMatch(node) |
| 907 | if p.assertYAMLType(id, node, yamlMap) == nil || !p.checkMapValid(ctx, id, node) { |
| 908 | return m |
| 909 | } |
| 910 | m.SetCondition(ValueString{ID: ctx.NextID(), Value: "true"}) |
| 911 | p.RangeMap(node, func(key, val *yaml.Node) bool { |
| 912 | keyID := ctx.CollectMetadata(key) |
| 913 | fieldName := key.Value |
| 914 | switch fieldName { |
| 915 | case "condition": |
| 916 | m.SetCondition(ctx.NewString(val)) |
| 917 | case "output": |
| 918 | if m.HasRule() { |
| 919 | p.ReportErrorAtID(keyID, "only the rule or the output may be set") |
| 920 | } |
| 921 | m.SetOutput(ctx.NewString(val)) |
| 922 | case "explanation": |
| 923 | if m.HasRule() { |
| 924 | p.ReportErrorAtID(keyID, "explanation can only be set on output match cases, not nested rules") |
| 925 | } |
| 926 | m.SetExplanation(ctx.NewString(val)) |
| 927 | case "rule", "match", "aggregate": |
| 928 | if m.HasOutput() { |
| 929 | p.ReportErrorAtID(keyID, "only the rule or the output may be set") |
| 930 | } |
| 931 | if m.HasExplanation() { |
| 932 | p.ReportErrorAtID(keyID, "explanation can only be set on output match cases, not nested rules") |
| 933 | } |
| 934 | m.SetRule(p.ParseRule(ctx, policy, val)) |
| 935 | default: |
| 936 | p.visitor.MatchTag(ctx, keyID, fieldName, val, policy, m) |
| 937 | } |
| 938 | return true |
| 939 | }) |
| 940 | if !m.HasOutput() && !m.HasRule() { |
| 941 | p.ReportErrorAtID(id, "match does not specify a rule or output") |
| 942 | } |
| 943 | return m |
| 944 | } |
| 945 | |
| 946 | func (p *parserImpl) assertYAMLType(id int64, node *yaml.Node, nodeTypes ...yamlNodeType) *yamlNodeType { |
| 947 | nt, found := yamlTypes[node.LongTag()] |
no test coverage detected