You've already forked prometheus-fail2ban-exporter
rewrite auth provider logic
This commit is contained in:
15
cfg/cfg.go
15
cfg/cfg.go
@ -2,9 +2,11 @@ package cfg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/auth"
|
||||
)
|
||||
|
||||
var cliStruct struct {
|
||||
@ -36,11 +38,22 @@ func Parse() *AppSettings {
|
||||
Fail2BanSocketPath: cliStruct.F2bSocketPath,
|
||||
FileCollectorPath: cliStruct.TextFileExporterPath,
|
||||
ExitOnSocketConnError: cliStruct.ExitOnSocketError,
|
||||
BasicAuthProvider: newHashedBasicAuth(cliStruct.BasicAuthUser, cliStruct.BasicAuthPass),
|
||||
AuthProvider: createAuthProvider(),
|
||||
}
|
||||
return settings
|
||||
}
|
||||
|
||||
func createAuthProvider() auth.AuthProvider {
|
||||
username := cliStruct.BasicAuthUser
|
||||
password := cliStruct.BasicAuthPass
|
||||
|
||||
if len(username) == 0 && len(password) == 0 {
|
||||
return auth.NewEmptyAuthProvider()
|
||||
}
|
||||
log.Print("basic auth enabled")
|
||||
return auth.NewBasicAuthProvider(username, password)
|
||||
}
|
||||
|
||||
func validateFlags(cliCtx *kong.Context) {
|
||||
var flagsValid = true
|
||||
var messages = []string{}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package cfg
|
||||
|
||||
import "gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/auth"
|
||||
|
||||
type AppSettings struct {
|
||||
VersionMode bool
|
||||
MetricsAddress string
|
||||
Fail2BanSocketPath string
|
||||
FileCollectorPath string
|
||||
BasicAuthProvider *hashedBasicAuth
|
||||
AuthProvider auth.AuthProvider
|
||||
ExitOnSocketConnError bool
|
||||
}
|
||||
|
Reference in New Issue
Block a user