add the remaining cli params using kingpin
This commit is contained in:
parent
0b0cc87574
commit
315ecf4271
@ -12,6 +12,11 @@ const (
|
|||||||
maxServerPort = 65535
|
maxServerPort = 65535
|
||||||
portEnvName = "F2B_WEB_PORT"
|
portEnvName = "F2B_WEB_PORT"
|
||||||
addressEnvName = "F2B_WEB_LISTEN_ADDRESS"
|
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 {
|
type AppSettings struct {
|
||||||
@ -36,6 +41,10 @@ func Parse() *AppSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readParamsFromCli(settings *AppSettings) {
|
func readParamsFromCli(settings *AppSettings) {
|
||||||
|
versionMode := kingpin.
|
||||||
|
Flag("version", "show version info and exit").
|
||||||
|
Default("false").
|
||||||
|
Bool()
|
||||||
port := kingpin.
|
port := kingpin.
|
||||||
Flag("port", "port to use for the metrics server").
|
Flag("port", "port to use for the metrics server").
|
||||||
Default("9191").
|
Default("9191").
|
||||||
@ -46,27 +55,41 @@ func readParamsFromCli(settings *AppSettings) {
|
|||||||
Default("0.0.0.0").
|
Default("0.0.0.0").
|
||||||
Envar(addressEnvName).
|
Envar(addressEnvName).
|
||||||
String()
|
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.MetricsPort = *port
|
||||||
settings.MetricsAddress = *address
|
settings.MetricsAddress = *address
|
||||||
|
settings.Fail2BanSocketPath = *socketPath
|
||||||
|
settings.FileCollectorEnabled = *fileCollectorEnabled
|
||||||
|
settings.FileCollectorPath = *fileCollectorPath
|
||||||
|
settings.setBasicAuthValues(*rawBasicAuthUsername, *rawBasicAuthPassword)
|
||||||
|
|
||||||
kingpin.Parse()
|
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) {
|
func (settings *AppSettings) setBasicAuthValues(rawUsername, rawPassword string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user