Skip to content

Commit fb46e6c

Browse files
committed
fix static check
1 parent b3fbf03 commit fb46e6c

File tree

20 files changed

+119
-104
lines changed

20 files changed

+119
-104
lines changed

artifactory_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@ func getTestCdxFile(t *testing.T, tempDir string) string {
368368
cdxFilePath := filepath.Join(tempDir, fmt.Sprintf("upload-integration-test-%s.cdx.json", utils.GetCurrentTimeUnix()))
369369
file, err := os.Create(cdxFilePath)
370370
assert.NoError(t, err)
371-
defer file.Close()
371+
defer func() {
372+
assert.NoError(t, file.Close())
373+
}()
372374
// Write the BOM to the file
373375
assert.NoError(t, cyclonedx.NewBOMEncoder(file, cyclonedx.BOMFileFormatJSON).SetPretty(true).Encode(bom))
374376
return cdxFilePath

audit_test.go

Lines changed: 45 additions & 46 deletions
Large diffs are not rendered by default.

commands/audit/audit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func CreateAuditResultsContext(serverDetails *config.ServerDetails, xrayVersion
155155

156156
// If the user requested to include vulnerabilities, or if the user didn't provide any watches, project key, artifactory repo path or git repo key, we should include vulnerabilities.
157157
func shouldIncludeVulnerabilities(includeVulnerabilities bool, watches []string, artifactoryRepoPath, projectKey, gitRepoHttpsCloneUrl string) bool {
158-
return includeVulnerabilities || !(len(watches) > 0 || projectKey != "" || artifactoryRepoPath != "" || gitRepoHttpsCloneUrl != "")
158+
return includeVulnerabilities || len(watches) <= 0 && projectKey == "" && artifactoryRepoPath == "" && gitRepoHttpsCloneUrl == ""
159159
}
160160

161161
func (auditCmd *AuditCommand) Run() (err error) {
@@ -363,7 +363,7 @@ func initAuditCmdResults(params *AuditParams) (cmdResults *results.SecurityComma
363363
cmdResults.SetEntitledForJas(entitledForJas)
364364
}
365365
if entitledForJas {
366-
cmdResults.SetSecretValidation(jas.CheckForSecretValidation(xrayManager, params.GetXrayVersion(), slices.Contains(params.AuditBasicParams.ScansToPerform(), utils.SecretTokenValidationScan)))
366+
cmdResults.SetSecretValidation(jas.CheckForSecretValidation(xrayManager, params.GetXrayVersion(), slices.Contains(params.ScansToPerform(), utils.SecretTokenValidationScan)))
367367
}
368368
return
369369
}
@@ -560,7 +560,7 @@ func addJasScansToRunner(auditParallelRunner *utils.SecurityParallelRunner, audi
560560
jas.WithResultsToCompare(auditParams.resultsToCompare),
561561
}
562562
jasScanner, err = jas.NewJasScanner(serverDetails, scannerOptions...)
563-
jas.UpdateJasScannerWithExcludePatternsFromProfile(jasScanner, auditParams.AuditBasicParams.GetConfigProfile())
563+
jas.UpdateJasScannerWithExcludePatternsFromProfile(jasScanner, auditParams.GetConfigProfile())
564564

565565
auditParallelRunner.ResultsMu.Unlock()
566566
if err != nil {
@@ -610,7 +610,7 @@ func createJasScansTask(auditParallelRunner *utils.SecurityParallelRunner, scanR
610610
ServerDetails: serverDetails,
611611
Scanner: scanner,
612612
Module: appsConfigModule,
613-
ConfigProfile: auditParams.AuditBasicParams.GetConfigProfile(),
613+
ConfigProfile: auditParams.GetConfigProfile(),
614614
ScansToPerform: auditParams.ScansToPerform(),
615615
SourceResultsToCompare: scanner.GetResultsToCompareByRelativePath(utils.GetRelativePath(targetResult.Target, scanResults.GetCommonParentPath())),
616616
SecretsScanType: secrets.SecretsScannerType,

commands/audit/audit_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ func TestDetectScansToPerform(t *testing.T) {
197197
detectScanTargets(results, test.params())
198198
if assert.Len(t, results.Targets, len(test.expected)) {
199199
sort.Slice(results.Targets, func(i, j int) bool {
200-
return results.Targets[i].ScanTarget.Target < results.Targets[j].ScanTarget.Target
200+
return results.Targets[i].Target < results.Targets[j].Target
201201
})
202202
sort.Slice(test.expected, func(i, j int) bool {
203-
return test.expected[i].ScanTarget.Target < test.expected[j].ScanTarget.Target
203+
return test.expected[i].Target < test.expected[j].Target
204204
})
205205
for i := range results.Targets {
206206
if results.Targets[i].ScaResults != nil {

commands/scan/dockerscan.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (dsc *DockerScanCommand) Run() (err error) {
8585
Pattern(imageTarPath).
8686
Target(dsc.resultsContext.RepoPath).
8787
BuildSpec()).SetThreads(1)
88-
dsc.ScanCommand.SetTargetNameOverride(dsc.imageTag)
88+
dsc.SetTargetNameOverride(dsc.imageTag)
8989
err = dsc.setCredentialEnvsForIndexerApp()
9090
if err != nil {
9191
return errorutils.CheckError(err)
@@ -96,7 +96,7 @@ func (dsc *DockerScanCommand) Run() (err error) {
9696
err = errorutils.CheckError(e)
9797
}
9898
}()
99-
return dsc.ScanCommand.RunAndRecordResults(utils.DockerImage, func(scanResults *results.SecurityCommandResults) (err error) {
99+
return dsc.RunAndRecordResults(utils.DockerImage, func(scanResults *results.SecurityCommandResults) (err error) {
100100
if scanResults == nil {
101101
return
102102
}
@@ -106,12 +106,12 @@ func (dsc *DockerScanCommand) Run() (err error) {
106106
}
107107

108108
func (dsc *DockerScanCommand) recordResults(scanResults *results.SecurityCommandResults) (err error) {
109-
hasViolationContext := dsc.ScanCommand.resultsContext.HasViolationContext()
110-
if err = output.RecordSarifOutput(scanResults, dsc.ScanCommand.serverDetails, dsc.ScanCommand.resultsContext.IncludeVulnerabilities, hasViolationContext); err != nil {
109+
hasViolationContext := dsc.resultsContext.HasViolationContext()
110+
if err = output.RecordSarifOutput(scanResults, dsc.serverDetails, dsc.resultsContext.IncludeVulnerabilities, hasViolationContext); err != nil {
111111
return
112112
}
113113
var summary output.ScanCommandResultSummary
114-
if summary, err = output.NewDockerScanSummary(scanResults, dsc.ScanCommand.serverDetails, dsc.ScanCommand.resultsContext.IncludeVulnerabilities, hasViolationContext, dsc.imageTag); err != nil {
114+
if summary, err = output.NewDockerScanSummary(scanResults, dsc.serverDetails, dsc.resultsContext.IncludeVulnerabilities, hasViolationContext, dsc.imageTag); err != nil {
115115
return
116116
}
117117
return output.RecordSecurityCommandSummary(summary)

commands/source_mcp/source_mcp.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package source_mcp
22

33
import (
4+
"errors"
45
"fmt"
56
"io"
67
"os/exec"
@@ -28,25 +29,35 @@ type McpCommand struct {
2829
}
2930

3031
func establishPipeToFile(dst io.WriteCloser, src io.Reader) {
31-
defer dst.Close()
32+
defer func() {
33+
err := dst.Close()
34+
if err != nil {
35+
log.Error("Error closing destination pipe")
36+
}
37+
}()
3238
_, err := io.Copy(dst, src)
3339
if err != nil {
3440
log.Error("Error establishing pipe")
3541
}
3642
}
3743

3844
func establishPipeFromFile(dst io.Writer, src io.ReadCloser) {
39-
defer src.Close()
45+
defer func() {
46+
err := src.Close()
47+
if err != nil {
48+
log.Error("Error closing source pipe")
49+
}
50+
}()
4051
_, err := io.Copy(dst, src)
4152
if err != nil {
4253
log.Error("Error establishing pipe")
4354
}
4455
}
4556

46-
func RunAmMcpWithPipes(env map[string]string, cmd string, input_pipe io.Reader, output_pipe io.Writer, error_pipe io.Writer, timeout int, args ...string) error {
57+
func RunAmMcpWithPipes(env map[string]string, cmd string, input_pipe io.Reader, output_pipe io.Writer, error_pipe io.Writer, timeout int, args ...string) (err error) {
4758
am_path, err := jas.GetAnalyzerManagerExecutable()
4859
if err != nil {
49-
return err
60+
return
5061
}
5162

5263
allArgs := append([]string{cmd}, args...)
@@ -59,21 +70,33 @@ func RunAmMcpWithPipes(env map[string]string, cmd string, input_pipe io.Reader,
5970
log.Error(fmt.Sprintf("Error creating MCPService stdin pipe: %v", _error))
6071
return _error
6172
}
62-
defer stdin.Close()
73+
defer func() {
74+
if _error := stdin.Close(); _error != nil {
75+
err = errors.Join(err, fmt.Errorf("error closing MCPService stdin pipe: %v", _error))
76+
}
77+
}()
6378

6479
stdout, _error := command.StdoutPipe()
6580
if _error != nil {
6681
log.Error(fmt.Sprintf("Error creating MCPService stdout pipe: %v", _error))
6782
return _error
6883
}
69-
defer stdout.Close()
84+
defer func() {
85+
if _error := stdout.Close(); _error != nil {
86+
err = errors.Join(err, fmt.Errorf("error closing MCPService stdout pipe: %v", _error))
87+
}
88+
}()
7089

7190
stderr, _error := command.StderrPipe()
7291
if _error != nil {
7392
log.Error(fmt.Sprintf("Error creating MCPService stderr pipe: %v", _error))
7493
return _error
7594
}
76-
defer stderr.Close()
95+
defer func() {
96+
if _error := stderr.Close(); _error != nil {
97+
err = errors.Join(err, fmt.Errorf("error closing MCPService stderr pipe: %v", _error))
98+
}
99+
}()
77100

78101
go establishPipeToFile(stdin, input_pipe)
79102
go establishPipeFromFile(error_pipe, stderr)

enrich_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import (
77
"github.com/jfrog/jfrog-cli-security/commands/enrich/enrichgraph"
88
securityTests "github.com/jfrog/jfrog-cli-security/tests"
99
securityTestUtils "github.com/jfrog/jfrog-cli-security/tests/utils"
10-
"github.com/jfrog/jfrog-cli-security/tests/utils/integration"
1110
securityIntegrationTestUtils "github.com/jfrog/jfrog-cli-security/tests/utils/integration"
1211
"github.com/stretchr/testify/assert"
1312
)
1413

1514
func TestXrayEnrichSbomOutput(t *testing.T) {
16-
integration.InitEnrichTest(t, enrichgraph.EnrichMinimumVersionXray)
15+
securityIntegrationTestUtils.InitEnrichTest(t, enrichgraph.EnrichMinimumVersionXray)
1716
cleanUp := securityIntegrationTestUtils.UseTestHomeWithDefaultXrayConfig(t)
1817
defer cleanUp()
1918
testCases := []struct {

jas/runner/jasrunner.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ type CveProvider func() (directCves []string, indirectCves []string)
5454

5555
func AddJasScannersTasks(params JasRunnerParams) error {
5656
// For docker scan we support only secrets and contextual scans.
57-
runAllScanners := false
58-
if params.ApplicableScanType == applicability.ApplicabilityScannerType || params.SecretsScanType == secrets.SecretsScannerType {
59-
runAllScanners = true
60-
}
57+
runAllScanners := params.ApplicableScanType == applicability.ApplicabilityScannerType || params.SecretsScanType == secrets.SecretsScannerType
6158

6259
var errorsCollection error
6360
if generalError := addJasScanTaskForModuleIfNeeded(params, utils.ContextualAnalysisScan, runContextualScan(&params)); generalError != nil {

sca/bom/buildinfo/technologies/conan/conan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func getConanExecPath() (conanExecPath string, err error) {
5353
return
5454
}
5555
if version.NewVersion(string(conanVersion)).Compare(conanV2) < 0 {
56-
err = fmt.Errorf("Conan dependency tree building is currently supported for Conan V2. The current Conan version is: %s", conanVersion)
56+
err = fmt.Errorf("conan dependency tree building is currently supported for Conan V2. The current Conan version is: %s", conanVersion)
5757
return
5858
}
5959
log.Debug("Conan version: ", string(conanVersion))

sca/bom/buildinfo/technologies/go/golang.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
biutils "github.com/jfrog/build-info-go/utils"
88
"github.com/jfrog/gofrog/datastructures"
9-
goartifactoryutils "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/golang"
109
goutils "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/golang"
1110
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1211
"github.com/jfrog/jfrog-cli-security/sca/bom/buildinfo/technologies"
@@ -39,14 +38,14 @@ func BuildDependencyTree(params technologies.BuildInfoBomGeneratorParams) (depen
3938
err = errCacheFolder
4039
return
4140
}
42-
if err = goartifactoryutils.SetGoModCache(projCacheDir); err != nil {
41+
if err = goutils.SetGoModCache(projCacheDir); err != nil {
4342
return
4443
}
4544
}
4645

4746
remoteGoRepo := params.DependenciesRepository
4847
if remoteGoRepo != "" {
49-
if err = goartifactoryutils.SetArtifactoryAsResolutionServer(params.ServerDetails, remoteGoRepo, goProxyParams); err != nil {
48+
if err = goutils.SetArtifactoryAsResolutionServer(params.ServerDetails, remoteGoRepo, goProxyParams); err != nil {
5049
return
5150
}
5251
}

0 commit comments

Comments
 (0)