aboutsummaryrefslogtreecommitdiff
path: root/auth/client.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-10-04 00:09:34 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-10-04 00:09:34 +0530
commit50f211800946318ff4e3c40c1fc497c149b0380d (patch)
treed4a8f15f05c1b21749593495c99437aad5385b04 /auth/client.go
parent1b45e30a8f0cbeb8b28a1464dc4342bffa958627 (diff)
Use the macli.toml file to store and get login info automatically
Diffstat (limited to 'auth/client.go')
-rw-r--r--auth/client.go30
1 files changed, 28 insertions, 2 deletions
diff --git a/auth/client.go b/auth/client.go
index 6ec75ca..5a3e501 100644
--- a/auth/client.go
+++ b/auth/client.go
@@ -22,15 +22,36 @@ import (
"os"
"fmt"
"github.com/zalando/go-keyring"
+ "github.com/spf13/viper"
+ "errors"
)
var clientSuffix string = "-client-id"
func getClientId() (string, error) {
- return keyring.Get(serviceName + clientSuffix, userName)
+ var id string
+ var err error
+
+
+ if NoSysKeyring {
+ id = viper.GetString("auth.client_id")
+ if id == "" {
+ err = errors.New("secret not found in keyring")
+ }
+ } else {
+ id, err = keyring.Get(serviceName + clientSuffix, userName)
+ }
+
+ return id, err
}
func setClientId(clientId string) {
+ if NoSysKeyring {
+ defer viper.WriteConfig()
+ viper.Set("auth.client_id", clientId)
+ return
+ }
+
err := keyring.Set(serviceName + clientSuffix, userName, clientId)
if err != nil {
fmt.Println("Error while writing Client ID to keychain", err)
@@ -39,9 +60,14 @@ func setClientId(clientId string) {
}
func deleteClientId() {
+ if NoSysKeyring {
+ defer viper.WriteConfig()
+ viper.Set("auth.client_id", "")
+ }
+
err := keyring.Delete(serviceName + clientSuffix, userName)
// if secret doesnt exist dont show error
- if err != nil {
+ if err != nil && !NoSysKeyring {
if err.Error() != "secret not found in keyring" {
fmt.Println("Error while deleting Client ID", err.Error())
os.Exit(1)