diff --git a/src/cfg/cfg.go b/src/cfg/cfg.go index f776611..a07ee9f 100644 --- a/src/cfg/cfg.go +++ b/src/cfg/cfg.go @@ -8,10 +8,15 @@ import ( ) const ( - minServerPort = 1000 - maxServerPort = 65535 - portEnvName = "F2B_WEB_PORT" - addressEnvName = "F2B_WEB_LISTEN_ADDRESS" + minServerPort = 1000 + maxServerPort = 65535 + portEnvName = "F2B_WEB_PORT" + addressEnvName = "F2B_WEB_LISTEN_ADDRESS" + socketEnvName = "F2B_COLLECTOR_SOCKET" + fileCollectorEnabledEnvName = "F2B_COLLECTOR_TEXT" + fileCollectorPathEnvName = "F2B_COLLECTOR_TEXT_PATH" + basicAuthUserEnvName = "F2B_WEB_BASICAUTH_USER" + basicAuthPassEnvName = "F2B_WEB_BASICAUTH_PASS" ) type AppSettings struct { @@ -36,6 +41,10 @@ func Parse() *AppSettings { } func readParamsFromCli(settings *AppSettings) { + versionMode := kingpin. + Flag("version", "show version info and exit"). + Default("false"). + Bool() port := kingpin. Flag("port", "port to use for the metrics server"). Default("9191"). @@ -46,27 +55,41 @@ func readParamsFromCli(settings *AppSettings) { Default("0.0.0.0"). Envar(addressEnvName). String() + socketPath := kingpin. + Flag("socket", "path to the fail2ban server socket"). + Default(""). + Envar(socketEnvName). + String() + fileCollectorEnabled := kingpin. + Flag("collector.textfile", "enable the textfile collector"). + Default("false"). + Envar(fileCollectorEnabledEnvName). + Bool() + fileCollectorPath := kingpin. + Flag("collector.textfile.directory", "directory to read text files with metrics from"). + Default(""). + Envar(fileCollectorPathEnvName). + String() + rawBasicAuthUsername := kingpin. + Flag("web.basic-auth.username", "username to use to protect endpoints with basic auth"). + Default(""). + Envar(basicAuthUserEnvName). + String() + rawBasicAuthPassword := kingpin. + Flag("web.basic-auth.password", "password to use to protect endpoints with basic auth"). + Default(""). + Envar(basicAuthPassEnvName). + String() + settings.VersionMode = *versionMode settings.MetricsPort = *port settings.MetricsAddress = *address + settings.Fail2BanSocketPath = *socketPath + settings.FileCollectorEnabled = *fileCollectorEnabled + settings.FileCollectorPath = *fileCollectorPath + settings.setBasicAuthValues(*rawBasicAuthUsername, *rawBasicAuthPassword) kingpin.Parse() - - var rawBasicAuthUsername string - var rawBasicAuthPassword string - - //appSettings := &AppSettings{} - //flag.BoolVar(&appSettings.VersionMode, "version", false, "show version info and exit") - //flag.StringVar(&appSettings.MetricsAddress, "web.listen-address", "0.0.0.0", "address to use for the metrics server") - //flag.IntVar(&appSettings.MetricsPort, "port", 9191, "port to use for the metrics server") - //flag.StringVar(&appSettings.Fail2BanSocketPath, "socket", "", "path to the fail2ban server socket") - //flag.BoolVar(&appSettings.FileCollectorEnabled, "collector.textfile", false, "enable the textfile collector") - //flag.StringVar(&appSettings.FileCollectorPath, "collector.textfile.directory", "", "directory to read text files with metrics from") - //flag.StringVar(&rawBasicAuthUsername, "web.basic-auth.username", "", "username to use to protect endpoints with basic auth") - //flag.StringVar(&rawBasicAuthPassword, "web.basic-auth.password", "", "password to use to protect endpoints with basic auth") - // - //flag.Parse() - settings.setBasicAuthValues(rawBasicAuthUsername, rawBasicAuthPassword) } func (settings *AppSettings) setBasicAuthValues(rawUsername, rawPassword string) {