ParseRule will parse the current yaml node as though it is the entry point to a rule.
(ctx ParserContext, policy *Policy, node *yaml.Node)
| 755 | |
| 756 | // ParseRule will parse the current yaml node as though it is the entry point to a rule. |
| 757 | func (p *parserImpl) ParseRule(ctx ParserContext, policy *Policy, node *yaml.Node) *Rule { |
| 758 | r, id := ctx.NewRule(node) |
| 759 | if p.assertYAMLType(id, node, yamlMap) == nil || !p.checkMapValid(ctx, id, node) { |
| 760 | return r |
| 761 | } |
| 762 | p.RangeMap(node, func(key, val *yaml.Node) bool { |
| 763 | tagID := ctx.CollectMetadata(key) |
| 764 | fieldName := key.Value |
| 765 | switch fieldName { |
| 766 | case "id": |
| 767 | r.SetID(ctx.NewString(val)) |
| 768 | case "description": |
| 769 | r.SetDescription(ctx.NewString(val)) |
| 770 | case "variables": |
| 771 | p.parseVariables(ctx, policy, r, val) |
| 772 | case "match": |
| 773 | p.parseMatches(ctx, policy, r, val) |
| 774 | default: |
| 775 | p.visitor.RuleTag(ctx, tagID, fieldName, val, policy, r) |
| 776 | } |
| 777 | return true |
| 778 | }) |
| 779 | return r |
| 780 | } |
| 781 | |
| 782 | func (p *parserImpl) parseVariables(ctx ParserContext, policy *Policy, r *Rule, node *yaml.Node) { |
| 783 | id := ctx.CollectMetadata(node) |
no test coverage detected