From 39a865ff7c45749df4d2d4d1f0b3f8211e151c72 Mon Sep 17 00:00:00 2001 From: jayme-github Date: Tue, 16 Jun 2020 22:50:26 +0200 Subject: [PATCH] Deprecate FRITZBOX_USER and FRITZBOX_PASSWORD ...in favor of USERNAME and PASSWORD to align with the other flags. FRITZBOX_USER and FRITZBOX_PASSWORD will still be used, but a message will be printed, asking to migate away from them. --- main.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b6d5db0..55ba6ac 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "io/ioutil" "log" "net/http" @@ -25,8 +26,8 @@ type client struct { var ( fritzClient client fbURL *url.URL - username = flag.String("username", os.Getenv("FRITZBOX_USER"), "FRITZ!Box username (default: $FRITZBOX_USER).") - password = flag.String("password", os.Getenv("FRITZBOX_PASSWORD"), "FRITZ!Box password (default: $FRITZBOX_PASSWORD).") + username = flag.String("username", "", "FRITZ!Box username.") + password = flag.String("password", "", "FRITZ!Box password.") urlString = flag.String("url", "https://fritz.box", "FRITZ!Box URL.") noVerify = flag.Bool("noverify", false, "Omit TLS verification of the FRITZ!Box certificate.") certificatePath = flag.String("cert", "", "Path to the FRITZ!Box certificate.") @@ -39,6 +40,25 @@ func validateFlags() { if err != nil { log.Fatalln(err) } + + // Deprecate special syntax variabled for username and password. + // All flags can be set via environment variables with the same name (uppercase) + // like USERNAME for -username and PASSWORD for -password. + fritzboxUser := os.Getenv("FRITZBOX_USER") + fritzboxPassword := os.Getenv("FRITZBOX_PASSWORD") + if fritzboxUser != "" { + fmt.Println("You are using the deprecated environment variable \"FRITZBOX_USER\", please use \"USERNAME\" instead.") + if *username == "" { + *username = fritzboxUser + } + } + if fritzboxPassword != "" { + fmt.Println("You are using the deprecated environment variable \"FRITZBOX_PASSWORD\", please use \"PASSWORD\" instead.") + if *password == "" { + *password = fritzboxPassword + } + } + if len(*username) == 0 { log.Fatalln("No username provided.") }