Skip to content

Commit

Permalink
feat(report): add a err code to wpscan.com API error (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
kotakanbe authored Jan 7, 2021
1 parent d7a613b commit 69d32d4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions errof/errof.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func (e Error) Error() string {
var (
// ErrFailedToAccessGithubAPI is error of github alert's api access
ErrFailedToAccessGithubAPI ErrorCode = "ErrFailedToAccessGithubAPI"

// ErrFailedToAccessWpScan is error of wpscan.com api access
ErrFailedToAccessWpScan ErrorCode = "ErrFailedToAccessWpScan"
)

// New :
Expand Down
6 changes: 2 additions & 4 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ func FillGitHubSecurityAlerts(r *models.ScanResult, owner, repo, token string) (
// util.Log.Debugf("%s", pp.Sprint(alerts))
// util.Log.Debugf("%s", string(body))
if alerts.Data.Repository.URL == "" {
return 0, errof.New(
errof.ErrFailedToAccessGithubAPI,
fmt.Sprintf("Failed to access to GitHub API. Response: %s", string(body)),
)
return 0, errof.New(errof.ErrFailedToAccessGithubAPI,
fmt.Sprintf("Failed to access to GitHub API. Response: %s", string(body)))
}

for _, v := range alerts.Data.Repository.VulnerabilityAlerts.Edges {
Expand Down
2 changes: 1 addition & 1 deletion models/scanresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type ScanResult struct {
Packages Packages `json:"packages"`
SrcPackages SrcPackages `json:",omitempty"`
EnabledDnfModules []string `json:"enabledDnfModules,omitempty"` // for dnf modules
WordPressPackages *WordPressPackages `json:",omitempty"`
WordPressPackages WordPressPackages `json:",omitempty"`
LibraryScanners LibraryScanners `json:"libraries,omitempty"`
CweDict CweDict `json:"cweDict,omitempty"`
Optional map[string]interface{} `json:",omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions scan/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type base struct {
Platform models.Platform
osPackages
LibraryScanners []models.LibraryScanner
WordPress *models.WordPressPackages
WordPress models.WordPressPackages

log *logrus.Entry
errs []error
Expand Down Expand Up @@ -656,7 +656,7 @@ func (l *base) scanWordPress() (err error) {
if err != nil {
return xerrors.Errorf("Failed to scan wordpress: %w", err)
}
l.WordPress = wp
l.WordPress = *wp
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion wordpress/wordpress.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

c "github.com/future-architect/vuls/config"
"github.com/future-architect/vuls/errof"
"github.com/future-architect/vuls/models"
"github.com/future-architect/vuls/util"
version "github.com/hashicorp/go-version"
Expand Down Expand Up @@ -107,7 +108,8 @@ func FillWordPress(r *models.ScanResult, token string) (int, error) {
func wpscan(url, name, token string) (vinfos []models.VulnInfo, err error) {
body, err := httpRequest(url, token)
if err != nil {
return nil, err
return nil, errof.New(errof.ErrFailedToAccessWpScan,
fmt.Sprintf("Failed to access to wpscan.comm. body: %s, err: %s", string(body), err))
}
if body == "" {
util.Log.Debugf("wpscan.com response body is empty. URL: %s", url)
Expand Down

0 comments on commit 69d32d4

Please sign in to comment.