-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapplistparser.go
More file actions
46 lines (41 loc) · 1011 Bytes
/
Copy pathapplistparser.go
File metadata and controls
46 lines (41 loc) · 1011 Bytes
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
package vcodeapi
import (
"bytes"
"encoding/xml"
"errors"
)
// App represents a Veracode Application Profile
type App struct {
AppID string `xml:"app_id,attr"`
AppName string `xml:"app_name,attr"`
}
// ParseAppList calls the Veracode getapplist.do API and returns an array of Apps
func ParseAppList(credsFile string) ([]App, error) {
var apps []App
appListAPI, err := appList(credsFile)
if err != nil {
return nil, err
}
decoder := xml.NewDecoder(bytes.NewReader(appListAPI))
for {
// Read tokens from the XML document in a stream.
t, _ := decoder.Token()
if t == nil {
break
}
// Inspect the type of the token just read
switch se := t.(type) {
case xml.StartElement:
// Read StartElement and check for flaw
if se.Name.Local == "app" {
var app App
decoder.DecodeElement(&app, &se)
apps = append(apps, app)
}
if se.Name.Local == "error" {
return nil, errors.New("api for GetAppList returned with an error element")
}
}
}
return apps, nil
}