-
Notifications
You must be signed in to change notification settings - Fork 6
/
teaminfoparser.go
56 lines (48 loc) · 1.39 KB
/
teaminfoparser.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
package vcodeapi
import (
"bytes"
"encoding/xml"
"errors"
)
//TeamInfo represents the Team Information for a Veracode Team
type TeamInfo struct {
TeamName string `xml:"team_name,attr"`
Users []User `xml:"user"`
Apps []App `xml:"application"`
}
//User represents a User in the Veracode Platform
type User struct {
Username string `xml:"username,attr"`
FirstName string `xml:"first_name,attr"`
LastName string `xml:"last_name,attr"`
Email string `xml:"email_address,attr"`
}
// App Struct is declared in applistparser.go
// ParseTeamInfo calls the Veracode getteaminfo.do API and returns a TeamInfo struct
func ParseTeamInfo(credsFile, teamID string, includeUsers, includeApplications bool) (TeamInfo, error) {
var team TeamInfo
teamInfoAPI, err := teamInfo(credsFile, teamID, includeUsers, includeApplications)
if err != nil {
return team, err
}
decoder := xml.NewDecoder(bytes.NewReader(teamInfoAPI))
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 == "teaminfo" {
decoder.DecodeElement(&team, &se)
}
if se.Name.Local == "error" {
return team, errors.New("api for GetTeamInfo returned with an error element")
}
}
}
return team, nil
}