@@ -5,10 +5,6 @@ import (
55 "context"
66 "encoding/json"
77 "fmt"
8- "github.com/murphysecurity/murphysec/env"
9- "github.com/murphysecurity/murphysec/infra/sl"
10- "github.com/repeale/fp-go"
11- "go.uber.org/zap"
128 "io"
139 "os/exec"
1410 "path/filepath"
@@ -17,6 +13,7 @@ import (
1713 "github.com/murphysecurity/murphysec/model"
1814 "github.com/murphysecurity/murphysec/utils"
1915 "github.com/pkg/errors"
16+ "go.uber.org/zap"
2017 "golang.org/x/mod/modfile"
2118)
2219
@@ -35,50 +32,24 @@ func (Inspector) CheckDir(dir string) bool {
3532}
3633
3734func (Inspector ) InspectProject (ctx context.Context ) error {
38- task := model .UseInspectionTask (ctx )
3935 logger := logctx .Use (ctx )
40- modFilePath := filepath .Join (task .Dir (), "go.mod" )
41- logger .Debug ("Reading go.mod" , zap .String ("path" , modFilePath ))
42- data , e := utils .ReadFileLimited (modFilePath , 1024 * 1024 * 4 )
43- if e != nil {
44- return errors .WithMessage (e , "Open GoMod file" )
45- }
46- logger .Debug ("Parsing go.mod" )
47- f , e := modfile .ParseLax (filepath .Base (modFilePath ), data , nil )
48- if e != nil {
49- return errors .WithMessage (e , "Parse go mod failed" )
50- }
51- var dependencies []model.DependencyItem
52- if ! env .DoNotBuild {
53- // try command go list
54- dependencies , e = doGoList (ctx , task .Dir ())
55- if e != nil {
56- if errors .Is (e , _ErrGoNotFound ) {
57- logger .Debug ("Go not found, skip GoList" )
58- } else {
59- // log it and go on
60- logger .Warn ("GoList failed" , zap .Error (e ))
61- }
62- dependencies = append (dependencies , fp .Map (mapRequireToDependencyItem )(sl .FilterNotNull (f .Require ))... )
36+ if privatePath , ok := ctx .Value ("privateSourceAddr" ).(string ); ok {
37+ logger .Debug ("Use private path" , zap .String ("path" , privatePath ))
38+ if err := setPrivatePath (privatePath , logger ); err != nil {
39+ return err
6340 }
6441 }
65- if len (dependencies ) == 0 {
66- if ! env .DoNotBuild {
67- logger .Warn ("no dependencies found, backup" )
42+ if proxyPath , ok := ctx .Value ("proxyAddr" ).(string ); ok {
43+ logger .Debug ("Use proxy path" , zap .String ("path" , proxyPath ))
44+ if err := setProxyPath (proxyPath , logger ); err != nil {
45+ return err
6846 }
69- dependencies = append (dependencies , fp .Map (mapRequireToDependencyItem )(sl .FilterNotNull (f .Require ))... )
7047 }
71- m := model.Module {
72- PackageManager : "gomod" ,
73- ModulePath : modFilePath ,
74- ModuleName : "<NoNameModule>" ,
75- Dependencies : dependencies ,
76- }
77- if f .Module != nil {
78- m .ModuleVersion = f .Module .Mod .Version
79- m .ModuleName = f .Module .Mod .Path
48+ if err := buildScan (ctx ); err != nil {
49+ if err := baseScan (ctx ); err != nil {
50+ return err
51+ }
8052 }
81- task .AddModule (m )
8253 return nil
8354}
8455
0 commit comments