From 64ca5a3bfd1eca28a22b67943c797792b8c2fdc4 Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Sat, 13 Oct 2018 19:23:49 -0600 Subject: [PATCH] Add script and docs for auth --- README.md | 8 ++++++++ cli.go | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/README.md b/README.md index 88a74dc..4f970df 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ You will be asked some questions during the initial configuration of TempGopher. * `Invert heating switch` - If set to `true`, the heating will be ON when the switch is LOW. This should usually be `false`, so that is the default * `Enable verbose logging` - If set to `true`, TempGopher will display in the console every thermostat reading. This can be quite verbose, so the default is `false`. * `Write data to an Influx database?` - Whether or not to configure an Influx database +* `Enable user authentication?` - Whether or not to enable authentication ## Example configuration script @@ -83,4 +84,11 @@ Influx UserAgent [InfluxDBClient]: Influx timeout (in seconds) [30]: Influx database []: tempgopher Enable InsecureSkipVerify? [fasle]: +Username: mike +Password: ******** +Add another user? [y/N]: y +Username: foo +Password: *** +Add another user? [y/N]: n + ``` diff --git a/cli.go b/cli.go index 1e33396..3ad20a8 100644 --- a/cli.go +++ b/cli.go @@ -7,6 +7,8 @@ import ( "strconv" "strings" + "github.com/howeyc/gopass" + "github.com/yryz/ds18b20" ) @@ -190,6 +192,29 @@ func PromptForConfiguration() Config { } } + fmt.Println("Enable user authentication?") + fmt.Print("[Y/n]: ") + choice = ReadInput(reader, "y") + if strings.ToLower(choice)[0] == 'y' { + another := true + for another { + fmt.Print("Username: ") + username := ReadInput(reader, "") + fmt.Print("Password: ") + password, err := gopass.GetPasswdMasked() + if err != nil { + panic(err) + } + config.Users = append(config.Users, User{username, string(password)}) + + fmt.Print("Add another user? [y/N]: ") + choice = ReadInput(reader, "n") + if strings.ToLower(choice)[0] == 'n' { + another = false + } + } + } + return config }