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

Method parseMatchInternal

policy/parser.go:905–944  ·  view source on GitHub ↗
(ctx ParserContext, policy *Policy, r *Rule, node *yaml.Node)

Source from the content-addressed store, hash-verified

903}
904
905func (p *parserImpl) parseMatchInternal(ctx ParserContext, policy *Policy, r *Rule, node *yaml.Node) *Match {
906 m, id := ctx.NewMatch(node)
907 if p.assertYAMLType(id, node, yamlMap) == nil || !p.checkMapValid(ctx, id, node) {
908 return m
909 }
910 m.SetCondition(ValueString{ID: ctx.NextID(), Value: "true"})
911 p.RangeMap(node, func(key, val *yaml.Node) bool {
912 keyID := ctx.CollectMetadata(key)
913 fieldName := key.Value
914 switch fieldName {
915 case "condition":
916 m.SetCondition(ctx.NewString(val))
917 case "output":
918 if m.HasRule() {
919 p.ReportErrorAtID(keyID, "only the rule or the output may be set")
920 }
921 m.SetOutput(ctx.NewString(val))
922 case "explanation":
923 if m.HasRule() {
924 p.ReportErrorAtID(keyID, "explanation can only be set on output match cases, not nested rules")
925 }
926 m.SetExplanation(ctx.NewString(val))
927 case "rule", "match", "aggregate":
928 if m.HasOutput() {
929 p.ReportErrorAtID(keyID, "only the rule or the output may be set")
930 }
931 if m.HasExplanation() {
932 p.ReportErrorAtID(keyID, "explanation can only be set on output match cases, not nested rules")
933 }
934 m.SetRule(p.ParseRule(ctx, policy, val))
935 default:
936 p.visitor.MatchTag(ctx, keyID, fieldName, val, policy, m)
937 }
938 return true
939 })
940 if !m.HasOutput() && !m.HasRule() {
941 p.ReportErrorAtID(id, "match does not specify a rule or output")
942 }
943 return m
944}
945
946func (p *parserImpl) assertYAMLType(id int64, node *yaml.Node, nodeTypes ...yamlNodeType) *yamlNodeType {
947 nt, found := yamlTypes[node.LongTag()]

Callers 2

parseMatchesMethod · 0.95
ParseMatchMethod · 0.95

Calls 15

assertYAMLTypeMethod · 0.95
checkMapValidMethod · 0.95
SetConditionMethod · 0.95
HasRuleMethod · 0.95
ReportErrorAtIDMethod · 0.95
SetOutputMethod · 0.95
SetExplanationMethod · 0.95
HasOutputMethod · 0.95
HasExplanationMethod · 0.95
SetRuleMethod · 0.95
ParseRuleMethod · 0.95
RangeMapMethod · 0.80

Tested by

no test coverage detected