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

Method ParseRule

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

797
798// ParseRule will parse the current yaml node as though it is the entry point to a rule.
799func (p *parserImpl) ParseRule(ctx ParserContext, policy *Policy, node *yaml.Node) *Rule {
800 r, id := ctx.NewRule(node)
801 if p.assertYAMLType(id, node, yamlMap) == nil || !p.checkMapValid(ctx, id, node) {
802 return r
803 }
804 p.RangeMap(node, func(key, val *yaml.Node) bool {
805 tagID := ctx.CollectMetadata(key)
806 fieldName := key.Value
807 switch fieldName {
808 case "id":
809 r.SetID(ctx.NewString(val))
810 case "description":
811 r.SetDescription(ctx.NewString(val))
812 case "variables":
813 p.parseVariables(ctx, policy, r, val)
814 case "match", "aggregate":
815 sem := firstMatch
816 if fieldName == "aggregate" {
817 sem = aggregate
818 }
819 if r.semantic != unspecified && r.semantic != sem {
820 p.ReportErrorAtID(tagID, "Only one of 'match' or 'aggregate' may be set in a rule")
821 } else {
822 r.SetSemantic(sem)
823 policy.SetSemantic(sem)
824 p.parseMatches(ctx, policy, r, val)
825 }
826 default:
827 p.visitor.RuleTag(ctx, tagID, fieldName, val, policy, r)
828 }
829 return true
830 })
831 return r
832}
833
834func (p *parserImpl) parseVariables(ctx ParserContext, policy *Policy, r *Rule, node *yaml.Node) {
835 id := ctx.CollectMetadata(node)

Callers 2

ParsePolicyMethod · 0.95
parseMatchInternalMethod · 0.95

Calls 13

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

Tested by

no test coverage detected