MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / decodeFilter

Function decodeFilter

pkg/config/filters.go:413–441  ·  view source on GitHub ↗
(resource string, b []byte)

Source from the content-addressed store, hash-verified

411}
412
413func decodeFilter(resource string, b []byte) (*FilterConfig, error) {
414 var out interface{}
415 err := yaml.Unmarshal(b, &out)
416 if err != nil {
417 return nil, fmt.Errorf("%q is an invalid yaml file: %v", resource, err)
418 }
419 // apply validation to rule definition
420 valid, errs := validate(rulesSchema, out)
421 if !valid || len(errs) > 0 {
422 rawRule := out
423 b, err := yaml.Marshal(&rawRule)
424 if err == nil {
425 rawRule = string(b)
426 }
427 return nil, fmt.Errorf("invalid rule definition: \n\n"+
428 "%v in %s: %v", rawRule, resource, multierror.Wrap(errs...))
429 }
430 // render template
431 b, err = renderTmpl(resource, b)
432 if err != nil {
433 return nil, err
434 }
435 // now unmarshal into typed filter config
436 var flt FilterConfig
437 if err := yaml.Unmarshal(b, &flt); err != nil {
438 return nil, err
439 }
440 return &flt, nil
441}
442
443// renderTmpl executes templating directives in the
444// rule yaml file. It returns the byte slice

Callers 1

LoadFiltersMethod · 0.85

Calls 5

WrapFunction · 0.92
renderTmplFunction · 0.85
validateFunction · 0.70
UnmarshalMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected