/* * Sicherheitsunterweisung * Copyright (C) 2023 Jason Streifling * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see . */ package data import ( "bufio" "fmt" "os" "strings" "syscall" "golang.org/x/term" ) func getUsername() (string, error) { user := os.Getenv("DB_USER") if user == "" { var err error fmt.Printf("DB Benutzer: ") user, err = bufio.NewReader(os.Stdin).ReadString('\n') if err != nil { return "", fmt.Errorf("error: getUsername: bufio.NewReader().ReadString(): %v", err) } } return strings.TrimSpace(user), nil } func getPassword() (string, error) { pass := os.Getenv("DB_PASS") if pass == "" { fmt.Printf("DB Passwort: ") bytePass, err := term.ReadPassword(int(syscall.Stdin)) if err != nil { return "", fmt.Errorf("error: getPassword: term.ReadPassword(): %v", err) } fmt.Println() pass = strings.TrimSpace(string(bytePass)) } return pass, nil } func getCredentials() (string, string, error) { user, err := getUsername() if err != nil { return "", "", fmt.Errorf("error: getCredentials: getUsername(): %v", err) } pass, err := getPassword() if err != nil { return "", "", fmt.Errorf("error: getCredentials: getPassword(): %v", err) } return user, pass, nil }