(stageFile Stagefile, pctx *UnixParserCtx, ectx EnricherCtx)
| 65 | } |
| 66 | |
| 67 | func processStageFile(stageFile Stagefile, pctx *UnixParserCtx, ectx EnricherCtx) ([]Node, error) { |
| 68 | if !strings.HasSuffix(stageFile.Filename, ".yaml") && !strings.HasSuffix(stageFile.Filename, ".yml") { |
| 69 | log.Warningf("skip non yaml : %s", stageFile.Filename) |
| 70 | return nil, nil |
| 71 | } |
| 72 | |
| 73 | log.Debugf("loading parser file '%s'", stageFile) |
| 74 | |
| 75 | st, err := os.Stat(stageFile.Filename) |
| 76 | if err != nil { |
| 77 | return nil, fmt.Errorf("failed to stat %s : %v", stageFile, err) |
| 78 | } |
| 79 | |
| 80 | if st.IsDir() { |
| 81 | return nil, nil |
| 82 | } |
| 83 | |
| 84 | yamlFile, err := os.Open(stageFile.Filename) |
| 85 | if err != nil { |
| 86 | return nil, fmt.Errorf("can't access parsing configuration file %s : %s", stageFile.Filename, err) |
| 87 | } |
| 88 | defer yamlFile.Close() |
| 89 | // process the yaml |
| 90 | dec := yaml.NewDecoder(yamlFile) |
| 91 | dec.SetStrict(true) |
| 92 | |
| 93 | var nodes []Node |
| 94 | |
| 95 | nodesCount := 0 |
| 96 | |
| 97 | for { |
| 98 | node := Node{} |
| 99 | node.OnSuccess = "continue" // default behavior is to continue |
| 100 | |
| 101 | if err = dec.Decode(&node); err != nil { |
| 102 | if errors.Is(err, io.EOF) { |
| 103 | log.Tracef("End of yaml file") |
| 104 | break |
| 105 | } |
| 106 | |
| 107 | return nil, fmt.Errorf("error decoding parsing configuration file '%s': %v", stageFile.Filename, err) |
| 108 | } |
| 109 | |
| 110 | // check for empty bucket |
| 111 | if node.Name == "" && node.Description == "" && node.Author == "" { |
| 112 | log.Infof("Node in %s has no name, author or description. Skipping.", stageFile.Filename) |
| 113 | continue |
| 114 | } |
| 115 | |
| 116 | // check compat |
| 117 | if node.FormatVersion == "" { |
| 118 | log.Tracef("no version in %s, assuming '1.0'", node.Name) |
| 119 | node.FormatVersion = "1.0" |
| 120 | } |
| 121 | |
| 122 | ok, err := constraint.Satisfies(node.FormatVersion, constraint.Parser) |
| 123 | if err != nil { |
| 124 | return nil, fmt.Errorf("failed to check version : %s", err) |
no test coverage detected
searching dependent graphs…