ParsePolicy will parse the target yaml node as though it is the top-level policy.
(ctx ParserContext, node *yaml.Node)
| 739 | |
| 740 | // ParsePolicy will parse the target yaml node as though it is the top-level policy. |
| 741 | func (p *parserImpl) ParsePolicy(ctx ParserContext, node *yaml.Node) *Policy { |
| 742 | ctx.CollectMetadata(node) |
| 743 | policy, id := ctx.NewPolicy(node) |
| 744 | if p.assertYAMLType(id, node, yamlMap) == nil || !p.checkMapValid(ctx, id, node) { |
| 745 | return policy |
| 746 | } |
| 747 | p.RangeMap(node, func(key, val *yaml.Node) bool { |
| 748 | keyID := p.CollectMetadata(key) |
| 749 | fieldName := key.Value |
| 750 | switch fieldName { |
| 751 | case "imports": |
| 752 | p.parseImports(ctx, policy, val) |
| 753 | case "name": |
| 754 | policy.SetName(ctx.NewString(val)) |
| 755 | case "description": |
| 756 | policy.SetDescription(p.newStrictString(val)) |
| 757 | // Since the description field was not supported initially, some |
| 758 | // clients rely on the ability to intercept it. |
| 759 | p.visitor.PolicyTag(ctx, keyID, fieldName, val, policy) |
| 760 | case "rule": |
| 761 | policy.SetRule(p.ParseRule(ctx, policy, val)) |
| 762 | default: |
| 763 | p.visitor.PolicyTag(ctx, keyID, fieldName, val, policy) |
| 764 | } |
| 765 | return true |
| 766 | }) |
| 767 | return policy |
| 768 | } |
| 769 | |
| 770 | func (p *parserImpl) parseImports(ctx ParserContext, policy *Policy, node *yaml.Node) { |
| 771 | id := ctx.CollectMetadata(node) |
no test coverage detected