Skip to content

Commit c37daae

Browse files
author
Matt Kulka
committed
codeclimate feedback
1 parent 0ccdd01 commit c37daae

File tree

6 files changed

+30
-37
lines changed

6 files changed

+30
-37
lines changed

Diff for: cli/grep.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (cmd *GrepCommand) Run() int {
9999
return 1
100100
}
101101

102-
matches, err := cmd.grepPaths(cmd.args.Search, filePaths)
102+
matches, err := cmd.searcher.grepPaths(cmd.client, cmd.args.Search, filePaths)
103103
if err != nil {
104104
return 1
105105
}
@@ -117,12 +117,3 @@ func (cmd *GrepCommand) GetSearchParams() SearchParameters {
117117
IsRegexp: cmd.args.Regexp,
118118
}
119119
}
120-
121-
func (cmd *GrepCommand) grepPaths(search string, paths []string) (matches []*Match, err error) {
122-
return funcOnPaths(cmd.client, paths, func(s *client.Secret) []*Match {
123-
for k, v := range s.GetData() {
124-
matches = append(matches, cmd.searcher.DoSearch(s.Path, k, fmt.Sprintf("%v", v))...)
125-
}
126-
return matches
127-
})
128-
}

Diff for: cli/replace.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,9 @@ func (cmd *ReplaceCommand) Run() int {
128128
return cmd.commitMatches(allMatches)
129129
}
130130

131-
func (cmd *ReplaceCommand) grepPaths(search string, paths []string) (matches []*Match, err error) {
132-
return funcOnPaths(cmd.client, paths, func(s *client.Secret) []*Match {
133-
for k, v := range s.GetData() {
134-
matches = append(matches, cmd.searcher.DoSearch(s.Path, k, fmt.Sprintf("%v", v))...)
135-
}
136-
return matches
137-
})
138-
}
139-
140131
// FindMatches will return a map of files sorted by path in which the search occurs
141132
func (cmd *ReplaceCommand) FindMatches(filePaths []string) (matchesByPath map[string][]*Match, err error) {
142-
matches, err := cmd.grepPaths(cmd.args.Search, filePaths)
133+
matches, err := cmd.searcher.grepPaths(cmd.client, cmd.args.Search, filePaths)
143134
if err != nil {
144135
return matchesByPath, err
145136
}
@@ -187,7 +178,7 @@ func (cmd *ReplaceCommand) commitMatches(matchesByPath map[string][]*Match) int
187178
func (cmd *ReplaceCommand) WriteReplacements(groupedMatches map[string][]*Match) error {
188179
// Re-read paths because they could've gone stale
189180
paths := make([]string, 0)
190-
for path, _ := range groupedMatches {
181+
for path := range groupedMatches {
191182
paths = append(paths, path)
192183
}
193184
secrets, err := cmd.client.BatchRead(paths)

Diff for: cli/search.go

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/andreyvit/diff"
1212
"github.com/fatih/color"
13+
"github.com/fishi0x01/vsh/client"
1314
)
1415

1516
// SearchingCommand interface to describe a command that performs a search operation
@@ -258,3 +259,12 @@ func (s *Searcher) matchData(subject string) (matchPairs [][]int, replaced strin
258259

259260
return matchPairs, replaced
260261
}
262+
263+
func (s *Searcher) grepPaths(c *client.Client, search string, paths []string) (matches []*Match, err error) {
264+
return funcOnPaths(c, paths, func(secret *client.Secret) []*Match {
265+
for k, v := range secret.GetData() {
266+
matches = append(matches, s.DoSearch(secret.Path, k, fmt.Sprintf("%v", v))...)
267+
}
268+
return matches
269+
})
270+
}

Diff for: client/batch.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,43 @@ type BatchOperation int
99

1010
// types of operations
1111
const (
12-
OP_READ BatchOperation = 0
13-
OP_WRITE BatchOperation = 1
12+
OpRead BatchOperation = 0
13+
OpWrite BatchOperation = 1
1414
)
1515

1616
// how many worker threads to use for batch operations
1717
const (
18-
VAULT_CONCURENCY = 5
18+
VaultConcurency = 5
1919
)
2020

2121
// BatchOperation can perform reads or writes with concurrency
2222
func (client *Client) BatchOperation(absolutePaths []string, op BatchOperation, secretsIn []*Secret) (secrets []*Secret, err error) {
23-
read_queue := make(chan string, len(absolutePaths))
24-
write_queue := make(chan *Secret, len(absolutePaths))
23+
readQueue := make(chan string, len(absolutePaths))
24+
writeQueue := make(chan *Secret, len(absolutePaths))
2525
results := make(chan *secretOperation, len(absolutePaths))
2626

2727
// load up queue for operation
2828
switch op {
29-
case OP_READ:
29+
case OpRead:
3030
for _, path := range absolutePaths {
31-
read_queue <- path
31+
readQueue <- path
3232
}
33-
case OP_WRITE:
33+
case OpWrite:
3434
for _, secret := range secretsIn {
35-
write_queue <- secret
35+
writeQueue <- secret
3636
}
3737
default:
3838
return nil, fmt.Errorf("invalid batch operation")
3939
}
4040

4141
// fire off goroutines for operation
42-
for i := 0; i < VAULT_CONCURENCY; i++ {
42+
for i := 0; i < VaultConcurency; i++ {
4343
client.waitGroup.Add(1)
4444
switch op {
45-
case OP_READ:
46-
go client.readWorker(read_queue, results)
47-
case OP_WRITE:
48-
go client.writeWorker(write_queue, results)
45+
case OpRead:
46+
go client.readWorker(readQueue, results)
47+
case OpWrite:
48+
go client.writeWorker(writeQueue, results)
4949
}
5050
}
5151
client.waitGroup.Wait()

Diff for: client/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (client *Client) Read(absolutePath string) (secret *Secret, err error) {
120120

121121
// BatchRead returns secrets for given paths
122122
func (client *Client) BatchRead(absolutePaths []string) (secrets []*Secret, err error) {
123-
return client.BatchOperation(absolutePaths, OP_READ, make([]*Secret, 0))
123+
return client.BatchOperation(absolutePaths, OpRead, make([]*Secret, 0))
124124
}
125125

126126
// Write writes secret to given path, using given Client
@@ -136,7 +136,7 @@ func (client *Client) Write(absolutePath string, secret *Secret) (err error) {
136136

137137
// BatchWrite writes provided secrets to Vault
138138
func (client *Client) BatchWrite(absolutePaths []string, secrets []*Secret) (err error) {
139-
_, err = client.BatchOperation(absolutePaths, OP_WRITE, secrets)
139+
_, err = client.BatchOperation(absolutePaths, OpWrite, secrets)
140140
return err
141141
}
142142

Diff for: client/type.go

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func (client *Client) topLevelType(path string) PathKind {
2626
}
2727
}
2828

29+
// FilterPaths reduces an array of paths to only include the specified type (leaf vs node)
2930
func (client *Client) FilterPaths(paths []string, kind PathKind) (filtered []string) {
3031
for _, path := range paths {
3132
if client.GetType(path) == kind {

0 commit comments

Comments
 (0)