-
Notifications
You must be signed in to change notification settings - Fork 0
/
scans.go
114 lines (94 loc) · 2.81 KB
/
scans.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package CxSASTClientGo
import (
"encoding/json"
"encoding/xml"
"fmt"
"github.com/pkg/errors"
)
func (c SASTClient) GetScan(scanid uint64) (Scan, error) {
c.depwarn("GetScan", "GetScanByID")
return c.GetScanByID(scanid)
}
func (c SASTClient) GetScanByID(scanid uint64) (Scan, error) {
c.logger.Debugf("Get SAST scan %d", scanid)
var scan Scan
response, err := c.get(fmt.Sprintf("/sast/scans/%d", scanid))
if err != nil {
return scan, err
}
err = json.Unmarshal(response, &scan)
return scan, err
}
func (c SASTClient) GetLastScan(projectid uint64) (Scan, error) {
c.depwarn("GetLastScan", "GetLastScanByID")
return c.GetLastScanByID(projectid)
}
func (c SASTClient) GetLastScanByID(projectid uint64) (Scan, error) {
var scans []Scan
response, err := c.get(fmt.Sprintf("/sast/scans?projectId=%d&scanStatus=Finished&last=1", projectid))
if err != nil {
return Scan{}, err
}
err = json.Unmarshal(response, &scans)
if err != nil {
return Scan{}, err
}
if len(scans) == 0 {
return Scan{}, errors.New(fmt.Sprintf("No scans found in project %d", projectid))
}
return scans[0], nil
}
func (c SASTClient) GetEngineConfigurations() ([]EngineConfiguration, error) {
var confs []EngineConfiguration
response, err := c.get("/sast/engineConfigurations")
if err != nil {
return confs, err
}
err = json.Unmarshal(response, &confs)
return confs, err
}
func (c SASTClient) GetEngineConfigurationsSOAP() ([]EngineConfiguration, error) {
var confs []EngineConfiguration
response, err := c.sendSOAPRequest("GetConfigurationSetList", "<SessionID></SessionID>")
if err != nil {
return confs, err
}
var xmlResponse struct {
XMLName xml.Name `xml:"Envelope"`
Body struct {
XMLName xml.Name `xml:"Body"`
Response struct {
XMLName xml.Name `xml:"GetConfigurationSetListResponse"`
Result struct {
XMLName xml.Name `xml:"GetConfigurationSetListResult"`
IsSuccesfull bool `xml:"IsSuccesfull"`
ErrorMessage string
ConfigSetList struct {
XMLName xml.Name `xml:"ConfigSetList"`
ConfigSets []struct {
ConfigSetName string
ID uint64
} `xml:"ConfigurationSet"`
}
}
}
}
}
err = xml.Unmarshal(response, &xmlResponse)
if err != nil {
c.logger.Errorf("Failed to parse SOAP response: %s", err)
c.logger.Tracef("Parsed from: %v", string(response))
return confs, err
}
if !xmlResponse.Body.Response.Result.IsSuccesfull {
return confs, fmt.Errorf("failed to get engine configurations: %v", xmlResponse.Body.Response.Result.ErrorMessage)
}
confs = make([]EngineConfiguration, len(xmlResponse.Body.Response.Result.ConfigSetList.ConfigSets))
for id, conf := range xmlResponse.Body.Response.Result.ConfigSetList.ConfigSets {
confs[id] = EngineConfiguration{
ID: conf.ID,
Name: conf.ConfigSetName,
}
}
return confs, err
}