Skip to content

Commit f3b2c10

Browse files
authored
feat(iam): add LockUser and UnlockUser method (scaleway#2292)
1 parent 5109ac7 commit f3b2c10

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

api/iam/v1alpha1/iam_sdk.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,11 @@ func (r *ListUsersResponse) UnsafeAppend(res interface{}) (uint32, error) {
20692069
return uint32(len(results.Users)), nil
20702070
}
20712071

2072+
// LockUserRequest: lock user request.
2073+
type LockUserRequest struct {
2074+
UserID string `json:"-"`
2075+
}
2076+
20722077
// RemoveGroupMemberRequest: remove group member request.
20732078
type RemoveGroupMemberRequest struct {
20742079
// GroupID: ID of the group.
@@ -2107,6 +2112,11 @@ type SetRulesResponse struct {
21072112
Rules []*Rule `json:"rules"`
21082113
}
21092114

2115+
// UnlockUserRequest: unlock user request.
2116+
type UnlockUserRequest struct {
2117+
UserID string `json:"-"`
2118+
}
2119+
21102120
// UpdateAPIKeyRequest: update api key request.
21112121
type UpdateAPIKeyRequest struct {
21122122
// AccessKey: access key to update.
@@ -2512,6 +2522,60 @@ func (s *API) UpdateUserPassword(req *UpdateUserPasswordRequest, opts ...scw.Req
25122522
return &resp, nil
25132523
}
25142524

2525+
// LockUser: Lock a user. Note that a locked user cannot log in or use API keys until the locked status is removed.
2526+
func (s *API) LockUser(req *LockUserRequest, opts ...scw.RequestOption) (*User, error) {
2527+
var err error
2528+
2529+
if fmt.Sprint(req.UserID) == "" {
2530+
return nil, errors.New("field UserID cannot be empty in request")
2531+
}
2532+
2533+
scwReq := &scw.ScalewayRequest{
2534+
Method: "POST",
2535+
Path: "/iam/v1alpha1/users/" + fmt.Sprint(req.UserID) + "/lock",
2536+
}
2537+
2538+
err = scwReq.SetBody(req)
2539+
if err != nil {
2540+
return nil, err
2541+
}
2542+
2543+
var resp User
2544+
2545+
err = s.client.Do(scwReq, &resp, opts...)
2546+
if err != nil {
2547+
return nil, err
2548+
}
2549+
return &resp, nil
2550+
}
2551+
2552+
// UnlockUser: Unlock a user.
2553+
func (s *API) UnlockUser(req *UnlockUserRequest, opts ...scw.RequestOption) (*User, error) {
2554+
var err error
2555+
2556+
if fmt.Sprint(req.UserID) == "" {
2557+
return nil, errors.New("field UserID cannot be empty in request")
2558+
}
2559+
2560+
scwReq := &scw.ScalewayRequest{
2561+
Method: "POST",
2562+
Path: "/iam/v1alpha1/users/" + fmt.Sprint(req.UserID) + "/unlock",
2563+
}
2564+
2565+
err = scwReq.SetBody(req)
2566+
if err != nil {
2567+
return nil, err
2568+
}
2569+
2570+
var resp User
2571+
2572+
err = s.client.Do(scwReq, &resp, opts...)
2573+
if err != nil {
2574+
return nil, err
2575+
}
2576+
return &resp, nil
2577+
}
2578+
25152579
// ListApplications: List the applications of an Organization. By default, the applications listed are ordered by creation date in ascending order. This can be modified via the `order_by` field. You must define the `organization_id` in the query path of your request. You can also define additional parameters for your query such as `application_ids`.
25162580
func (s *API) ListApplications(req *ListApplicationsRequest, opts ...scw.RequestOption) (*ListApplicationsResponse, error) {
25172581
var err error

0 commit comments

Comments
 (0)