diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-10-04 00:09:34 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-10-04 00:09:34 +0530 |
commit | 50f211800946318ff4e3c40c1fc497c149b0380d (patch) | |
tree | d4a8f15f05c1b21749593495c99437aad5385b04 /auth/auth.go | |
parent | 1b45e30a8f0cbeb8b28a1464dc4342bffa958627 (diff) |
Use the macli.toml file to store and get login info automatically
Diffstat (limited to 'auth/auth.go')
-rw-r--r-- | auth/auth.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/auth/auth.go b/auth/auth.go index 5a768ff..15ad854 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -26,6 +26,7 @@ import ( "errors" "fmt" "github.com/zalando/go-keyring" + "github.com/spf13/viper" ) var serviceName string = "macli" @@ -43,10 +44,16 @@ func init() { // asks for all the details func Login(tk, clientId string, storeClientId bool) { - /* check if an auth token already exists - * if there is an error with keyring, askClientId would handle it - * can safely ignore error here */ - existingToken, _ := keyring.Get(serviceName, userName) + // check if an auth token already exists + var existingToken string + if NoSysKeyring { + existingToken = viper.GetString("auth.token") + } else { + /* if there is an error with keyring, askClientId would handle it + * can safely ignore error here */ + existingToken, _ = keyring.Get(serviceName, userName) + } + if existingToken != "" { if !confirmInput("Already logged in. Log in again? [Y/n] ", true) { fmt.Println("Login process aborted") |