forked from jianyuan/go-sentry
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganization_members.go
123 lines (106 loc) · 3.76 KB
/
organization_members.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package sentry
import (
"context"
"fmt"
"time"
)
// OrganizationMember represents a User's membership to the organization.
// https://github.com/getsentry/sentry/blob/22.5.0/src/sentry/api/serializers/models/organization_member/response.py#L57-L69
type OrganizationMember struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
User User `json:"user"`
Role string `json:"role"`
RoleName string `json:"roleName"`
Pending bool `json:"pending"`
Expired bool `json:"expired"`
Flags map[string]bool `json:"flags"`
DateCreated time.Time `json:"dateCreated"`
InviteStatus string `json:"inviteStatus"`
InviterName *string `json:"inviterName"`
Teams []string `json:"teams"`
}
const (
RoleMember string = "member"
RoleBilling string = "billing"
RoleAdmin string = "admin"
RoleOwner string = "owner"
RoleManager string = "manager"
)
// OrganizationMembersService provides methods for accessing Sentry membership API endpoints.
type OrganizationMembersService service
// List organization members.
func (s *OrganizationMembersService) List(ctx context.Context, organizationSlug string, params *ListCursorParams) ([]*OrganizationMember, *Response, error) {
u := fmt.Sprintf("0/organizations/%v/members/", organizationSlug)
u, err := addQuery(u, params)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
members := []*OrganizationMember{}
resp, err := s.client.Do(ctx, req, &members)
if err != nil {
return nil, resp, err
}
return members, resp, nil
}
func (s *OrganizationMembersService) Get(ctx context.Context, organizationSlug string, memberID string) (*OrganizationMember, *Response, error) {
u := fmt.Sprintf("0/organizations/%v/members/%v/", organizationSlug, memberID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
member := new(OrganizationMember)
resp, err := s.client.Do(ctx, req, member)
if err != nil {
return nil, resp, err
}
return member, resp, nil
}
type CreateOrganizationMemberParams struct {
Email string `json:"email"`
Role string `json:"role"`
Teams []string `json:"teams,omitempty"`
}
func (s *OrganizationMembersService) Create(ctx context.Context, organizationSlug string, params *CreateOrganizationMemberParams) (*OrganizationMember, *Response, error) {
u := fmt.Sprintf("0/organizations/%v/members/", organizationSlug)
req, err := s.client.NewRequest("POST", u, params)
if err != nil {
return nil, nil, err
}
member := new(OrganizationMember)
resp, err := s.client.Do(ctx, req, member)
if err != nil {
return nil, resp, err
}
return member, resp, nil
}
type UpdateOrganizationMemberParams struct {
Role string `json:"role"`
Teams []string `json:"teams,omitempty"`
}
func (s *OrganizationMembersService) Update(ctx context.Context, organizationSlug string, memberID string, params *UpdateOrganizationMemberParams) (*OrganizationMember, *Response, error) {
u := fmt.Sprintf("0/organizations/%v/members/%v/", organizationSlug, memberID)
req, err := s.client.NewRequest("PUT", u, params)
if err != nil {
return nil, nil, err
}
member := new(OrganizationMember)
resp, err := s.client.Do(ctx, req, member)
if err != nil {
return nil, resp, err
}
return member, resp, nil
}
func (s *OrganizationMembersService) Delete(ctx context.Context, organizationSlug string, memberID string) (*Response, error) {
u := fmt.Sprintf("0/organizations/%v/members/%v/", organizationSlug, memberID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}