node.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. package parser
  2. import (
  3. "errors"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/antonmedv/expr"
  8. "github.com/antonmedv/expr/vm"
  9. "github.com/davecgh/go-spew/spew"
  10. "github.com/prometheus/client_golang/prometheus"
  11. log "github.com/sirupsen/logrus"
  12. yaml "gopkg.in/yaml.v2"
  13. "github.com/crowdsecurity/grokky"
  14. "github.com/crowdsecurity/crowdsec/pkg/cache"
  15. "github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
  16. "github.com/crowdsecurity/crowdsec/pkg/types"
  17. )
  18. type Node struct {
  19. FormatVersion string `yaml:"format"`
  20. //Enable config + runtime debug of node via config o/
  21. Debug bool `yaml:"debug,omitempty"`
  22. //If enabled, the node (and its child) will report their own statistics
  23. Profiling bool `yaml:"profiling,omitempty"`
  24. //Name, author, description and reference(s) for parser pattern
  25. Name string `yaml:"name,omitempty"`
  26. Author string `yaml:"author,omitempty"`
  27. Description string `yaml:"description,omitempty"`
  28. References []string `yaml:"references,omitempty"`
  29. //if debug is present in the node, keep its specific Logger in runtime structure
  30. Logger *log.Entry `yaml:"-"`
  31. //This is mostly a hack to make writing less repetitive.
  32. //relying on stage, we know which field to parse, and we
  33. //can also promote log to next stage on success
  34. Stage string `yaml:"stage,omitempty"`
  35. //OnSuccess allows to tag a node to be able to move log to next stage on success
  36. OnSuccess string `yaml:"onsuccess,omitempty"`
  37. rn string //this is only for us in debug, a random generated name for each node
  38. //Filter is executed at runtime (with current log line as context)
  39. //and must succeed or node is exited
  40. Filter string `yaml:"filter,omitempty"`
  41. RunTimeFilter *vm.Program `yaml:"-" json:"-"` //the actual compiled filter
  42. //If node has leafs, execute all of them until one asks for a 'break'
  43. LeavesNodes []Node `yaml:"nodes,omitempty"`
  44. //Flag used to describe when to 'break' or return an 'error'
  45. EnrichFunctions EnricherCtx
  46. /* If the node is actually a leaf, it can have : grok, enrich, statics */
  47. //pattern_syntax are named grok patterns that are re-utilized over several grok patterns
  48. SubGroks yaml.MapSlice `yaml:"pattern_syntax,omitempty"`
  49. //Holds a grok pattern
  50. Grok GrokPattern `yaml:"grok,omitempty"`
  51. //Statics can be present in any type of node and is executed last
  52. Statics []ExtraField `yaml:"statics,omitempty"`
  53. //Stash allows to capture data from the log line and store it in an accessible cache
  54. Stash []DataCapture `yaml:"stash,omitempty"`
  55. //Whitelists
  56. Whitelist Whitelist `yaml:"whitelist,omitempty"`
  57. Data []*types.DataSource `yaml:"data,omitempty"`
  58. }
  59. func (n *Node) validate(pctx *UnixParserCtx, ectx EnricherCtx) error {
  60. //stage is being set automagically
  61. if n.Stage == "" {
  62. return fmt.Errorf("stage needs to be an existing stage")
  63. }
  64. /* "" behaves like continue */
  65. if n.OnSuccess != "continue" && n.OnSuccess != "next_stage" && n.OnSuccess != "" {
  66. return fmt.Errorf("onsuccess '%s' not continue,next_stage", n.OnSuccess)
  67. }
  68. if n.Filter != "" && n.RunTimeFilter == nil {
  69. return fmt.Errorf("non-empty filter '%s' was not compiled", n.Filter)
  70. }
  71. if n.Grok.RunTimeRegexp != nil || n.Grok.TargetField != "" {
  72. if n.Grok.TargetField == "" && n.Grok.ExpValue == "" {
  73. return fmt.Errorf("grok requires 'expression' or 'apply_on'")
  74. }
  75. if n.Grok.RegexpName == "" && n.Grok.RegexpValue == "" {
  76. return fmt.Errorf("grok needs 'pattern' or 'name'")
  77. }
  78. }
  79. for idx, static := range n.Statics {
  80. if static.Method != "" {
  81. if static.ExpValue == "" {
  82. return fmt.Errorf("static %d : when method is set, expression must be present", idx)
  83. }
  84. if _, ok := ectx.Registered[static.Method]; !ok {
  85. log.Warningf("the method '%s' doesn't exist or the plugin has not been initialized", static.Method)
  86. }
  87. } else {
  88. if static.Meta == "" && static.Parsed == "" && static.TargetByName == "" {
  89. return fmt.Errorf("static %d : at least one of meta/event/target must be set", idx)
  90. }
  91. if static.Value == "" && static.RunTimeValue == nil {
  92. return fmt.Errorf("static %d value or expression must be set", idx)
  93. }
  94. }
  95. }
  96. for idx, stash := range n.Stash {
  97. if stash.Name == "" {
  98. return fmt.Errorf("stash %d : name must be set", idx)
  99. }
  100. if stash.Value == "" {
  101. return fmt.Errorf("stash %s : value expression must be set", stash.Name)
  102. }
  103. if stash.Key == "" {
  104. return fmt.Errorf("stash %s : key expression must be set", stash.Name)
  105. }
  106. if stash.TTL == "" {
  107. return fmt.Errorf("stash %s : ttl must be set", stash.Name)
  108. }
  109. if stash.Strategy == "" {
  110. stash.Strategy = "LRU"
  111. }
  112. //should be configurable
  113. if stash.MaxMapSize == 0 {
  114. stash.MaxMapSize = 100
  115. }
  116. }
  117. return nil
  118. }
  119. func (n *Node) process(p *types.Event, ctx UnixParserCtx, expressionEnv map[string]interface{}) (bool, error) {
  120. var NodeState bool
  121. var NodeHasOKGrok bool
  122. clog := n.Logger
  123. cachedExprEnv := expressionEnv
  124. clog.Tracef("Event entering node")
  125. if n.RunTimeFilter != nil {
  126. //Evaluate node's filter
  127. output, err := exprhelpers.Run(n.RunTimeFilter, cachedExprEnv, clog, n.Debug)
  128. if err != nil {
  129. clog.Warningf("failed to run filter : %v", err)
  130. clog.Debugf("Event leaving node : ko")
  131. return false, nil
  132. }
  133. switch out := output.(type) {
  134. case bool:
  135. if !out {
  136. clog.Debugf("Event leaving node : ko (failed filter)")
  137. return false, nil
  138. }
  139. default:
  140. clog.Warningf("Expr '%s' returned non-bool, abort : %T", n.Filter, output)
  141. clog.Debugf("Event leaving node : ko")
  142. return false, nil
  143. }
  144. NodeState = true
  145. } else {
  146. clog.Tracef("Node has not filter, enter")
  147. NodeState = true
  148. }
  149. if n.Name != "" {
  150. NodesHits.With(prometheus.Labels{"source": p.Line.Src, "type": p.Line.Module, "name": n.Name}).Inc()
  151. }
  152. exprErr := error(nil)
  153. isWhitelisted := n.CheckIPsWL(p.ParseIPSources())
  154. if !isWhitelisted {
  155. isWhitelisted, exprErr = n.CheckExprWL(cachedExprEnv)
  156. }
  157. if exprErr != nil {
  158. // Previous code returned nil if there was an error, so we keep this behavior
  159. return false, nil //nolint:nilerr
  160. }
  161. if isWhitelisted && !p.Whitelisted {
  162. p.Whitelisted = true
  163. p.WhitelistReason = n.Whitelist.Reason
  164. /*huglily wipe the ban order if the event is whitelisted and it's an overflow */
  165. if p.Type == types.OVFLW { /*don't do this at home kids */
  166. ips := []string{}
  167. for k := range p.Overflow.Sources {
  168. ips = append(ips, k)
  169. }
  170. clog.Infof("Ban for %s whitelisted, reason [%s]", strings.Join(ips, ","), n.Whitelist.Reason)
  171. p.Overflow.Whitelisted = true
  172. }
  173. }
  174. //Process grok if present, should be exclusive with nodes :)
  175. gstr := ""
  176. if n.Grok.RunTimeRegexp != nil {
  177. clog.Tracef("Processing grok pattern : %s : %p", n.Grok.RegexpName, n.Grok.RunTimeRegexp)
  178. //for unparsed, parsed etc. set sensible defaults to reduce user hassle
  179. if n.Grok.TargetField != "" {
  180. //it's a hack to avoid using real reflect
  181. if n.Grok.TargetField == "Line.Raw" {
  182. gstr = p.Line.Raw
  183. } else if val, ok := p.Parsed[n.Grok.TargetField]; ok {
  184. gstr = val
  185. } else {
  186. clog.Debugf("(%s) target field '%s' doesn't exist in %v", n.rn, n.Grok.TargetField, p.Parsed)
  187. NodeState = false
  188. }
  189. } else if n.Grok.RunTimeValue != nil {
  190. output, err := exprhelpers.Run(n.Grok.RunTimeValue, cachedExprEnv, clog, n.Debug)
  191. if err != nil {
  192. clog.Warningf("failed to run RunTimeValue : %v", err)
  193. NodeState = false
  194. }
  195. switch out := output.(type) {
  196. case string:
  197. gstr = out
  198. case int:
  199. gstr = fmt.Sprintf("%d", out)
  200. case float64, float32:
  201. gstr = fmt.Sprintf("%f", out)
  202. default:
  203. clog.Errorf("unexpected return type for RunTimeValue : %T", output)
  204. }
  205. }
  206. var groklabel string
  207. if n.Grok.RegexpName == "" {
  208. groklabel = fmt.Sprintf("%5.5s...", n.Grok.RegexpValue)
  209. } else {
  210. groklabel = n.Grok.RegexpName
  211. }
  212. grok := n.Grok.RunTimeRegexp.Parse(gstr)
  213. if len(grok) > 0 {
  214. /*tag explicitly that the *current* node had a successful grok pattern. it's important to know success state*/
  215. NodeHasOKGrok = true
  216. clog.Debugf("+ Grok '%s' returned %d entries to merge in Parsed", groklabel, len(grok))
  217. //We managed to grok stuff, merged into parse
  218. for k, v := range grok {
  219. clog.Debugf("\t.Parsed['%s'] = '%s'", k, v)
  220. p.Parsed[k] = v
  221. }
  222. // if the grok succeed, process associated statics
  223. err := n.ProcessStatics(n.Grok.Statics, p)
  224. if err != nil {
  225. clog.Errorf("(%s) Failed to process statics : %v", n.rn, err)
  226. return false, err
  227. }
  228. } else {
  229. //grok failed, node failed
  230. clog.Debugf("+ Grok '%s' didn't return data on '%s'", groklabel, gstr)
  231. NodeState = false
  232. }
  233. } else {
  234. clog.Tracef("! No grok pattern : %p", n.Grok.RunTimeRegexp)
  235. }
  236. //Process the stash (data collection) if : a grok was present and succeeded, or if there is no grok
  237. if NodeHasOKGrok || n.Grok.RunTimeRegexp == nil {
  238. for idx, stash := range n.Stash {
  239. var value string
  240. var key string
  241. if stash.ValueExpression == nil {
  242. clog.Warningf("Stash %d has no value expression, skipping", idx)
  243. continue
  244. }
  245. if stash.KeyExpression == nil {
  246. clog.Warningf("Stash %d has no key expression, skipping", idx)
  247. continue
  248. }
  249. //collect the data
  250. output, err := exprhelpers.Run(stash.ValueExpression, cachedExprEnv, clog, n.Debug)
  251. if err != nil {
  252. clog.Warningf("Error while running stash val expression : %v", err)
  253. }
  254. //can we expect anything else than a string ?
  255. switch output := output.(type) {
  256. case string:
  257. value = output
  258. default:
  259. clog.Warningf("unexpected type %t (%v) while running '%s'", output, output, stash.Value)
  260. continue
  261. }
  262. //collect the key
  263. output, err = exprhelpers.Run(stash.KeyExpression, cachedExprEnv, clog, n.Debug)
  264. if err != nil {
  265. clog.Warningf("Error while running stash key expression : %v", err)
  266. }
  267. //can we expect anything else than a string ?
  268. switch output := output.(type) {
  269. case string:
  270. key = output
  271. default:
  272. clog.Warningf("unexpected type %t (%v) while running '%s'", output, output, stash.Key)
  273. continue
  274. }
  275. cache.SetKey(stash.Name, key, value, &stash.TTLVal)
  276. }
  277. }
  278. //Iterate on leafs
  279. for _, leaf := range n.LeavesNodes {
  280. ret, err := leaf.process(p, ctx, cachedExprEnv)
  281. if err != nil {
  282. clog.Tracef("\tNode (%s) failed : %v", leaf.rn, err)
  283. clog.Debugf("Event leaving node : ko")
  284. return false, err
  285. }
  286. clog.Tracef("\tsub-node (%s) ret : %v (strategy:%s)", leaf.rn, ret, n.OnSuccess)
  287. if ret {
  288. NodeState = true
  289. /* if child is successful, stop processing */
  290. if n.OnSuccess == "next_stage" {
  291. clog.Debugf("child is success, OnSuccess=next_stage, skip")
  292. break
  293. }
  294. } else if !NodeHasOKGrok {
  295. /*
  296. If the parent node has a successful grok pattern, it's state will stay successful even if one or more chil fails.
  297. If the parent node is a skeleton node (no grok pattern), then at least one child must be successful for it to be a success.
  298. */
  299. NodeState = false
  300. }
  301. }
  302. /*todo : check if a node made the state change ?*/
  303. /* should the childs inherit the on_success behavior */
  304. clog.Tracef("State after nodes : %v", NodeState)
  305. //grok or leafs failed, don't process statics
  306. if !NodeState {
  307. if n.Name != "" {
  308. NodesHitsKo.With(prometheus.Labels{"source": p.Line.Src, "type": p.Line.Module, "name": n.Name}).Inc()
  309. }
  310. clog.Debugf("Event leaving node : ko")
  311. return NodeState, nil
  312. }
  313. if n.Name != "" {
  314. NodesHitsOk.With(prometheus.Labels{"source": p.Line.Src, "type": p.Line.Module, "name": n.Name}).Inc()
  315. }
  316. /*
  317. This is to apply statics when the node either was whitelisted, or is not a whitelist (it has no expr/ips wl)
  318. It is overconvoluted and should be simplified
  319. */
  320. if len(n.Statics) > 0 && (isWhitelisted || !n.ContainsWLs()) {
  321. clog.Debugf("+ Processing %d statics", len(n.Statics))
  322. // if all else is good in whitelist, process node's statics
  323. err := n.ProcessStatics(n.Statics, p)
  324. if err != nil {
  325. clog.Errorf("Failed to process statics : %v", err)
  326. return false, err
  327. }
  328. } else {
  329. clog.Tracef("! No node statics")
  330. }
  331. if NodeState {
  332. clog.Debugf("Event leaving node : ok")
  333. log.Tracef("node is successful, check strategy")
  334. if n.OnSuccess == "next_stage" {
  335. idx := stageidx(p.Stage, ctx.Stages)
  336. //we're at the last stage
  337. if idx+1 == len(ctx.Stages) {
  338. clog.Debugf("node reached the last stage : %s", p.Stage)
  339. } else {
  340. clog.Debugf("move Event from stage %s to %s", p.Stage, ctx.Stages[idx+1])
  341. p.Stage = ctx.Stages[idx+1]
  342. }
  343. } else {
  344. clog.Tracef("no strategy on success (%s), continue !", n.OnSuccess)
  345. }
  346. } else {
  347. clog.Debugf("Event leaving node : ko")
  348. }
  349. clog.Tracef("Node successful, continue")
  350. return NodeState, nil
  351. }
  352. func (n *Node) compile(pctx *UnixParserCtx, ectx EnricherCtx) error {
  353. var err error
  354. var valid bool
  355. valid = false
  356. dumpr := spew.ConfigState{MaxDepth: 1, DisablePointerAddresses: true}
  357. n.rn = seed.Generate()
  358. n.EnrichFunctions = ectx
  359. log.Tracef("compile, node is %s", n.Stage)
  360. /* if the node has debugging enabled, create a specific logger with debug
  361. that will be used only for processing this node ;) */
  362. if n.Debug {
  363. var clog = log.New()
  364. if err = types.ConfigureLogger(clog); err != nil {
  365. log.Fatalf("While creating bucket-specific logger : %s", err)
  366. }
  367. clog.SetLevel(log.DebugLevel)
  368. n.Logger = clog.WithFields(log.Fields{
  369. "id": n.rn,
  370. })
  371. n.Logger.Infof("%s has debug enabled", n.Name)
  372. } else {
  373. /* else bind it to the default one (might find something more elegant here)*/
  374. n.Logger = log.WithFields(log.Fields{
  375. "id": n.rn,
  376. })
  377. }
  378. /* display info about top-level nodes, they should be the only one with explicit stage name ?*/
  379. n.Logger = n.Logger.WithFields(log.Fields{"stage": n.Stage, "name": n.Name})
  380. n.Logger.Tracef("Compiling : %s", dumpr.Sdump(n))
  381. //compile filter if present
  382. if n.Filter != "" {
  383. n.RunTimeFilter, err = expr.Compile(n.Filter, exprhelpers.GetExprOptions(map[string]interface{}{"evt": &types.Event{}})...)
  384. if err != nil {
  385. return fmt.Errorf("compilation of '%s' failed: %v", n.Filter, err)
  386. }
  387. }
  388. /* handle pattern_syntax and groks */
  389. for _, pattern := range n.SubGroks {
  390. n.Logger.Tracef("Adding subpattern '%s' : '%s'", pattern.Key, pattern.Value)
  391. if err = pctx.Grok.Add(pattern.Key.(string), pattern.Value.(string)); err != nil {
  392. if errors.Is(err, grokky.ErrAlreadyExist) {
  393. n.Logger.Warningf("grok '%s' already registred", pattern.Key)
  394. continue
  395. }
  396. n.Logger.Errorf("Unable to compile subpattern %s : %v", pattern.Key, err)
  397. return err
  398. }
  399. }
  400. /* load grok by name or compile in-place */
  401. if n.Grok.RegexpName != "" {
  402. n.Logger.Tracef("+ Regexp Compilation '%s'", n.Grok.RegexpName)
  403. n.Grok.RunTimeRegexp, err = pctx.Grok.Get(n.Grok.RegexpName)
  404. if err != nil {
  405. return fmt.Errorf("unable to find grok '%s' : %v", n.Grok.RegexpName, err)
  406. }
  407. if n.Grok.RunTimeRegexp == nil {
  408. return fmt.Errorf("empty grok '%s'", n.Grok.RegexpName)
  409. }
  410. n.Logger.Tracef("%s regexp: %s", n.Grok.RegexpName, n.Grok.RunTimeRegexp.String())
  411. valid = true
  412. } else if n.Grok.RegexpValue != "" {
  413. if strings.HasSuffix(n.Grok.RegexpValue, "\n") {
  414. n.Logger.Debugf("Beware, pattern ends with \\n : '%s'", n.Grok.RegexpValue)
  415. }
  416. n.Grok.RunTimeRegexp, err = pctx.Grok.Compile(n.Grok.RegexpValue)
  417. if err != nil {
  418. return fmt.Errorf("failed to compile grok '%s': %v", n.Grok.RegexpValue, err)
  419. }
  420. if n.Grok.RunTimeRegexp == nil {
  421. // We shouldn't be here because compilation succeeded, so regexp shouldn't be nil
  422. return fmt.Errorf("grok compilation failure: %s", n.Grok.RegexpValue)
  423. }
  424. n.Logger.Tracef("%s regexp : %s", n.Grok.RegexpValue, n.Grok.RunTimeRegexp.String())
  425. valid = true
  426. }
  427. /*if grok source is an expression*/
  428. if n.Grok.ExpValue != "" {
  429. n.Grok.RunTimeValue, err = expr.Compile(n.Grok.ExpValue,
  430. exprhelpers.GetExprOptions(map[string]interface{}{"evt": &types.Event{}})...)
  431. if err != nil {
  432. return fmt.Errorf("while compiling grok's expression: %w", err)
  433. }
  434. }
  435. /* load grok statics */
  436. //compile expr statics if present
  437. for idx := range n.Grok.Statics {
  438. if n.Grok.Statics[idx].ExpValue != "" {
  439. n.Grok.Statics[idx].RunTimeValue, err = expr.Compile(n.Grok.Statics[idx].ExpValue,
  440. exprhelpers.GetExprOptions(map[string]interface{}{"evt": &types.Event{}})...)
  441. if err != nil {
  442. return err
  443. }
  444. }
  445. valid = true
  446. }
  447. /* load data capture (stash) */
  448. for i, stash := range n.Stash {
  449. n.Stash[i].ValueExpression, err = expr.Compile(stash.Value,
  450. exprhelpers.GetExprOptions(map[string]interface{}{"evt": &types.Event{}})...)
  451. if err != nil {
  452. return fmt.Errorf("while compiling stash value expression: %w", err)
  453. }
  454. n.Stash[i].KeyExpression, err = expr.Compile(stash.Key,
  455. exprhelpers.GetExprOptions(map[string]interface{}{"evt": &types.Event{}})...)
  456. if err != nil {
  457. return fmt.Errorf("while compiling stash key expression: %w", err)
  458. }
  459. n.Stash[i].TTLVal, err = time.ParseDuration(stash.TTL)
  460. if err != nil {
  461. return fmt.Errorf("while parsing stash ttl: %w", err)
  462. }
  463. logLvl := n.Logger.Logger.GetLevel()
  464. //init the cache, does it make sense to create it here just to be sure everything is fine ?
  465. if err = cache.CacheInit(cache.CacheCfg{
  466. Size: n.Stash[i].MaxMapSize,
  467. TTL: n.Stash[i].TTLVal,
  468. Name: n.Stash[i].Name,
  469. Strategy: n.Stash[i].Strategy,
  470. LogLevel: &logLvl,
  471. }); err != nil {
  472. return fmt.Errorf("while initializing cache: %w", err)
  473. }
  474. }
  475. /* compile leafs if present */
  476. for idx := range n.LeavesNodes {
  477. if n.LeavesNodes[idx].Name == "" {
  478. n.LeavesNodes[idx].Name = fmt.Sprintf("child-%s", n.Name)
  479. }
  480. /*propagate debug/stats to child nodes*/
  481. if !n.LeavesNodes[idx].Debug && n.Debug {
  482. n.LeavesNodes[idx].Debug = true
  483. }
  484. if !n.LeavesNodes[idx].Profiling && n.Profiling {
  485. n.LeavesNodes[idx].Profiling = true
  486. }
  487. n.LeavesNodes[idx].Stage = n.Stage
  488. err = n.LeavesNodes[idx].compile(pctx, ectx)
  489. if err != nil {
  490. return err
  491. }
  492. valid = true
  493. }
  494. /* load statics if present */
  495. for idx := range n.Statics {
  496. if n.Statics[idx].ExpValue != "" {
  497. n.Statics[idx].RunTimeValue, err = expr.Compile(n.Statics[idx].ExpValue, exprhelpers.GetExprOptions(map[string]interface{}{"evt": &types.Event{}})...)
  498. if err != nil {
  499. n.Logger.Errorf("Statics Compilation failed %v.", err)
  500. return err
  501. }
  502. }
  503. valid = true
  504. }
  505. /* compile whitelists if present */
  506. whitelistValid, err := n.CompileWLs()
  507. if err != nil {
  508. return err
  509. }
  510. valid = valid || whitelistValid
  511. if !valid {
  512. /* node is empty, error force return */
  513. n.Logger.Error("Node is empty or invalid, abort")
  514. n.Stage = ""
  515. return fmt.Errorf("Node is empty")
  516. }
  517. if err := n.validate(pctx, ectx); err != nil {
  518. return err
  519. }
  520. return nil
  521. }