Skip to content

Commit

Permalink
feat: 统一扫描器离线相关配置处理逻辑 #39
Browse files Browse the repository at this point in the history
* feat: 统一扫描器离线相关配置处理逻辑 #39

* feat: 统一扫描器离线相关配置处理逻辑 -- 兼容历史配置 #39
  • Loading branch information
myqonnt authored May 31, 2023
1 parent e1b085c commit 1e3e25c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions trivy/pkg/constant/trivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ const ArgDbDownloadUrl = "dbDownloadUrl"

// ArgJavaDbDownloadUrl java漏洞库下载地址
const ArgJavaDbDownloadUrl = "javaDbDownloadUrl"

// ConfigOffline 是否使用离线模式
const ConfigOffline = "offline"
21 changes: 14 additions & 7 deletions trivy/pkg/scan_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ type TrivyExecutor struct{}

// Execute 执行分析
func (e TrivyExecutor) Execute(config *object.ToolConfig, file *os.File) (*object.ToolOutput, error) {
offline := len(config.GetStringArg(constant.ArgDbDownloadUrl)) > 0
offline, err := config.GetBoolArg(constant.ConfigOffline)
if err != nil {
offline = len(config.GetStringArg(constant.ArgDbDownloadUrl)) > 0
}
if offline {
if err := downloadAllDB(config); err != nil {
return nil, err
Expand All @@ -34,16 +37,20 @@ func downloadAllDB(config *object.ToolConfig) error {
downloader := &util.DefaultDownloader{}
// download db
url := config.GetStringArg(constant.ArgDbDownloadUrl)
dbDir := filepath.Join(constant.DbCacheDir, constant.DbDir)
if err := util.ExtractTarUrl(url, dbDir, 0770, downloader); err != nil {
return err
if len(url) > 0 {
dbDir := filepath.Join(constant.DbCacheDir, constant.DbDir)
if err := util.ExtractTarUrl(url, dbDir, 0770, downloader); err != nil {
return err
}
}

// download java db
javaDbUrl := config.GetStringArg(constant.ArgJavaDbDownloadUrl)
javaDbDir := filepath.Join(constant.DbCacheDir, constant.JavaDbDir)
if err := util.ExtractTarUrl(javaDbUrl, javaDbDir, 0770, downloader); err != nil {
return err
if len(javaDbUrl) > 0 {
javaDbDir := filepath.Join(constant.DbCacheDir, constant.JavaDbDir)
if err := util.ExtractTarUrl(javaDbUrl, javaDbDir, 0770, downloader); err != nil {
return err
}
}
return nil
}
Expand Down

0 comments on commit 1e3e25c

Please sign in to comment.