-
Notifications
You must be signed in to change notification settings - Fork 7
/
requests.go
121 lines (108 loc) · 4.08 KB
/
requests.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
package users
import "github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
// CreateOpts is the structure required by the Create method to create a new user.
type CreateOpts struct {
// User name.
Name string `json:"user_name" required:"true"`
// User email. The value can contain from 1 to 64 characters.
Email string `json:"user_email" required:"true"`
// The expires time of Workspace user. The format is "yyyy-MM-ddTHH:mm:ss.000 Z".
// 0 means it will never expire.
AccountExpires string `json:"account_expires,omitempty"`
// Whether to allow password modification.
EnableChangePassword *bool `json:"enable_change_password,omitempty"`
// Whether the next login requires a password reset.
NextLoginChangePassword *bool `json:"next_login_change_password,omitempty"`
// Group ID list.
GroupIds []string `json:"group_ids,omitempty"`
// User description.
Description string `json:"description,omitempty"`
// Alias name.
Alias string `json:"alias_name,omitempty"`
}
var requestOpts = golangsdk.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
}
// Create is a method to create a user using given parameters.
func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*CreateResp, error) {
b, err := golangsdk.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
var r CreateResp
_, err = c.Post(rootURL(c), b, &r, &golangsdk.RequestOpts{
MoreHeaders: requestOpts.MoreHeaders,
})
return &r, err
}
// Get is a method to obtain the user detail by its ID.
func Get(c *golangsdk.ServiceClient, userId string) (*UserDetail, error) {
var r GetResp
_, err := c.Get(resourceURL(c, userId), &r, &golangsdk.RequestOpts{
MoreHeaders: requestOpts.MoreHeaders,
})
return &r.UserDetail, err
}
// ListOpts is the structure required by the List method to query user list.
type ListOpts struct {
// User name.
Name string `q:"user_name"`
// User description, support fuzzing match.
Description string `q:"description"`
// Number of records to be queried.
// If omited, return all user's information.
Limit int `q:"limit"`
// The offset number.
Offset int `q:"offset"`
}
// List is a method to query the job details using given parameters.
func List(c *golangsdk.ServiceClient, opts ListOpts) (*QueryResp, error) {
url := rootURL(c)
query, err := golangsdk.BuildQueryString(opts)
if err != nil {
return nil, err
}
url += query.String()
var r QueryResp
_, err = c.Get(url, &r, &golangsdk.RequestOpts{
MoreHeaders: requestOpts.MoreHeaders,
})
return &r, err
}
// UpdateOpts is the structure required by the Update method to change user information.
type UpdateOpts struct {
// User email. The value can contain from 1 to 64 characters.
Email string `json:"user_email" required:"true"`
// User description.
Description *string `json:"description,omitempty"`
// The expires time of Workspace user. The format is "yyyy-MM-ddTHH:mm:ss.000Z".
// 0 means it will never expire.
AccountExpires string `json:"account_expires,omitempty"`
// Whether to allow password modification.
EnableChangePassword *bool `json:"enable_change_password,omitempty"`
// Whether the next login requires a password reset.
NextLoginChangePassword *bool `json:"next_login_change_password,omitempty"`
// Whether the password will never expires.
PasswordNeverExpires *bool `json:"password_never_expired,omitempty"`
// Whether the account is disabled.
Disabled *bool `json:"disabled,omitempty"`
}
// Update is a method to change user informaion using givin parameters.
func Update(c *golangsdk.ServiceClient, userId string, opts UpdateOpts) (*UpdateResp, error) {
b, err := golangsdk.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
var r UpdateResp
_, err = c.Put(resourceURL(c, userId), b, &r, &golangsdk.RequestOpts{
MoreHeaders: requestOpts.MoreHeaders,
})
return &r, err
}
// Delete is a method to remove an existing user using given parameters.
func Delete(c *golangsdk.ServiceClient, userId string) error {
_, err := c.Delete(resourceURL(c, userId), &golangsdk.RequestOpts{
MoreHeaders: requestOpts.MoreHeaders,
})
return err
}