Skip to content

Commit

Permalink
feat(iam): add LockUser and UnlockUser method (scaleway#2292)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Oct 31, 2024
1 parent 5109ac7 commit f3b2c10
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions api/iam/v1alpha1/iam_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,11 @@ func (r *ListUsersResponse) UnsafeAppend(res interface{}) (uint32, error) {
return uint32(len(results.Users)), nil
}

// LockUserRequest: lock user request.
type LockUserRequest struct {
UserID string `json:"-"`
}

// RemoveGroupMemberRequest: remove group member request.
type RemoveGroupMemberRequest struct {
// GroupID: ID of the group.
Expand Down Expand Up @@ -2107,6 +2112,11 @@ type SetRulesResponse struct {
Rules []*Rule `json:"rules"`
}

// UnlockUserRequest: unlock user request.
type UnlockUserRequest struct {
UserID string `json:"-"`
}

// UpdateAPIKeyRequest: update api key request.
type UpdateAPIKeyRequest struct {
// AccessKey: access key to update.
Expand Down Expand Up @@ -2512,6 +2522,60 @@ func (s *API) UpdateUserPassword(req *UpdateUserPasswordRequest, opts ...scw.Req
return &resp, nil
}

// LockUser: Lock a user. Note that a locked user cannot log in or use API keys until the locked status is removed.
func (s *API) LockUser(req *LockUserRequest, opts ...scw.RequestOption) (*User, error) {
var err error

if fmt.Sprint(req.UserID) == "" {
return nil, errors.New("field UserID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "POST",
Path: "/iam/v1alpha1/users/" + fmt.Sprint(req.UserID) + "/lock",
}

err = scwReq.SetBody(req)
if err != nil {
return nil, err
}

var resp User

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// UnlockUser: Unlock a user.
func (s *API) UnlockUser(req *UnlockUserRequest, opts ...scw.RequestOption) (*User, error) {
var err error

if fmt.Sprint(req.UserID) == "" {
return nil, errors.New("field UserID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "POST",
Path: "/iam/v1alpha1/users/" + fmt.Sprint(req.UserID) + "/unlock",
}

err = scwReq.SetBody(req)
if err != nil {
return nil, err
}

var resp User

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// 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`.
func (s *API) ListApplications(req *ListApplicationsRequest, opts ...scw.RequestOption) (*ListApplicationsResponse, error) {
var err error
Expand Down

0 comments on commit f3b2c10

Please sign in to comment.