MCPcopy Create free account
hub / github.com/cel-expr/cel-go / ParsePolicy

Method ParsePolicy

policy/parser.go:699–726  ·  view source on GitHub ↗

ParsePolicy will parse the target yaml node as though it is the top-level policy.

(ctx ParserContext, node *yaml.Node)

Source from the content-addressed store, hash-verified

697
698// ParsePolicy will parse the target yaml node as though it is the top-level policy.
699func (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
728func (p *parserImpl) parseImports(ctx ParserContext, policy *Policy, node *yaml.Node) {
729 id := ctx.CollectMetadata(node)

Callers 1

parseYAMLMethod · 0.95

Calls 14

assertYAMLTypeMethod · 0.95
checkMapValidMethod · 0.95
CollectMetadataMethod · 0.95
parseImportsMethod · 0.95
SetNameMethod · 0.95
SetDescriptionMethod · 0.95
newStrictStringMethod · 0.95
SetRuleMethod · 0.95
ParseRuleMethod · 0.95
RangeMapMethod · 0.80
CollectMetadataMethod · 0.65
NewPolicyMethod · 0.65

Tested by

no test coverage detected