generated from davidji99/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathusers.go
147 lines (121 loc) · 4.43 KB
/
users.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package api
import (
"github.com/davidji99/simpleresty"
)
// UsersService handles communication with the user related
// methods of the Split.io APIv2.
//
// Reference: https://docs.split.io/reference#users-overview
type UsersService service
// User represents a user.
type User struct {
ID *string `json:"id"`
Type *string `json:"type"`
Name *string `json:"name"`
Email *string `json:"email"`
Status *string `json:"status"`
TFA *bool `json:"2fa"`
Groups []*Group `json:"groups,omitempty"`
}
// UserListResult
type UserListResult struct {
Data []*User `json:"data"`
NextMarker *string `json:"nextMarker,omitempty"`
PreviousMarker *string `json:"previousMarker,omitempty"`
Limit *int `json:"limit"`
Count *int `json:"count"`
}
// UserListOpts represents all query parameters when fetching all Users.
type UserListOpts struct {
// ACTIVE | DEACTIVATED | PENDING are the allowed status values to filter by
Status string `url:"status,omitempty"`
// 1-200 are the potential values. Default=50
Limit int `url:"limit,omitempty"`
// value of "previousMarker" in response
Before int `url:"limit,omitempty"`
// value of "nextMarker" in response
After string `url:"limit,omitempty"`
// eturns Active members of a group
GroupID string `url:"limit,omitempty"`
}
// UserCreateRequest is to create a new user.
type UserCreateRequest struct {
Email string `json:"email,omitempty"`
Groups []struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
} `json:"groups,omitempty"`
}
// UserUpdateRequest updates an existing user.
type UserUpdateRequest struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
TFA *bool `json:"2fa,omitempty"`
Status string `json:"status,omitempty"`
}
// List all active, deactivated, and pending users in the organization.
//
// By default, pending users are not returned via this endpoint.
//
// Reference: https://docs.split.io/reference#list-users
func (u *UsersService) List(opts *UserListOpts) (*UserListResult, *simpleresty.Response, error) {
var result UserListResult
urlStr, urlStrErr := u.client.http.RequestURLWithQueryParams("/users", opts)
if urlStrErr != nil {
return nil, nil, urlStrErr
}
// Execute the request
response, getErr := u.client.get(urlStr, &result, nil)
return &result, response, getErr
}
// Get a user by their user Id.
//
// Reference: https://docs.split.io/reference#get-user
func (u *UsersService) Get(id string) (*User, *simpleresty.Response, error) {
var result User
urlStr := u.client.http.RequestURL("/users/%s", id)
response, getErr := u.client.get(urlStr, &result, nil)
return &result, response, getErr
}
// Invite a new user to your organization. They will be created with a Pending status
//
// Reference: https://docs.split.io/reference#invite-a-new-user
func (u *UsersService) Invite(opts *UserCreateRequest) (*User, *simpleresty.Response, error) {
var result User
urlStr := u.client.http.RequestURL("/users")
// Execute the request
response, err := u.client.post(urlStr, &result, opts)
return &result, response, err
}
// Update display name, email, disable 2FA, and Activate/Deactivate of a User.
//
// Reference: https://docs.split.io/reference#full-update-user
func (u *UsersService) Update(id string, opts *UserUpdateRequest) (*User, *simpleresty.Response, error) {
var result User
urlStr := u.client.http.RequestURL("/users/%s", id)
// Execute the request
response, err := u.client.put(urlStr, &result, opts)
return &result, response, err
}
//// UpdateUserGroups Use this endpoint to update the groups that a user is part of.
////
//// Reference: https://docs.split.io/reference#update-users-groups
//func (s *UsersService) UpdateUserGroups(id string, opts *UserUpdateRequest) (*User, *simpleresty.Response, error) {
// var result User
// urlStr := s.client.http.RequestURL("/users/%s", id)
//
// // Execute the request
// response, err := s.client.put(urlStr, &result, opts)
//
// return &result, response, err
//}
// DeletePendingUser that have not accepted their invites yet. Once a user is active,
// you can only deactivate the user via a PUT request
//
// Reference: https://docs.split.io/reference#delete-a-pending-user
func (u *UsersService) DeletePendingUser(id string) (*simpleresty.Response, error) {
urlStr := u.client.http.RequestURL("/users/%s", id)
// Execute the request
response, deleteErr := u.client.delete(urlStr, nil, nil)
return response, deleteErr
}