ParseRule will parse the current yaml node as though it is the entry point to a rule.
(ctx ParserContext, policy *Policy, node *yaml.Node)
| 797 | |
| 798 | // ParseRule will parse the current yaml node as though it is the entry point to a rule. |
| 799 | func (p *parserImpl) ParseRule(ctx ParserContext, policy *Policy, node *yaml.Node) *Rule { |
| 800 | r, id := ctx.NewRule(node) |
| 801 | if p.assertYAMLType(id, node, yamlMap) == nil || !p.checkMapValid(ctx, id, node) { |
| 802 | return r |
| 803 | } |
| 804 | p.RangeMap(node, func(key, val *yaml.Node) bool { |
| 805 | tagID := ctx.CollectMetadata(key) |
| 806 | fieldName := key.Value |
| 807 | switch fieldName { |
| 808 | case "id": |
| 809 | r.SetID(ctx.NewString(val)) |
| 810 | case "description": |
| 811 | r.SetDescription(ctx.NewString(val)) |
| 812 | case "variables": |
| 813 | p.parseVariables(ctx, policy, r, val) |
| 814 | case "match", "aggregate": |
| 815 | sem := firstMatch |
| 816 | if fieldName == "aggregate" { |
| 817 | sem = aggregate |
| 818 | } |
| 819 | if r.semantic != unspecified && r.semantic != sem { |
| 820 | p.ReportErrorAtID(tagID, "Only one of 'match' or 'aggregate' may be set in a rule") |
| 821 | } else { |
| 822 | r.SetSemantic(sem) |
| 823 | policy.SetSemantic(sem) |
| 824 | p.parseMatches(ctx, policy, r, val) |
| 825 | } |
| 826 | default: |
| 827 | p.visitor.RuleTag(ctx, tagID, fieldName, val, policy, r) |
| 828 | } |
| 829 | return true |
| 830 | }) |
| 831 | return r |
| 832 | } |
| 833 | |
| 834 | func (p *parserImpl) parseVariables(ctx ParserContext, policy *Policy, r *Rule, node *yaml.Node) { |
| 835 | id := ctx.CollectMetadata(node) |
no test coverage detected