@@ -45,16 +45,19 @@ func credentialdiggerScan(config credentialdiggerScanOptions, telemetryData *tel
45
45
provider , prov_err := orchestrator .GetOrchestratorConfigProvider (nil )
46
46
if prov_err != nil {
47
47
log .Entry ().WithError (prov_err ).Error (
48
- "credentialdiggerScan: unable to load orchestrator specific configuration." )
48
+ "Unable to load orchestrator specific configuration." )
49
49
}
50
50
if config .Repository == "" {
51
51
// Get current repository from orchestrator
52
+ log .Entry ().Debug ("Repository URL not defined in step configuration. Try get it from orchestrators" )
52
53
repoUrlOrchestrator := provider .RepoURL ()
53
54
if repoUrlOrchestrator == "n/a" {
54
55
// Jenkins configuration error
55
- log . Entry (). WithError ( errors .New (
56
- fmt . Sprintf ( "Unknown repository URL %s" , repoUrlOrchestrator )) ).Error (
56
+ configError := errors .New (fmt . Sprintf ( "Unknown repository URL %s" , repoUrlOrchestrator ))
57
+ log . Entry (). WithError ( configError ).Error (
57
58
"Repository URL n/a. Please verify git plugin is installed." )
59
+ // The repository to scan was not identified. Return an error
60
+ return configError
58
61
}
59
62
config .Repository = repoUrlOrchestrator
60
63
log .Entry ().Debug ("Use current repository: " , repoUrlOrchestrator )
@@ -69,7 +72,7 @@ func credentialdiggerScan(config credentialdiggerScanOptions, telemetryData *tel
69
72
log .Entry ().Info ("Load rules" )
70
73
err := credentialdiggerAddRules (& config , telemetryData , utils )
71
74
if err != nil {
72
- log .Entry ().Error ("credentialdiggerScan: Failed running credentialdigger add_rules" )
75
+ log .Entry ().Error ("Failed running credentialdigger add_rules" )
73
76
return err
74
77
}
75
78
log .Entry ().Info ("Rules added" )
@@ -93,17 +96,21 @@ func credentialdiggerScan(config credentialdiggerScanOptions, telemetryData *tel
93
96
}
94
97
// err is an error exit number when there are findings
95
98
if err == nil {
96
- log .Entry ().Info ("No discoveries found in this repo" )
97
- // If there are no findings, there is no need to export an empty report
98
- return nil
99
+ log .Entry ().Info ("No leaks found in this repo with scan " )
100
+ // Even if there are no leaks, the user may still want to export all
101
+ // the discoveries (param exportAll set to true)
99
102
}
100
103
101
104
// 3: Get discoveries
102
105
err = credentialdiggerGetDiscoveries (& config , telemetryData , utils )
103
106
if err != nil {
104
- // The exit number is the number of discoveries
107
+ // The exit number is the number of discoveries exported
105
108
// Therefore, this error is not relevant, if raised
106
109
log .Entry ().Warn ("There are findings to review" )
110
+ } else {
111
+ // There are no discoveries exported, so no need to generate the
112
+ // artifact
113
+ return nil
107
114
}
108
115
109
116
// 4: Export report in workspace
@@ -149,7 +156,8 @@ func credentialdiggerAddRules(config *credentialdiggerScanOptions, telemetryData
149
156
log .Entry ().Debug ("Use a local ruleset" )
150
157
// Use rules defined in stashed file
151
158
if hasRulesFile (config .RulesFile , service ) {
152
- log .Entry ().WithField ("file" , config .RulesFile ).Info ("Use stashed rules file from repository" )
159
+ log .Entry ().WithField ("file" , config .RulesFile ).Info (
160
+ "Use stashed rules file from repository" )
153
161
ruleFile = config .RulesFile
154
162
} else {
155
163
log .Entry ().Info ("Use standard pre-defined rules" )
@@ -167,14 +175,15 @@ func credentialdiggerGetDiscoveries(config *credentialdiggerScanOptions, telemet
167
175
// Export all the discoveries or export only new ones
168
176
if ! config .ExportAll {
169
177
cmd_list = append (cmd_list , "--state" , "new" )
178
+ } else {
179
+ log .Entry ().Info ("Export all discoveries" )
170
180
}
171
181
err := executeCredentialDiggerProcess (service , cmd_list )
172
182
if err != nil {
173
- log .Entry ().Error ("credentialdiggerScan: Failed running credentialdigger get_discoveries" )
174
- log .Entry ().Error (err )
183
+ log .Entry ().Warn ("Report generated" )
175
184
return err
176
185
}
177
- log .Entry ().Info ("Scan complete" )
186
+ log .Entry ().Info ("Scan complete with no potential leaks " )
178
187
return nil
179
188
}
180
189
@@ -203,7 +212,8 @@ func credentialdiggerBuildCommonArgs(config *credentialdiggerScanOptions) []stri
203
212
}
204
213
205
214
func credentialdiggerScanSnapshot (config * credentialdiggerScanOptions , telemetryData * telemetry.CustomData , service credentialdiggerUtils ) error {
206
- log .Entry ().Infof ("Scan Snapshot %v from repo %v" , config .Snapshot , config .Repository )
215
+ log .Entry ().Infof (
216
+ "Scan Snapshot %v from repo %v" , config .Snapshot , config .Repository )
207
217
cmd_list := []string {"scan_snapshot" ,
208
218
"--snapshot" , config .Snapshot }
209
219
cmd_list = append (cmd_list , credentialdiggerBuildCommonArgs (config )... )
@@ -218,7 +228,8 @@ func credentialdiggerScanSnapshot(config *credentialdiggerScanOptions, telemetry
218
228
}
219
229
220
230
func credentialdiggerScanPR (config * credentialdiggerScanOptions , telemetryData * telemetry.CustomData , service credentialdiggerUtils ) error {
221
- log .Entry ().Infof ("Scan PR %v from repo %v" , config .PrNumber , config .Repository )
231
+ log .Entry ().Infof (
232
+ "Scan PR %v from repo %v" , config .PrNumber , config .Repository )
222
233
cmd_list := []string {"scan_pr" ,
223
234
"--pr" , strconv .Itoa (config .PrNumber ),
224
235
"--api_endpoint" , config .APIURL }
0 commit comments