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

Method ParsePolicy

policy/parser.go:741–768  ·  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

739
740// ParsePolicy will parse the target yaml node as though it is the top-level policy.
741func (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
770func (p *parserImpl) parseImports(ctx ParserContext, policy *Policy, node *yaml.Node) {
771 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