Skip to content

Commit

Permalink
skip policy download if used -p flag and skip docker login on non mas…
Browse files Browse the repository at this point in the history
…ter branch (#1210)

Co-authored-by: Suvarna Rokade <suvarna.rokade@accurics.com>
  • Loading branch information
Rchanger and Suvarna Rokade committed Mar 31, 2022
1 parent 655761a commit a6a6a37
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/gobuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ jobs:
run: make docker-build

- name: Login to docker hub
# login to docker hub only from master
if: ${{ github.ref == 'refs/heads/master' }}
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u accurics --password-stdin

- name: Push Terrascan latest docker image
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ var scanCmd = &cobra.Command{
Detect compliance and security violations across Infrastructure as Code to mitigate risk before provisioning cloud native infrastructure.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if scanOptions.configOnly || scanOptions.configWithError {
if scanOptions.configOnly || scanOptions.configWithError ||
len(scanOptions.policyPath) > 0 {
return nil
}
return initial(cmd, args, true)
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/scan/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"path/filepath"

"github.com/accurics/terrascan/pkg/config"
"github.com/accurics/terrascan/pkg/policy"
"github.com/accurics/terrascan/pkg/utils"
scanUtils "github.com/accurics/terrascan/test/e2e/scan"
Expand Down Expand Up @@ -345,4 +346,23 @@ var _ = Describe("Scan", func() {
})
})
})
Describe("terrascan scan command run with policy-path", func() {
Context("terrascan scan command is run with --p flag", func() {
It("should scan and should use provided policies without downloading any from default repo", func() {
if path, err := os.Stat(config.GetPolicyRepoPath()); err == nil && path.IsDir() {
os.RemoveAll(config.GetPolicyRepoPath())
}
iacDir, err1 := filepath.Abs(filepath.Join(awsIacRelPath, "aws_ami_violation"))
policyDir, err2 := filepath.Abs(policyRootRelPath)
Expect(err1).NotTo(HaveOccurred())
Expect(err2).NotTo(HaveOccurred())
scanArgs := []string{"scan", "-p", policyDir, "-i", "terraform", "-d", iacDir}
session := helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, scanArgs...)
Eventually(session, 3).Should(gexec.Exit(helper.ExitCodeThree))
_, err := os.Stat(config.GetPolicyRepoPath())
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("no such file or directory"))
})
})
})
})

0 comments on commit a6a6a37

Please sign in to comment.