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

Default path is pwd for grep and replace #95

Merged
merged 1 commit into from
Apr 10, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master - unreleased

ENHANCEMENTS:

* In interactive mode, assume path for command is pwd for grep and replace ([#95](https://github.com/fishi0x01/vsh/pull/95))

## v0.11.0 (February 27, 2021)

ENHANCEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Working on vault secrets can be critical, making quality and correct behavior a
That being said, `vsh` is still a small open source project, meaning we cannot give any guarantees.
However, we put strong emphasis on test-driven development.
Every PR is tested with an extensive [suite](test/suites) of integration tests.
Vast majority of tests run on KV1 and KV2 and every test runs against vault `1.0.0` and `1.6.2`, i.e., vault versions in between should also be compatible.
Vast majority of tests run on KV1 and KV2 and every test runs against vault `1.0.0` and `1.6.3`, i.e., vault versions in between should also be compatible.

## Contributions

Expand Down
5 changes: 4 additions & 1 deletion cli/grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type GrepCommand struct {
// GrepCommandArgs provides a struct for go-arg parsing
type GrepCommandArgs struct {
Search string `arg:"positional,required"`
Path string `arg:"positional,required"`
Path string `arg:"positional"`
Regexp bool `arg:"-e,--regexp" help:"Treat search string as a regexp"`
Keys bool `arg:"-k,--keys" help:"Match against keys (true if -v is not specified)"`
Values bool `arg:"-v,--values" help:"Match against values (true if -k is not specified)"`
Expand Down Expand Up @@ -67,6 +67,9 @@ func (cmd *GrepCommand) Parse(args []string) error {
if err != nil {
return err
}
if cmd.args.Path == "" {
cmd.args.Path = cmd.client.Pwd
}
if cmd.args.Keys == true {
cmd.Mode |= ModeKeys
}
Expand Down
5 changes: 4 additions & 1 deletion cli/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ReplaceCommand struct {
type ReplaceCommandArgs struct {
Search string `arg:"positional,required"`
Replacement string `arg:"positional,required"`
Path string `arg:"positional,required"`
Path string `arg:"positional"`
Regexp bool `arg:"-e,--regexp" help:"Treat search string and selector as a regexp"`
KeySelector string `arg:"-s,--key-selector" help:"Limit replacements to specified key" placeholder:"PATTERN"`
Keys bool `arg:"-k,--keys" help:"Match against keys (true if -v is not specified)"`
Expand Down Expand Up @@ -85,6 +85,9 @@ func (cmd *ReplaceCommand) Parse(args []string) error {
if err != nil {
return err
}
if cmd.args.Path == "" {
cmd.args.Path = cmd.client.Pwd
}
if cmd.args.Keys == true {
cmd.Mode |= ModeKeys
}
Expand Down
2 changes: 1 addition & 1 deletion test/run-all-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e # required to fail test suite when a single test fails

VAULT_VERSIONS=("1.6.2" "1.0.0")
VAULT_VERSIONS=("1.6.3" "1.0.0")
KV_BACKENDS=("KV1" "KV2")

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
Expand Down
2 changes: 1 addition & 1 deletion test/run-single-test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e # required to fail test suite when a single test fails

VAULT_VERSION=${VAULT_VERSION:-"1.6.2"}
VAULT_VERSION=${VAULT_VERSION:-"1.6.3"}
KV_BACKEND=${KV_BACKEND:-"KV2"}
TEST_SUITE=${TEST_SUITE:-"commands/cp"}

Expand Down
7 changes: 7 additions & 0 deletions test/suites/commands/grep.bats
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ load ../../bin/plugins/bats-assert/load
assert_line --partial "unknown argument --foo"
assert_failure 1

#######################################
echo "==== case: match in pwd ===="
export VAULT_PATH=${KV_BACKEND}/src/dev
run ${APP_BIN} -c "grep 'apple' -v"
unset VAULT_PATH
assert_line --partial "/${KV_BACKEND}/src/dev/1"

#######################################
echo "==== TODO case: grep term on directory with reduced permissions ===="

Expand Down
10 changes: 10 additions & 0 deletions test/suites/commands/replace.bats
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,14 @@ load ../../bin/plugins/bats-assert/load
run ${APP_BIN} -c "replace -e -s '][' '^apple' 'orange' ${KV_BACKEND}/src/selector/1 -y"
assert_failure
assert_line --partial "key-selector: error parsing regexp"

#######################################
echo "==== case: replace in pwd ===="
export VAULT_PATH=${KV_BACKEND}/src/a
run ${APP_BIN} -c "replace 'long-value' 'interesting-value' -y"
assert_success
assert_line "Writing!"
unset VAULT_PATH
run get_vault_value "long" "${KV_BACKEND}/src/a/foo"
assert_line this-is-a-really-interesting-value-for-testing
}