MCPcopy
hub / github.com/caddyserver/caddy / CELLibrary

Method CELLibrary

modules/caddyhttp/ip_matchers.go:101–130  ·  view source on GitHub ↗

CELLibrary produces options that expose this matcher for use in CEL expression matchers. Example: expression remote_ip('192.168.0.0/16', '172.16.0.0/12', '10.0.0.0/8')

(ctx caddy.Context)

Source from the content-addressed store, hash-verified

99//
100// expression remote_ip('192.168.0.0/16', '172.16.0.0/12', '10.0.0.0/8')
101func (MatchRemoteIP) CELLibrary(ctx caddy.Context) (cel.Library, error) {
102 return CELMatcherImpl(
103 // name of the macro, this is the function name that users see when writing expressions.
104 "remote_ip",
105 // name of the function that the macro will be rewritten to call.
106 "remote_ip_match_request_list",
107 // internal data type of the MatchPath value.
108 []*cel.Type{cel.ListType(cel.StringType)},
109 // function to convert a constant list of strings to a MatchPath instance.
110 func(data ref.Val) (RequestMatcherWithError, error) {
111 refStringList := stringSliceType
112 strList, err := data.ConvertToNative(refStringList)
113 if err != nil {
114 return nil, err
115 }
116
117 m := MatchRemoteIP{}
118
119 for _, input := range strList.([]string) {
120 if input == "forwarded" {
121 return nil, errors.New("the 'forwarded' option is no longer supported; use the 'client_ip' matcher instead")
122 }
123 m.Ranges = append(m.Ranges, input)
124 }
125
126 err = m.Provision(ctx)
127 return m, err
128 },
129 )
130}
131
132// Provision parses m's IP ranges, either from IP or CIDR expressions.
133func (m *MatchRemoteIP) Provision(ctx caddy.Context) error {

Callers

nothing calls this directly

Calls 3

ProvisionMethod · 0.95
CELMatcherImplFunction · 0.85
ConvertToNativeMethod · 0.45

Tested by

no test coverage detected