From f7110da64392f74b49f89fae44edb9f5a544519f Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Mon, 15 Sep 2025 16:39:37 +0200 Subject: [PATCH] Implement reading password from file --- README.md | 2 ++ main.go | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 657070a..bf94fb6 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ Usage of ./vodafone-station-exporter: Print version and exit -vodafone.station-password string 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. 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 diff --git a/main.go b/main.go index 23f07a1..3aaaab9 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "net/http" "os" "reflect" + "strings" ) const version = "0.0.1" @@ -26,12 +27,13 @@ func (s *slogWriter) Write(p []byte) (n int, err error) { } var ( - showVersion = flag.Bool("version", false, "Print version and exit") - showMetrics = flag.Bool("show-metrics", false, "Show available metrics and exit") - listenAddress = flag.String("web.listen-address", "[::]:9420", "Address to listen on") - 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)") - vodafoneStationPassword = flag.String("vodafone.station-password", "How is the default password calculated? mhmm", "Password for logging into the Vodafone station") + showVersion = flag.Bool("version", false, "Print version and exit") + showMetrics = flag.Bool("show-metrics", false, "Show available metrics and exit") + listenAddress = flag.String("web.listen-address", "[::]:9420", "Address to listen on") + 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)") + 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() { @@ -40,6 +42,18 @@ func main() { cfg := &promslog.Config{} 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 { describeMetrics() os.Exit(0)