MCPcopy
hub / github.com/crowdsecurity/crowdsec / Compile

Method Compile

pkg/parser/stash.go:62–99  ·  view source on GitHub ↗
(logger *log.Entry)

Source from the content-addressed store, hash-verified

60}
61
62func (s *Stash) Compile(logger *log.Entry) (*RuntimeStash, error) {
63 var err error
64
65 rs := &RuntimeStash{Config: s}
66
67 rs.ValueExpression, err = expr.Compile(s.Value,
68 exprhelpers.GetExprOptions(map[string]any{"evt": &pipeline.Event{}})...)
69 if err != nil {
70 return nil, fmt.Errorf("while compiling stash value expression: %w", err)
71 }
72
73 rs.KeyExpression, err = expr.Compile(s.Key,
74 exprhelpers.GetExprOptions(map[string]any{"evt": &pipeline.Event{}})...)
75 if err != nil {
76 return nil, fmt.Errorf("while compiling stash key expression: %w", err)
77 }
78
79 rs.TTLVal, err = time.ParseDuration(s.TTL)
80 if err != nil {
81 return nil, fmt.Errorf("while parsing stash ttl: %w", err)
82 }
83
84 // init the cache, does it make sense to create it here just to be sure everything is fine ?
85
86 cacheCfg := cache.CacheCfg{
87 Size: s.MaxMapSize,
88 TTL: rs.TTLVal,
89 Name: s.Name,
90 Strategy: s.Strategy,
91 LogLevel: logger.Logger.GetLevel(),
92 }
93
94 if err = cache.CacheInit(cacheCfg, cacheCfg.NewLogger()); err != nil {
95 return nil, fmt.Errorf("while initializing cache: %w", err)
96 }
97
98 return rs, nil
99}
100
101func (rs *RuntimeStash) Apply(idx int, cachedExprEnv map[string]any, logger *log.Entry, debug bool) {
102 var (

Callers 15

ValidateContextExprFunction · 0.45
NewAlertContextFunction · 0.45
ValidateYAMLFunction · 0.45
LoadAcquisitionFromDSNFunction · 0.45
ParseSourceConfigFunction · 0.45
setupAWSMethod · 0.45
UnmarshalConfigMethod · 0.45
UnmarshalConfigMethod · 0.45
newRXFunction · 0.45
NewProfileFunction · 0.45
CompileWLsMethod · 0.45
compileMethod · 0.45

Calls 4

NewLoggerMethod · 0.95
GetExprOptionsFunction · 0.92
CacheInitFunction · 0.92
GetLevelMethod · 0.80

Tested by 15

ValidateYAMLFunction · 0.36
TestBaseDbgFunction · 0.36
TestVisitorFunction · 0.36
TestMatchFunction · 0.36
TestParseQueryInExprFunction · 0.36
TestDistanceHelperFunction · 0.36
TestRegexpInFileFunction · 0.36
TestFileFunction · 0.36
TestIpInRangeFunction · 0.36
TestIpToRangeFunction · 0.36
TestAtofFunction · 0.36