ParsePolicy will parse the target yaml node as though it is the top-level policy.
(ctx ParserContext, node *yaml.Node)
| 697 | |
| 698 | // ParsePolicy will parse the target yaml node as though it is the top-level policy. |
| 699 | func (p *parserImpl) ParsePolicy(ctx ParserContext, node *yaml.Node) *Policy { |
| 700 | ctx.CollectMetadata(node) |
| 701 | policy, id := ctx.NewPolicy(node) |
| 702 | if p.assertYAMLType(id, node, yamlMap) == nil || !p.checkMapValid(ctx, id, node) { |
| 703 | return policy |
| 704 | } |
| 705 | p.RangeMap(node, func(key, val *yaml.Node) bool { |
| 706 | keyID := p.CollectMetadata(key) |
| 707 | fieldName := key.Value |
| 708 | switch fieldName { |
| 709 | case "imports": |
| 710 | p.parseImports(ctx, policy, val) |
| 711 | case "name": |
| 712 | policy.SetName(ctx.NewString(val)) |
| 713 | case "description": |
| 714 | policy.SetDescription(p.newStrictString(val)) |
| 715 | // Since the description field was not supported initially, some |
| 716 | // clients rely on the ability to intercept it. |
| 717 | p.visitor.PolicyTag(ctx, keyID, fieldName, val, policy) |
| 718 | case "rule": |
| 719 | policy.SetRule(p.ParseRule(ctx, policy, val)) |
| 720 | default: |
| 721 | p.visitor.PolicyTag(ctx, keyID, fieldName, val, policy) |
| 722 | } |
| 723 | return true |
| 724 | }) |
| 725 | return policy |
| 726 | } |
| 727 | |
| 728 | func (p *parserImpl) parseImports(ctx ParserContext, policy *Policy, node *yaml.Node) { |
| 729 | id := ctx.CollectMetadata(node) |
no test coverage detected