Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Unify behavior of verbose #41

Merged
merged 5 commits into from
Jun 17, 2020
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
6 changes: 4 additions & 2 deletions cli/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cli

import (
"fmt"
"github.com/fishi0x01/vsh/client"
"io"

"github.com/fishi0x01/vsh/client"
"github.com/fishi0x01/vsh/log"
)

// CatCommand container for all 'cat' parameters
Expand Down Expand Up @@ -70,7 +72,7 @@ func (cmd *CatCommand) Run() {
}
}
} else {
fmt.Fprintln(cmd.stderr, cmd.client.Pwd+cmd.Path, "is not a file")
log.Error("%s%s is not a file", cmd.client.Pwd, cmd.Path)
}

return
Expand Down
8 changes: 5 additions & 3 deletions cli/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cli

import (
"fmt"
"github.com/fishi0x01/vsh/client"
"io"

"github.com/fishi0x01/vsh/client"
"github.com/fishi0x01/vsh/log"
)

// CdCommand container for all 'cd' parameters
Expand Down Expand Up @@ -54,12 +56,12 @@ func (cmd *CdCommand) Run() {
t := cmd.client.GetType(newPwd)

if t == client.NONE {
fmt.Fprintln(cmd.stderr, "Not a valid directory: "+newPwd)
log.Error("Invalid directory: %s", newPwd)
return
}

if t == client.LEAF {
fmt.Fprintln(cmd.stderr, "Not a valid directory: "+newPwd+" is a file")
log.Error("Invalid directory: %s is a file", newPwd)
return
}

Expand Down
5 changes: 3 additions & 2 deletions cli/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"

"github.com/fishi0x01/vsh/client"
"github.com/fishi0x01/vsh/log"
)

// CopyCommand container for all 'cp' parameters
Expand Down Expand Up @@ -57,7 +58,7 @@ func (cmd *CopyCommand) Run() {

t := cmd.client.GetType(newSrcPwd)
if t != client.NODE && t != client.LEAF {
fmt.Fprintln(cmd.stderr, "Not a valid source path: "+newSrcPwd)
log.Error("Invalid source path: %s", newSrcPwd)
return
}

Expand All @@ -79,7 +80,7 @@ func (cmd *CopyCommand) copySecret(source string, target string) error {
return err
}

fmt.Fprintln(cmd.stdout, "Copied "+source+" to "+target)
log.Info("Copied %s to %s", source, target)

return nil
}
8 changes: 5 additions & 3 deletions cli/grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package cli

import (
"fmt"
"github.com/fatih/color"
"github.com/fishi0x01/vsh/client"
"index/suffixarray"
"io"
"sort"

"github.com/fatih/color"
"github.com/fishi0x01/vsh/client"
"github.com/fishi0x01/vsh/log"
)

// GrepCommand container for all 'grep' parameters
Expand Down Expand Up @@ -69,7 +71,7 @@ func (cmd *GrepCommand) Run() {

t := cmd.client.GetType(path)
if t != client.NODE && t != client.LEAF {
fmt.Fprintln(cmd.stderr, "Not a valid path: "+path)
log.Error("Invalid path: %s", path)
return
}

Expand Down
6 changes: 4 additions & 2 deletions cli/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package cli

import (
"fmt"
"github.com/fishi0x01/vsh/client"
"io"
"strings"

"github.com/fishi0x01/vsh/client"
"github.com/fishi0x01/vsh/log"
)

// ListCommand container for 'ls' parameters
Expand Down Expand Up @@ -57,7 +59,7 @@ func (cmd *ListCommand) Run() {
result, err := cmd.client.List(newPwd)

if err != nil {
fmt.Println(err)
log.Error("%w", err)
} else {
fmt.Fprintln(cmd.stdout, strings.Join(result, "\n"))
}
Expand Down
8 changes: 5 additions & 3 deletions cli/mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cli

import (
"fmt"
"github.com/fishi0x01/vsh/client"
"io"

"github.com/fishi0x01/vsh/client"
"github.com/fishi0x01/vsh/log"
)

// MoveCommand container for all 'mv' parameters
Expand Down Expand Up @@ -56,7 +58,7 @@ func (cmd *MoveCommand) Run() {

t := cmd.client.GetType(newSrcPwd)
if t != client.NODE && t != client.LEAF {
fmt.Fprintln(cmd.stderr, "Not a valid source path: "+newSrcPwd)
log.Error("Invalid source path: %s", newSrcPwd)
return
}

Expand All @@ -83,7 +85,7 @@ func (cmd *MoveCommand) moveSecret(source string, target string) error {
return err
}

fmt.Fprintln(cmd.stdout, "Moved "+source+" to "+target)
log.Info("Moved %s to %s", source, target)

return nil
}
8 changes: 5 additions & 3 deletions cli/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cli

import (
"fmt"
"github.com/fishi0x01/vsh/client"
"io"

"github.com/fishi0x01/vsh/client"
"github.com/fishi0x01/vsh/log"
)

// RemoveCommand container for all 'rm' parameters
Expand Down Expand Up @@ -62,7 +64,7 @@ func (cmd *RemoveCommand) Run() {
}
}
default:
fmt.Fprintln(cmd.stderr, "Not a valid path: "+newPwd)
log.Error("Invalid path: %s", newPwd)
}
}

Expand All @@ -73,7 +75,7 @@ func (cmd *RemoveCommand) removeSecret(path string) error {
return err
}

fmt.Fprintln(cmd.stdout, "Removed "+path)
log.Info("Removed %s", path)

return nil
}
8 changes: 4 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package client

import (
"errors"
"fmt"
"github.com/fishi0x01/vsh/log"
"github.com/hashicorp/vault/api"
"strconv"
"strings"

"github.com/fishi0x01/vsh/log"
"github.com/hashicorp/vault/api"
)

// Client wrapper for Vault API client
Expand Down Expand Up @@ -65,7 +65,7 @@ func NewClient(conf *VaultConfig) (*Client, error) {
if sliceContains(permissions, "list") || sliceContains(permissions, "root") {
mounts, err = vault.Sys().ListMounts()
} else {
fmt.Println("Cannot auto-discover mount backends: Token does not have list permission on sys/mounts")
log.Debug("Cannot auto-discover mount backends: Token does not have list permission on sys/mounts")
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func executor(in string) {
fmt.Fprint(os.Stdout, "")
return
default:
fmt.Fprintln(os.Stderr, "Unknown command '"+args[0]+"'")
log.Error("Unknown command '%s'", args[0])
return
}

Expand Down
2 changes: 1 addition & 1 deletion test/command-tests/ls.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ load ../bin/plugins/bats-assert/load

#######################################
echo "==== case: list backends with reduced permissions ===="
run bash -c "VAULT_TOKEN=reduced ${APP_BIN} -c 'ls /'"
run bash -c "VAULT_TOKEN=reduced ${APP_BIN} -v -c 'ls /'"
assert_success
assert_output --partial "Cannot auto-discover mount backends"

Expand Down
4 changes: 2 additions & 2 deletions test/special-tests/params.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ load ../bin/plugins/bats-assert/load
@test "vault-${VAULT_VERSION} whitespaces between parameters" {
#######################################
echo "==== case: copy with multiple whitespaces ===="
run ${APP_BIN} -c "cp /KV2/src/prod/all /KV2/dest/prod/all"
run ${APP_BIN} -v -c "cp /KV2/src/prod/all /KV2/dest/prod/all"
assert_success
assert_output --partial "Copied /KV2/src/prod/all to /KV2/dest/prod/all"

echo "==== case: copy with tabs ===="
run ${APP_BIN} -c "cp /KV2/src/prod/all /KV2/dest/prod/all "
run ${APP_BIN} -v -c "cp /KV2/src/prod/all /KV2/dest/prod/all "
assert_success
assert_output --partial "Copied /KV2/src/prod/all to /KV2/dest/prod/all"

Expand Down