forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteam_external_group.go
43 lines (36 loc) · 1.15 KB
/
team_external_group.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
package gapi
import (
"bytes"
"encoding/json"
"fmt"
)
// TeamGroup represents a Grafana TeamGroup.
type TeamGroup struct {
OrgID int64 `json:"orgId,omitempty"`
TeamID int64 `json:"teamId,omitempty"`
GroupID string `json:"groupID,omitempty"`
}
// TeamGroups fetches and returns the list of Grafana team group whose Team ID it's passed.
func (c *Client) TeamGroups(id int64) ([]TeamGroup, error) {
teamGroups := make([]TeamGroup, 0)
err := c.request("GET", fmt.Sprintf("/api/teams/%d/groups", id), nil, nil, &teamGroups)
if err != nil {
return teamGroups, err
}
return teamGroups, nil
}
// NewTeamGroup creates a new Grafana Team Group .
func (c *Client) NewTeamGroup(id int64, groupID string) error {
dataMap := map[string]string{
"groupId": groupID,
}
data, err := json.Marshal(dataMap)
if err != nil {
return err
}
return c.request("POST", fmt.Sprintf("/api/teams/%d/groups", id), nil, bytes.NewBuffer(data), nil)
}
// DeleteTeam deletes the Grafana team whose ID it's passed.
func (c *Client) DeleteTeamGroup(id int64, groupID string) error {
return c.request("DELETE", fmt.Sprintf("/api/teams/%d/groups/%s", id, groupID), nil, nil, nil)
}