don't log full password string

This commit is contained in:
David 2021-08-08 16:56:45 -04:00
parent a0b2bffcb3
commit 2803ce919a
2 changed files with 22 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"os" "os"
"runtime/debug" "runtime/debug"
"strings"
"sync" "sync"
"git.yetaga.in/alazyreader/library/book" "git.yetaga.in/alazyreader/library/book"
@ -47,6 +48,13 @@ func (s *State) Set(key string, value interface{}) {
s.stateMap[key] = value s.stateMap[key] = value
} }
func max(a, b int) int {
if a > b {
return a
}
return b
}
// UI states // UI states
const ( const (
IN_MENU = iota IN_MENU = iota
@ -66,6 +74,9 @@ func main() {
// set up DB connection // set up DB connection
if c.DBUser == "" || c.DBPass == "" || c.DBHost == "" || c.DBPort == "" || c.DBName == "" { if c.DBUser == "" || c.DBPass == "" || c.DBHost == "" || c.DBPort == "" || c.DBName == "" {
if c.DBPass != "" { // obscure password
c.DBPass = c.DBPass[0:max(3, len(c.DBPass))] + strings.Repeat("*", max(0, len(c.DBPass)-3))
}
log.Fatalf("vars: %+v", c) log.Fatalf("vars: %+v", c)
} }
lib, err := database.NewMySQLConnection(c.DBUser, c.DBPass, c.DBHost, c.DBPort, c.DBName) lib, err := database.NewMySQLConnection(c.DBUser, c.DBPass, c.DBHost, c.DBPort, c.DBName)

View File

@ -6,6 +6,7 @@ import (
"io/fs" "io/fs"
"log" "log"
"net/http" "net/http"
"strings"
"git.yetaga.in/alazyreader/library/book" "git.yetaga.in/alazyreader/library/book"
"git.yetaga.in/alazyreader/library/config" "git.yetaga.in/alazyreader/library/config"
@ -14,6 +15,13 @@ import (
"github.com/kelseyhightower/envconfig" "github.com/kelseyhightower/envconfig"
) )
func max(a, b int) int {
if a > b {
return a
}
return b
}
type Library interface { type Library interface {
GetAllBooks(context.Context) ([]book.Book, error) GetAllBooks(context.Context) ([]book.Book, error)
} }
@ -29,7 +37,6 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return return
} }
StaticHandler(r.static).ServeHTTP(w, req) StaticHandler(r.static).ServeHTTP(w, req)
return
} }
func APIHandler(l Library) http.Handler { func APIHandler(l Library) http.Handler {
@ -66,6 +73,9 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
if c.DBUser == "" || c.DBPass == "" || c.DBHost == "" || c.DBPort == "" || c.DBName == "" { if c.DBUser == "" || c.DBPass == "" || c.DBHost == "" || c.DBPort == "" || c.DBName == "" {
if c.DBPass != "" { // obscure password
c.DBPass = c.DBPass[0:max(3, len(c.DBPass))] + strings.Repeat("*", max(0, len(c.DBPass)-3))
}
log.Fatalf("vars: %+v", c) log.Fatalf("vars: %+v", c)
} }
lib, err := database.NewMySQLConnection(c.DBUser, c.DBPass, c.DBHost, c.DBPort, c.DBName) lib, err := database.NewMySQLConnection(c.DBUser, c.DBPass, c.DBHost, c.DBPort, c.DBName)