Skip to content

Commit

Permalink
Add option to skip auto fix in Frogbot scan repository (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Sep 15, 2024
1 parent 70e1046 commit 5402418
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scanrepository/scanrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ func (cfp *ScanRepositoryCmd) scanAndFixProject(repository *utils.Repository) er
}
vulnerabilitiesByPathMap[fullPathWd] = currPathVulnerabilities
}
if fixNeeded {
if repository.DetectionOnly {
log.Info(fmt.Sprintf("This command is running in detection mode only. To enable automatic fixing of issues, set the '%s' environment variable to 'false'.", utils.DetectionOnlyEnv))
} else if fixNeeded {
return cfp.fixVulnerablePackages(repository, vulnerabilitiesByPathMap)
}
return nil
Expand Down
1 change: 1 addition & 0 deletions utils/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
DepsRepoEnv = "JF_DEPS_REPO"
MinSeverityEnv = "JF_MIN_SEVERITY"
FixableOnlyEnv = "JF_FIXABLE_ONLY"
DetectionOnlyEnv = "JF_SKIP_AUTOFIX"
AllowedLicensesEnv = "JF_ALLOWED_LICENSES"
WatchesDelimiter = ","

Expand Down
6 changes: 6 additions & 0 deletions utils/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (p *Project) setDefaultsIfNeeded() error {
type Scan struct {
IncludeAllVulnerabilities bool `yaml:"includeAllVulnerabilities,omitempty"`
FixableOnly bool `yaml:"fixableOnly,omitempty"`
DetectionOnly bool `yaml:"skipAutoFix,omitempty"`
FailOnSecurityIssues *bool `yaml:"failOnSecurityIssues,omitempty"`
AvoidPreviousPrCommentsDeletion bool `yaml:"avoidPreviousPrCommentsDeletion,omitempty"`
MinSeverity string `yaml:"minSeverity,omitempty"`
Expand Down Expand Up @@ -193,6 +194,11 @@ func (s *Scan) setDefaultsIfNeeded() (err error) {
return
}
}
if !s.DetectionOnly {
if s.DetectionOnly, err = getBoolEnv(DetectionOnlyEnv, false); err != nil {
return
}
}
if s.FailOnSecurityIssues == nil {
var failOnSecurityIssues bool
if failOnSecurityIssues, err = getBoolEnv(FailOnSecurityIssuesEnv, true); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions utils/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func TestExtractAndAssertRepoParams(t *testing.T) {
GitEmailAuthorEnv: "myemail@jfrog.com",
MinSeverityEnv: "high",
FixableOnlyEnv: "true",
DetectionOnlyEnv: "true",
AllowedLicensesEnv: "MIT, Apache-2.0, ISC",
AvoidExtraMessages: "true",
})
Expand Down Expand Up @@ -195,6 +196,7 @@ func TestExtractAndAssertRepoParams(t *testing.T) {
assert.Equal(t, "this is my branch {BRANCH_NAME_HASH}", templates.branchNameTemplate)
assert.Equal(t, "High", repo.MinSeverity)
assert.True(t, repo.FixableOnly)
assert.True(t, repo.DetectionOnly)
assert.Equal(t, true, repo.AggregateFixes)
assert.Equal(t, "myemail@jfrog.com", repo.EmailAuthor)
assert.Equal(t, "build 1323", repo.PullRequestCommentTitle)
Expand Down Expand Up @@ -347,6 +349,7 @@ func TestGenerateConfigAggregatorFromEnv(t *testing.T) {
FailOnSecurityIssuesEnv: "false",
MinSeverityEnv: "medium",
FixableOnlyEnv: "true",
DetectionOnlyEnv: "true",
AllowedLicensesEnv: "MIT, Apache-2.0",
AvoidExtraMessages: "true",
PullRequestCommentTitleEnv: "build 1323",
Expand Down Expand Up @@ -389,6 +392,7 @@ func validateBuildRepoAggregator(t *testing.T, repo *Repository, gitParams *Git,
assert.Equal(t, false, *repo.FailOnSecurityIssues)
assert.Equal(t, "Medium", repo.MinSeverity)
assert.Equal(t, true, repo.FixableOnly)
assert.Equal(t, true, repo.DetectionOnly)
assert.ElementsMatch(t, []string{"MIT", "Apache-2.0"}, repo.AllowedLicenses)
assert.Equal(t, gitParams.RepoOwner, repo.RepoOwner)
assert.Equal(t, gitParams.Token, repo.Token)
Expand Down

0 comments on commit 5402418

Please sign in to comment.