@@ -20,7 +20,6 @@ import (
20
20
"io/ioutil"
21
21
"log"
22
22
"os"
23
- "path/filepath"
24
23
"regexp"
25
24
"sort"
26
25
"strings"
@@ -185,52 +184,6 @@ func saveOutput(filename, format, rootPath string, issues []*gosec.Issue, metric
185
184
return nil
186
185
}
187
186
188
- func cleanPath (path string ) (string , error ) {
189
- cleanFailed := fmt .Errorf ("%s is not within the $GOPATH and cannot be processed" , path )
190
- nonRecursivePath := strings .TrimSuffix (path , "/..." )
191
- // do not attempt to clean directs that are resolvable on gopath
192
- if _ , err := os .Stat (nonRecursivePath ); err != nil && os .IsNotExist (err ) {
193
- log .Printf ("directory %s doesn't exist, checking if is a package on $GOPATH" , path )
194
- for _ , basedir := range gosec .Gopath () {
195
- dir := filepath .Join (basedir , "src" , nonRecursivePath )
196
- if st , err := os .Stat (dir ); err == nil && st .IsDir () {
197
- log .Printf ("located %s in %s" , path , dir )
198
- return path , nil
199
- }
200
- }
201
- return "" , cleanFailed
202
- }
203
-
204
- // ensure we resolve package directory correctly based on $GOPATH
205
- pkgPath , err := gosec .GetPkgRelativePath (path )
206
- if err != nil {
207
- return "" , cleanFailed
208
- }
209
- return pkgPath , nil
210
- }
211
-
212
- func cleanPaths (paths []string ) []string {
213
- var clean []string
214
- for _ , path := range paths {
215
- cleaned , err := cleanPath (path )
216
- if err != nil {
217
- log .Fatal (err )
218
- }
219
- clean = append (clean , cleaned )
220
- }
221
- return clean
222
- }
223
-
224
- func resolvePackage (pkg string , searchPaths []string ) string {
225
- for _ , basedir := range searchPaths {
226
- dir := filepath .Join (basedir , "src" , pkg )
227
- if st , err := os .Stat (dir ); err == nil && st .IsDir () {
228
- return dir
229
- }
230
- }
231
- return pkg
232
- }
233
-
234
187
func convertToScore (severity string ) (gosec.Score , error ) {
235
188
severity = strings .ToLower (severity )
236
189
switch severity {
@@ -299,19 +252,16 @@ func main() {
299
252
analyzer .LoadRules (ruleDefinitions .Builders ())
300
253
301
254
vendor := regexp .MustCompile (`[\\/]vendor([\\/]|$)` )
302
-
303
255
var packages []string
304
256
// Iterate over packages on the import paths
305
- gopaths := gosec .Gopath ()
306
- for _ , pkg := range gotool .ImportPaths (cleanPaths (flag .Args ())) {
307
-
257
+ for _ , pkg := range gotool .ImportPaths (flag .Args ()) {
308
258
// Skip vendor directory
309
259
if ! * flagScanVendor {
310
260
if vendor .MatchString (pkg ) {
311
261
continue
312
262
}
313
263
}
314
- packages = append (packages , resolvePackage ( pkg , gopaths ) )
264
+ packages = append (packages , pkg )
315
265
}
316
266
317
267
var buildTags []string
@@ -343,6 +293,7 @@ func main() {
343
293
if ! issuesFound && * flagQuiet {
344
294
os .Exit (0 )
345
295
}
296
+
346
297
rootPath := packages [0 ]
347
298
// Create output report
348
299
if err := saveOutput (* flagOutput , * flagFormat , rootPath , issues , metrics , errors ); err != nil {
0 commit comments