MCPcopy Index your code
hub / github.com/crowdsecurity/crowdsec / LoadConfig

Function LoadConfig

cmd/crowdsec/main.go:93–176  ·  view source on GitHub ↗

LoadConfig returns a configuration parsed from configuration file

(configFile string, disableAgent bool, disableAPI bool, quiet bool)

Source from the content-addressed store, hash-verified

91
92// LoadConfig returns a configuration parsed from configuration file
93func LoadConfig(configFile string, disableAgent bool, disableAPI bool, quiet bool) (*csconfig.Config, error) {
94 cConfig, _, err := csconfig.NewConfig(configFile, disableAgent, disableAPI, quiet)
95 if err != nil {
96 return nil, fmt.Errorf("while loading configuration file: %w", err)
97 }
98
99 if err := trace.Init(filepath.Join(cConfig.ConfigPaths.DataDir, "trace")); err != nil {
100 return nil, fmt.Errorf("while setting up trace directory: %w", err)
101 }
102
103 if flags.LogLevel != 0 {
104 cConfig.Common.LogLevel = flags.LogLevel
105 if cConfig.API != nil && cConfig.API.Server != nil {
106 cConfig.API.Server.LogLevel = flags.LogLevel
107 }
108 }
109
110 if flags.haveTimeMachine() {
111 // in time-machine mode, we want to see what's happening
112 cConfig.Common.LogMedia = "stdout"
113 }
114
115 if err := logging.SetupStandardLogger(cConfig.Common.LogConfig, cConfig.Common.LogLevel, cConfig.Common.ForceColorLogs); err != nil {
116 return nil, err
117 }
118
119 if cConfig.Common.LogMedia != "stdout" {
120 log.AddHook(newFatalHook())
121 }
122
123 if err := csconfig.LoadFeatureFlagsFile(configFile, log.StandardLogger()); err != nil {
124 return nil, err
125 }
126
127 if !cConfig.DisableAgent {
128 if err := cConfig.LoadCrowdsec(); err != nil {
129 return nil, err
130 }
131 }
132
133 if !cConfig.DisableAPI {
134 if err := cConfig.LoadAPIServer(false, false); err != nil {
135 return nil, err
136 }
137 }
138
139 if !cConfig.DisableAgent && (cConfig.API == nil || cConfig.API.Client == nil || cConfig.API.Client.Credentials == nil) {
140 return nil, errors.New("missing local API credentials for crowdsec agent, abort")
141 }
142
143 if cConfig.DisableAPI && cConfig.DisableAgent {
144 return nil, errors.New("you must run at least the API Server or crowdsec")
145 }
146
147 if flags.OneShotDSN != "" && flags.SingleFileType == "" {
148 return nil, errors.New("-dsn requires a -type argument")
149 }
150

Callers 4

ExecuteMethod · 0.85
runServiceFunction · 0.85
reloadHandlerFunction · 0.85
runFunction · 0.85

Calls 11

LoadCrowdsecMethod · 0.95
LoadAPIServerMethod · 0.95
NewConfigFunction · 0.92
SetupStandardLoggerFunction · 0.92
LoadFeatureFlagsFileFunction · 0.92
ListFeatureFlagsFunction · 0.92
newFatalHookFunction · 0.85
haveTimeMachineMethod · 0.80
StandardLoggerMethod · 0.80
InitMethod · 0.45
WarnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…