Skip to content

Commit 41510bd

Browse files
author
chenhaoxuan
committed
Merge branch 'gotree' into 'v3'
update: go tree See merge request develop/client!14
2 parents 0e5aa29 + b0489b8 commit 41510bd

File tree

5 files changed

+388
-42
lines changed

5 files changed

+388
-42
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.23.4
44

55
require (
66
github.com/AlecAivazis/survey/v2 v2.3.7
7+
github.com/Masterminds/semver v1.5.0
78
github.com/antchfx/xmlquery v1.4.1
89
github.com/antlr4-go/antlr/v4 v4.13.1
910
github.com/bahlo/generic-list-go v0.2.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
22
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
33
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
44
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
5+
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
6+
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
57
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
68
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
79
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=

module/go_mod/go.go

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3734
func (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

Comments
 (0)