mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2026-10-12 02:12:31 +00:00
refact: remove unnecessary pointers to map, string, mutex (#4212)
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
var (
|
||||
FileWriter *os.File
|
||||
FileWriteMutex *sync.Mutex
|
||||
FileWriteMutex sync.Mutex
|
||||
FileSize int64
|
||||
)
|
||||
|
||||
@@ -231,8 +231,6 @@ func (s *FilePlugin) Configure(_ context.Context, config *protobufs.Config) (*pr
|
||||
return &protobufs.Empty{}, err
|
||||
}
|
||||
|
||||
FileWriteMutex = &sync.Mutex{}
|
||||
|
||||
FileWriter, err = os.OpenFile(d.LogPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||
if err != nil {
|
||||
logger.Error("Failed to open log file", "error", err)
|
||||
|
||||
@@ -18,20 +18,20 @@ import (
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
// IPFilter []string `yaml:"ip_filter"`
|
||||
// ChunkSize *int64 `yaml:"chunk_size"`
|
||||
ListenAddr string `yaml:"listen_addr"`
|
||||
ListenSocket string `yaml:"listen_socket"`
|
||||
Path string `yaml:"path"`
|
||||
AuthType string `yaml:"auth_type"`
|
||||
BasicAuth *BasicAuthConfig `yaml:"basic_auth"`
|
||||
Headers *map[string]string `yaml:"headers"`
|
||||
TLS *TLSConfig `yaml:"tls"`
|
||||
CustomStatusCode *int `yaml:"custom_status_code"`
|
||||
CustomHeaders *map[string]string `yaml:"custom_headers"`
|
||||
MaxBodySize *int64 `yaml:"max_body_size"`
|
||||
Timeout *time.Duration `yaml:"timeout"`
|
||||
configuration.DataSourceCommonCfg `yaml:",inline"`
|
||||
// IPFilter []string `yaml:"ip_filter"`
|
||||
// ChunkSize *int64 `yaml:"chunk_size"`
|
||||
ListenAddr string `yaml:"listen_addr"`
|
||||
ListenSocket string `yaml:"listen_socket"`
|
||||
Path string `yaml:"path"`
|
||||
AuthType string `yaml:"auth_type"`
|
||||
BasicAuth *BasicAuthConfig `yaml:"basic_auth"`
|
||||
Headers map[string]string `yaml:"headers"`
|
||||
TLS *TLSConfig `yaml:"tls"`
|
||||
CustomStatusCode *int `yaml:"custom_status_code"`
|
||||
CustomHeaders map[string]string `yaml:"custom_headers"`
|
||||
MaxBodySize *int64 `yaml:"max_body_size"`
|
||||
Timeout *time.Duration `yaml:"timeout"`
|
||||
configuration.DataSourceCommonCfg `yaml:",inline"`
|
||||
}
|
||||
|
||||
func ConfigurationFromYAML(y []byte) (Configuration, error) {
|
||||
|
||||
@@ -37,7 +37,7 @@ func authorizeRequest(r *http.Request, hc *Configuration) error {
|
||||
}
|
||||
|
||||
if hc.AuthType == "headers" {
|
||||
for key, value := range *hc.Headers {
|
||||
for key, value := range hc.Headers {
|
||||
if r.Header.Get(key) != value {
|
||||
return errors.New("invalid headers")
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func (s *Source) RunServer(ctx context.Context, out chan pipeline.Event, t *tomb
|
||||
}
|
||||
|
||||
if s.Config.CustomHeaders != nil {
|
||||
for key, value := range *s.Config.CustomHeaders {
|
||||
for key, value := range s.Config.CustomHeaders {
|
||||
w.Header().Set(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ type DataProvider struct {
|
||||
Type string `yaml:"type"`
|
||||
//Control cache strategy on expensive regexps
|
||||
Cache *bool `yaml:"cache"`
|
||||
Strategy *string `yaml:"strategy"`
|
||||
Strategy string `yaml:"strategy"`
|
||||
Size *int `yaml:"size"`
|
||||
TTL *time.Duration `yaml:"ttl"`
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func RegexpCacheInit(filename string, cacheCfg enrichment.DataProvider) error {
|
||||
return nil
|
||||
}
|
||||
// cache is implicitly disabled if no cache config is provided
|
||||
if cacheCfg.Strategy == nil && cacheCfg.TTL == nil && cacheCfg.Size == nil {
|
||||
if cacheCfg.Strategy == "" && cacheCfg.TTL == nil && cacheCfg.Size == nil {
|
||||
return nil
|
||||
}
|
||||
// cache is enabled
|
||||
@@ -156,8 +156,8 @@ func RegexpCacheInit(filename string, cacheCfg enrichment.DataProvider) error {
|
||||
gc := gcache.New(size)
|
||||
|
||||
strategy := "LRU"
|
||||
if cacheCfg.Strategy != nil {
|
||||
strategy = *cacheCfg.Strategy
|
||||
if cacheCfg.Strategy != "" {
|
||||
strategy = cacheCfg.Strategy
|
||||
}
|
||||
|
||||
switch strategy {
|
||||
|
||||
Reference in New Issue
Block a user