(resource string, b []byte)
| 411 | } |
| 412 | |
| 413 | func 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 |
no test coverage detected