-
Notifications
You must be signed in to change notification settings - Fork 6
/
teamlistparser.go
48 lines (42 loc) · 1.05 KB
/
teamlistparser.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
package vcodeapi
import (
"bytes"
"encoding/xml"
"errors"
)
//Team represents a Veracode team of users
type Team struct {
TeamID string `xml:"team_id,attr"`
TeamName string `xml:"team_name,attr"`
CreationDate string `xml:"creation_date,attr"`
}
//ParseTeamList calls the getteamlist.do API and returns an array of teams
func ParseTeamList(credsFile string) ([]Team, error) {
var teams []Team
teamListAPI, err := teamList(credsFile)
if err != nil {
return nil, err
}
decoder := xml.NewDecoder(bytes.NewReader(teamListAPI))
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 == "team" {
var team Team
decoder.DecodeElement(&team, &se)
teams = append(teams, team)
}
if se.Name.Local == "error" {
return nil, errors.New("api for GetTeamList returned with an error element")
}
}
}
return teams, nil
}