-
Notifications
You must be signed in to change notification settings - Fork 3
/
account_user.go
83 lines (68 loc) · 2.15 KB
/
account_user.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
package scalr
import (
"context"
"errors"
)
// Compile-time proof of interface implementation.
var _ AccountUsers = (*accountUsers)(nil)
// AccountUsers describes all the account user related methods that the
// Scalr IACP API supports.
type AccountUsers interface {
List(ctx context.Context, options AccountUserListOptions) (*AccountUserList, error)
}
// accountUsers implements AccountUsers.
type accountUsers struct {
client *Client
}
// AccountUserStatus represents a status of account user relation.
type AccountUserStatus string
// List of available account user statuses.
const (
AccountUserStatusActive AccountUserStatus = "Active"
AccountUserStatusInactive AccountUserStatus = "Inactive"
AccountUserStatusPending AccountUserStatus = "Pending"
)
// AccountUserListOptions represents the options for listing account users.
type AccountUserListOptions struct {
Account *string `url:"filter[account],omitempty"`
User *string `url:"filter[user],omitempty"`
Query *string `url:"query,omitempty"`
Sort *string `url:"sort,omitempty"`
Include *string `url:"include,omitempty"`
}
func (o AccountUserListOptions) validate() error {
if !(validString(o.Account) || validString(o.User)) {
return errors.New("either filter[account] or filter[user] is required")
}
return nil
}
// AccountUserList represents a list of account users.
type AccountUserList struct {
*Pagination
Items []*AccountUser
}
// AccountUser represents a Scalr account user.
type AccountUser struct {
ID string `jsonapi:"primary,account-users"`
Status AccountUserStatus `jsonapi:"attr,status"`
// Relations
Account *Account `jsonapi:"relation,account"`
User *User `jsonapi:"relation,user"`
Teams []*Team `jsonapi:"relation,teams"`
}
// List all the account users.
func (s *accountUsers) List(ctx context.Context, options AccountUserListOptions) (*AccountUserList, error) {
if err := options.validate(); err != nil {
return nil, err
}
req, err := s.client.newRequest("GET", "account-users", &options)
if err != nil {
return nil, err
}
aul := &AccountUserList{}
err = s.client.do(ctx, req, aul)
if err != nil {
return nil, err
}
return aul, nil
}