-
Notifications
You must be signed in to change notification settings - Fork 23
/
account_groups.go
48 lines (41 loc) · 1.45 KB
/
account_groups.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 thousandeyes
import "fmt"
// AccountGroups - list of account groups
type AccountGroups []AccountGroup
// AccountGroup - An account within a ThousandEyes organization
type AccountGroup struct {
AccountGroupName *string `json:"accountGroupName,omitempty"`
AID *int64 `json:"aid,omitempty"`
}
// SharedWithAccount describes accounts with which a resource is shared.
// This is separate from the AccountGroup above only due to the difference
// in JSON object names.
type SharedWithAccount struct {
AccountGroupName *string `json:"name,omitempty"`
AID *int64 `json:"aid,omitempty"`
}
// GetAccountGroups - Get third party and webhook integrations
func (c *Client) GetAccountGroups() (*[]SharedWithAccount, error) {
resp, err := c.get("/account-groups")
if err != nil {
return nil, err
}
var target map[string][]AccountGroup
if dErr := c.decodeJSON(resp, &target); dErr != nil {
return nil, fmt.Errorf("Could not decode JSON response: %v", dErr)
}
if _, ok := target["accountGroups"]; !ok {
return nil, fmt.Errorf("'accountGroups' not found in JSON response")
}
// Since the use of this is for the SharedWithAccount configuration,
// we will return that type.
var accountGroups []SharedWithAccount
for _, v := range target["accountGroups"] {
account := SharedWithAccount{
AccountGroupName: v.AccountGroupName,
AID: v.AID,
}
accountGroups = append(accountGroups, account)
}
return &accountGroups, nil
}