From 50f211800946318ff4e3c40c1fc497c149b0380d Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 4 Oct 2022 00:09:34 +0530 Subject: Use the macli.toml file to store and get login info automatically --- auth/auth.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'auth/auth.go') 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") -- cgit v1.2.3