-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteam.go
83 lines (69 loc) · 2.36 KB
/
team.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
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-Present Datadog, Inc.
package cloudcraft
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
"time"
)
// teamPath is the path to the team endpoint of the Cloudcraft API.
const teamPath string = "team"
// TeamService handles communication with the "/team" endpoint of Cloudcraft's
// developer API.
type TeamService service
// Team represents a team in Cloudcraft.
type Team struct {
UpdatedAt time.Time `json:"updatedAt,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
CustomerID string `json:"customerId,omitempty"`
Role string `json:"role,omitempty"`
Members []Members `json:"members,omitempty"`
Visible bool `json:"visible,omitempty"`
CrossOrganizational bool `json:"crossOrganizational,omitempty"`
ExternalSharing bool `json:"externalSharing,omitempty"`
}
// Members represents a list of members in a team.
type Members struct {
ID string `json:"id,omitempty"`
Role string `json:"role,omitempty"`
UserID *string `json:"userId,omitempty"`
Name *string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
MFAEnabled bool `json:"mfaEnabled,omitempty"`
}
// List returns a list of teams.
//
// [API Reference].
//
// [API Reference]: https://docs.datadoghq.com/cloudcraft/api/teams/#list-teams
func (s *TeamService) List(ctx context.Context) ([]*Team, *Response, error) {
if ctx == nil {
return nil, nil, ErrNilContext
}
var (
baseURL = s.client.cfg.endpoint.String()
endpoint strings.Builder
)
endpoint.Grow(len(baseURL) + len(teamPath))
endpoint.WriteString(baseURL)
endpoint.WriteString(teamPath)
req, err := s.client.request(ctx, http.MethodGet, endpoint.String(), http.NoBody)
if err != nil {
return nil, nil, fmt.Errorf("%w", err)
}
resp, err := s.client.do(req)
if err != nil {
return nil, nil, fmt.Errorf("%w", err)
}
var result []*Team
if err := json.Unmarshal(resp.Body, &result); err != nil {
return nil, resp, fmt.Errorf("%w", err)
}
return result, resp, nil
}