Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 统一扫描器离线相关配置处理逻辑 #39 #40

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
cnlkl marked this conversation as resolved.
Show resolved Hide resolved
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