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

skip policy download if -p flag used #1210

Merged
merged 1 commit into from
Mar 31, 2022
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
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"))
})
})
})
})