Implement reading password from file

This commit is contained in:
Jakob Lechner 2025-09-15 16:39:37 +02:00
parent 09785448e2
commit f7110da643
2 changed files with 22 additions and 6 deletions

View file

@ -10,6 +10,8 @@ Usage of ./vodafone-station-exporter:
Print version and exit Print version and exit
-vodafone.station-password string -vodafone.station-password string
Password for logging into the Vodafone station (default "How is the default password calculated? mhmm") Password for logging into the Vodafone station (default "How is the default password calculated? mhmm")
-vodafone.station-password-file string
File that contains the password for logging into the Vodafone station
-vodafone.station-url string -vodafone.station-url string
Vodafone station URL. For bridge mode this is 192.168.100.1 (note: Configure a route if using bridge mode) (default "http://192.168.0.1") Vodafone station URL. For bridge mode this is 192.168.100.1 (note: Configure a route if using bridge mode) (default "http://192.168.0.1")
-web.listen-address string -web.listen-address string

26
main.go
View file

@ -12,6 +12,7 @@ import (
"net/http" "net/http"
"os" "os"
"reflect" "reflect"
"strings"
) )
const version = "0.0.1" const version = "0.0.1"
@ -26,12 +27,13 @@ func (s *slogWriter) Write(p []byte) (n int, err error) {
} }
var ( var (
showVersion = flag.Bool("version", false, "Print version and exit") showVersion = flag.Bool("version", false, "Print version and exit")
showMetrics = flag.Bool("show-metrics", false, "Show available metrics and exit") showMetrics = flag.Bool("show-metrics", false, "Show available metrics and exit")
listenAddress = flag.String("web.listen-address", "[::]:9420", "Address to listen on") listenAddress = flag.String("web.listen-address", "[::]:9420", "Address to listen on")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics") metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics")
vodafoneStationUrl = flag.String("vodafone.station-url", "http://192.168.0.1", "Vodafone station URL. For bridge mode this is 192.168.100.1 (note: Configure a route if using bridge mode)") vodafoneStationUrl = flag.String("vodafone.station-url", "http://192.168.0.1", "Vodafone station URL. For bridge mode this is 192.168.100.1 (note: Configure a route if using bridge mode)")
vodafoneStationPassword = flag.String("vodafone.station-password", "How is the default password calculated? mhmm", "Password for logging into the Vodafone station") vodafoneStationPassword = flag.String("vodafone.station-password", "How is the default password calculated? mhmm", "Password for logging into the Vodafone station")
vodafoneStationPasswordFile = flag.String("vodafone.station-password-file", "", "Path to a file containing the Vodafone station password (overrides -vodafone.station-password)")
) )
func main() { func main() {
@ -40,6 +42,18 @@ func main() {
cfg := &promslog.Config{} cfg := &promslog.Config{}
logger = promslog.New(cfg) logger = promslog.New(cfg)
// Handle password from file if provided
if *vodafoneStationPasswordFile != "" {
data, err := os.ReadFile(*vodafoneStationPasswordFile)
if err != nil {
logger.Error("Failed to read password file", slog.String("err", err.Error()))
os.Exit(2)
}
pw := string(data)
pw = strings.TrimSpace(pw)
vodafoneStationPassword = &pw
}
if *showMetrics { if *showMetrics {
describeMetrics() describeMetrics()
os.Exit(0) os.Exit(0)