Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmd/aem/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"github.com/spf13/cobra"
"github.com/wttech/aemc/pkg"
"os"
)

func (c *CLI) vaultCmd() *cobra.Command {
Expand All @@ -12,8 +11,10 @@ func (c *CLI) vaultCmd() *cobra.Command {
Short: "Executes Vault commands",
Run: func(cmd *cobra.Command, args []string) {
vaultCli := pkg.NewVaultCli(c.aem)
vaultCliArgs := os.Args[1:]
_ = vaultCli.CommandShell(vaultCliArgs)
if err := vaultCli.CommandShell(args); err != nil {
c.Error(err)
return
}
},
Args: cobra.ArbitraryArgs,
FParseErrWhitelist: cobra.FParseErrWhitelist{
Expand Down
21 changes: 11 additions & 10 deletions pkg/vault_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ func (v VaultCli) dir() string {
return filepath.Join(v.aem.baseOpts.ToolDir, "vault-cli")
}

func (v VaultCli) execDir() string {
func (v VaultCli) execFile() string {
vaultDir, _, _ := strings.Cut(filepath.Base(v.DownloadURL), "-bin")
return filepath.Join(v.dir(), vaultDir, "bin")
execDir := filepath.Join(v.dir(), vaultDir, "bin")
if osx.IsWindows() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you checked this on windows?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return pathx.Canonical(execDir + "/vlt.bat")
}
return pathx.Canonical(execDir + "/vlt")
}

func (v VaultCli) lock() osx.Lock[VaultCliLock] {
Expand All @@ -60,12 +64,10 @@ func (v VaultCli) Prepare() error {
return nil
}
log.Infof("preparing new Vault '%s'", v.DownloadURL)
err = v.prepare()
if err != nil {
if err = v.prepare(); err != nil {
return err
}
err = lock.Lock()
if err != nil {
if err = lock.Lock(); err != nil {
return err
}
log.Infof("prepared new Vault '%s'", v.DownloadURL)
Expand Down Expand Up @@ -100,11 +102,10 @@ func (v VaultCli) CommandShell(args []string) error {
if err := v.Prepare(); err != nil {
return fmt.Errorf("cannot prepare Vault before running command: %w", err)
}
cmd := execx.CommandShell(args)
cmd.Dir = v.execDir()
vaultCliArgs := append([]string{v.execFile()}, args...)
cmd := execx.CommandShell(vaultCliArgs)
v.aem.CommandOutput(cmd)
err := cmd.Run()
if err != nil {
if err := cmd.Run(); err != nil {
return fmt.Errorf("cannot run Vault command: %w", err)
}
return nil
Expand Down
Loading