This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprescan.go
67 lines (55 loc) · 1.86 KB
/
prescan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"encoding/xml"
"fmt"
"net/http"
"sort"
"strings"
)
type PrescanModuleList struct {
XMLName xml.Name `xml:"prescanresults"`
Modules []PrescanModule `xml:"module"`
}
type PrescanModule struct {
XMLName xml.Name `xml:"module"`
ID int `xml:"id,attr"`
Name string `xml:"name,attr"`
Status string `xml:"status,attr"`
Platform string `xml:"platform,attr"`
Size string `xml:"size,attr"`
MD5 string `xml:"checksum,attr"`
HasFatalErrors bool `xml:"has_fatal_errors,attr"`
IsDependency bool `xml:"is_dependency,attr"`
Issues []PrescanModuleIssue `xml:"issue"`
}
type PrescanModuleIssue struct {
XMLName xml.Name `xml:"issue"`
Details string `xml:"details,attr"`
}
func (api API) getPrescanModuleList(appId, buildId int) PrescanModuleList {
var url = fmt.Sprintf("https://analysiscenter.veracode.com/api/5.0/getprescanresults.do?app_id=%d&build_id=%d", appId, buildId)
response := api.makeApiRequest(url, http.MethodGet)
moduleList := PrescanModuleList{}
xml.Unmarshal(response, &moduleList)
// Sort modules by name for consistency
sort.Slice(moduleList.Modules, func(i, j int) bool {
return moduleList.Modules[i].Name < moduleList.Modules[j].Name
})
return moduleList
}
func (moduleList PrescanModuleList) getFromName(moduleName string) PrescanModule {
for _, moduleFromlist := range moduleList.Modules {
if moduleFromlist.Name == moduleName {
return moduleFromlist
}
}
return PrescanModule{}
}
func (module PrescanModule) getFatalReason() string {
for _, issue := range strings.Split(module.Status, ",") {
if strings.HasPrefix(issue, "(Fatal)") {
return strings.Replace(issue, "(Fatal)", ": ", 1)
}
}
return ""
}