MCPcopy
hub / github.com/cloudflare/cloudflared / parseFilters

Function parseFilters

cmd/cloudflared/tail/cmd.go:164–205  ·  view source on GitHub ↗

parseFilters will attempt to parse provided filters to send to with the EventStartStreaming

(c *cli.Context)

Source from the content-addressed store, hash-verified

162
163// parseFilters will attempt to parse provided filters to send to with the EventStartStreaming
164func parseFilters(c *cli.Context) (*management.StreamingFilters, error) {
165 var level *management.LogLevel
166 var sample float64
167
168 events := make([]management.LogEventType, 0)
169
170 argLevel := c.String("level")
171 argEvents := c.StringSlice("event")
172 argSample := c.Float64("sample")
173
174 if argLevel != "" {
175 l, ok := management.ParseLogLevel(argLevel)
176 if !ok {
177 return nil, fmt.Errorf("invalid --level filter provided, please use one of the following Log Levels: debug, info, warn, error")
178 }
179 level = &l
180 }
181
182 for _, v := range argEvents {
183 t, ok := management.ParseLogEventType(v)
184 if !ok {
185 return nil, fmt.Errorf("invalid --event filter provided, please use one of the following EventTypes: cloudflared, http, tcp, udp")
186 }
187 events = append(events, t)
188 }
189
190 if argSample <= 0.0 || argSample > 1.0 {
191 return nil, fmt.Errorf("invalid --sample value provided, please make sure it is in the range (0.0 .. 1.0)")
192 }
193 sample = argSample
194
195 if level == nil && len(events) == 0 && argSample != 1.0 {
196 // When no filters are provided, do not return a StreamingFilters struct
197 return nil, nil
198 }
199
200 return &management.StreamingFilters{
201 Level: level,
202 Events: events,
203 Sampling: sample,
204 }, nil
205}
206
207// buildURL will build the management url to contain the required query parameters to authenticate the request.
208func buildURL(c *cli.Context, log *zerolog.Logger, res cfapi.ManagementResource) (url.URL, error) {

Callers 1

RunFunction · 0.85

Calls 6

ParseLogLevelFunction · 0.92
ParseLogEventTypeFunction · 0.92
StringSliceMethod · 0.80
Float64Method · 0.80
ErrorfMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected