Skip to content

Commit

Permalink
fix: Set token before writing to file, silent fail if error (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
werne2j authored Jan 22, 2021
1 parent c358e9e commit 708a485
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
14 changes: 7 additions & 7 deletions pkg/vault/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vault

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -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")
Expand All @@ -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
}
7 changes: 2 additions & 5 deletions pkg/vault/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package version

var (
// Version is the argocd-vault-plugin version.
Version = "v0.2.0"
Version = "v0.2.1"
)

0 comments on commit 708a485

Please sign in to comment.