Skip to content

Commit 2beef7e

Browse files
committed
feat: add dynamic option
1 parent ceb9f9d commit 2beef7e

File tree

8 files changed

+39
-7
lines changed

8 files changed

+39
-7
lines changed

cmd/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type OptionalConfig struct {
4141
ProgressBar bool `json:"progress"`
4242
TLSVerify bool `json:"tls"`
4343
Proxy string `json:"proxy"`
44+
Dynamic bool `json:"dynamic"`
4445
}
4546

4647
type RepoConfig struct {

config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@
4848

4949
// 全局http代理
5050
// global proxy for http requests, eg: http://127.0.0.1:7890
51-
"proxy": ""
51+
"proxy": "",
52+
53+
// 允许动态命令
54+
// allow dynamic command, eg: mvn
55+
"dynamic": false
5256

5357
},
5458

opensca/sca/golang/gomod.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sort"
1010
"strings"
1111

12+
"github.com/xmirrorsecurity/opensca-cli/v3/cmd/config"
1213
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/model"
1314
)
1415

@@ -131,6 +132,10 @@ func ParseGosum(file *model.File) *model.DepGraph {
131132
// GoModGraph 调用 go mod graph 解析依赖
132133
func GoModGraph(ctx context.Context, modfile *model.File) *model.DepGraph {
133134

135+
if !config.Conf().Optional.Dynamic {
136+
return nil
137+
}
138+
134139
_, err := exec.LookPath("go")
135140
if err != nil {
136141
return nil

opensca/sca/golang/sca.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"path/filepath"
66

7+
"github.com/xmirrorsecurity/opensca-cli/v3/cmd/config"
78
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/model"
89
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/sca/filter"
910
)
@@ -44,12 +45,14 @@ func (sca Sca) Sca(ctx context.Context, parent *model.File, files []*model.File,
4445
}
4546

4647
// 尝试调用 go mod graph
47-
for dir, f := range gomod {
48-
graph := GoModGraph(ctx, f)
49-
if graph != nil && len(graph.Children) > 0 {
50-
call(f, graph)
51-
delete(gomod, dir)
52-
delete(gosum, dir)
48+
if config.Conf().Optional.Dynamic {
49+
for dir, f := range gomod {
50+
graph := GoModGraph(ctx, f)
51+
if graph != nil && len(graph.Children) > 0 {
52+
call(f, graph)
53+
delete(gomod, dir)
54+
delete(gosum, dir)
55+
}
5356
}
5457
}
5558

opensca/sca/groovy/gradle.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"regexp"
1212
"strings"
1313

14+
"github.com/xmirrorsecurity/opensca-cli/v3/cmd/config"
1415
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/logs"
1516
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/model"
1617
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/sca/filter"
@@ -115,6 +116,10 @@ type gradleDep struct {
115116

116117
func GradleTree(ctx context.Context, dir *model.File) []*model.DepGraph {
117118

119+
if !config.Conf().Optional.Dynamic {
120+
return nil
121+
}
122+
118123
if dir == nil {
119124
return nil
120125
}

opensca/sca/java/mvn.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414
"sync"
1515

16+
"github.com/xmirrorsecurity/opensca-cli/v3/cmd/config"
1617
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/common"
1718
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/logs"
1819
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/model"
@@ -516,6 +517,10 @@ func DownloadPomFromRepo(dep PomDependency, do func(r io.Reader), repos ...commo
516517
// pom: pom文件信息
517518
func MvnTree(ctx context.Context, pom *Pom) *model.DepGraph {
518519

520+
if !config.Conf().Optional.Dynamic {
521+
return nil
522+
}
523+
519524
if pom == nil {
520525
return nil
521526
}

opensca/sca/python/env.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111
"strings"
1212

13+
"github.com/xmirrorsecurity/opensca-cli/v3/cmd/config"
1314
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/common"
1415
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/logs"
1516
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/model"
@@ -123,6 +124,9 @@ func pipenvGraph(ctx context.Context, dir string) *model.DepGraph {
123124
}
124125

125126
func runCmd(ctx context.Context, dir string, cmd string, args ...string) ([]byte, bool) {
127+
if !config.Conf().Optional.Dynamic {
128+
return nil, false
129+
}
126130
c := exec.CommandContext(ctx, cmd, args...)
127131
c.Dir = dir
128132
out, err := c.CombinedOutput()

opensca/sca/python/setup.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"regexp"
1111
"strings"
1212

13+
"github.com/xmirrorsecurity/opensca-cli/v3/cmd/config"
1314
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/logs"
1415
"github.com/xmirrorsecurity/opensca-cli/v3/opensca/model"
1516
)
@@ -72,6 +73,10 @@ type setupDep struct {
7273

7374
func ParseSetupPyWithPython(file *model.File) *model.DepGraph {
7475

76+
if !config.Conf().Optional.Dynamic {
77+
return nil
78+
}
79+
7580
if _, err := exec.LookPath("python"); err != nil {
7681
return nil
7782
}

0 commit comments

Comments
 (0)