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

Method ParseRule

policy/parser.go:757–780  ·  view source on GitHub ↗

ParseRule will parse the current yaml node as though it is the entry point to a rule.

(ctx ParserContext, policy *Policy, node *yaml.Node)

Source from the content-addressed store, hash-verified

755
756// ParseRule will parse the current yaml node as though it is the entry point to a rule.
757func (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
782func (p *parserImpl) parseVariables(ctx ParserContext, policy *Policy, r *Rule, node *yaml.Node) {
783 id := ctx.CollectMetadata(node)

Callers 2

ParsePolicyMethod · 0.95
ParseMatchMethod · 0.95

Calls 11

assertYAMLTypeMethod · 0.95
checkMapValidMethod · 0.95
SetIDMethod · 0.95
SetDescriptionMethod · 0.95
parseVariablesMethod · 0.95
parseMatchesMethod · 0.95
RangeMapMethod · 0.80
NewRuleMethod · 0.65
CollectMetadataMethod · 0.65
NewStringMethod · 0.65
RuleTagMethod · 0.65

Tested by

no test coverage detected