Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
pipeline: goimports cmd calls need to use hard-coded string, otherwis…
Browse files Browse the repository at this point in the history
…e gosec does not accept them

Signed-off-by: Muvaffak Onus <me@muvaf.com>
  • Loading branch information
muvaf committed Nov 16, 2021
1 parent 6d4b1ef commit 6d20ea2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/pipeline/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,17 @@ func Run(pc *config.Provider, rootDir string) { // nolint:gocyclo
if err := NewSetupGenerator(rootDir, pc.ModulePath).Generate(controllerPkgList); err != nil {
panic(errors.Wrap(err, "cannot generate setup file"))
}
apisDir := filepath.Clean(filepath.Join(rootDir, "apis"))
internalDir := filepath.Clean(filepath.Join(rootDir, "internal"))
if out, err := exec.Command("bash", "-c", fmt.Sprintf("goimports -w $(find %s -iname 'zz_*')", apisDir)).CombinedOutput(); err != nil {

// NOTE(muvaf): gosec linter requires that the whole command is hard-coded.
// So, we set the directory of the command instead of passing in the directory
// as an argument to "find".
goimportsCmd := exec.Command("bash", "-c", "goimports -w $(find . -iname 'zz_*')")
goimportsCmd.Dir = filepath.Clean(filepath.Join(rootDir, "apis"))
if out, err := goimportsCmd.CombinedOutput(); err != nil {
panic(errors.Wrap(err, "cannot run goimports for apis folder: "+string(out)))
}
if out, err := exec.Command("bash", "-c", fmt.Sprintf("goimports -w $(find %s -iname 'zz_*')", internalDir)).CombinedOutput(); err != nil {
goimportsCmd.Dir = filepath.Clean(filepath.Join(rootDir, "internal"))
if out, err := goimportsCmd.CombinedOutput(); err != nil {
panic(errors.Wrap(err, "cannot run goimports for internal folder: "+string(out)))
}

Expand Down

0 comments on commit 6d20ea2

Please sign in to comment.