From 708a4853fa8e5bd50e296aeeb8a280302edc9404 Mon Sep 17 00:00:00 2001 From: Jacob Wernette Date: Fri, 22 Jan 2021 13:43:04 -0500 Subject: [PATCH] fix: Set token before writing to file, silent fail if error (#39) --- pkg/vault/util.go | 14 +++++++------- pkg/vault/utils_test.go | 7 ++----- version/version.go | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pkg/vault/util.go b/pkg/vault/util.go index 297b2ee6..8ab0f9b1 100644 --- a/pkg/vault/util.go +++ b/pkg/vault/util.go @@ -2,6 +2,7 @@ package vault import ( "encoding/json" + "fmt" "io/ioutil" "os" "path/filepath" @@ -51,10 +52,13 @@ func Login(vaultClient VaultType, vaultConfig *Config) error { } // SetToken TODO -func SetToken(client *Client, token string) error { +func SetToken(client *Client, token string) { + // We want to set the token first + client.VaultAPIClient.SetToken(token) + home, err := os.UserHomeDir() if err != nil { - return err + fmt.Printf("Could not access home directory, will need to login to Vault on subsequent runs: %s", err.Error()) } path := filepath.Join(home, ".avp") @@ -68,10 +72,6 @@ func SetToken(client *Client, token string) error { file, _ := json.MarshalIndent(data, "", " ") err = ioutil.WriteFile(filepath.Join(path, "config.json"), file, 0644) if err != nil { - return err + fmt.Printf("Could not write token to file, will need to login to Vault on subsequent runs: %s", err.Error()) } - - client.VaultAPIClient.SetToken(token) - - return nil } diff --git a/pkg/vault/utils_test.go b/pkg/vault/utils_test.go index ee940cae..7dc00180 100644 --- a/pkg/vault/utils_test.go +++ b/pkg/vault/utils_test.go @@ -56,12 +56,9 @@ func TestSetToken(t *testing.T) { VaultAPIClient: cluster.Cores[0].Client, } - err := vault.SetToken(vc, "token") - if err != nil { - t.Errorf("expected token to be written, got: %s.", err) - } + vault.SetToken(vc, "token") - err = removeToken() + err := removeToken() if err != nil { t.Fatal(err) } diff --git a/version/version.go b/version/version.go index d014a47d..be70c402 100644 --- a/version/version.go +++ b/version/version.go @@ -2,5 +2,5 @@ package version var ( // Version is the argocd-vault-plugin version. - Version = "v0.2.0" + Version = "v0.2.1" )