From 35354a2a53cc41a7dba81d2aba2116b91261e825 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Tue, 29 Oct 2024 15:36:28 +0000 Subject: [PATCH] feat: update generated APIs --- api/mongodb/v1alpha1/mongodb_sdk.go | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/api/mongodb/v1alpha1/mongodb_sdk.go b/api/mongodb/v1alpha1/mongodb_sdk.go index 0f68df7e..a96240f3 100644 --- a/api/mongodb/v1alpha1/mongodb_sdk.go +++ b/api/mongodb/v1alpha1/mongodb_sdk.go @@ -718,6 +718,21 @@ type CreateSnapshotRequest struct { ExpiresAt *time.Time `json:"expires_at,omitempty"` } +// CreateUserRequest: create user request. +type CreateUserRequest struct { + // Region: region to target. If none is passed will use default region from the config. + Region scw.Region `json:"-"` + + // InstanceID: UUID of the Database Instance the user belongs to. + InstanceID string `json:"-"` + + // Name: name of the database user. + Name string `json:"-"` + + // Password: password of the database user. + Password *string `json:"password,omitempty"` +} + // DeleteInstanceRequest: delete instance request. type DeleteInstanceRequest struct { // Region: region to target. If none is passed will use default region from the config. @@ -1673,6 +1688,46 @@ func (s *API) ListUsers(req *ListUsersRequest, opts ...scw.RequestOption) (*List return &resp, nil } +// CreateUser: Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request. +func (s *API) CreateUser(req *CreateUserRequest, opts ...scw.RequestOption) (*User, error) { + var err error + + if req.Region == "" { + defaultRegion, _ := s.client.GetDefaultRegion() + req.Region = defaultRegion + } + + if fmt.Sprint(req.Region) == "" { + return nil, errors.New("field Region cannot be empty in request") + } + + if fmt.Sprint(req.InstanceID) == "" { + return nil, errors.New("field InstanceID cannot be empty in request") + } + + if fmt.Sprint(req.Name) == "" { + return nil, errors.New("field Name cannot be empty in request") + } + + scwReq := &scw.ScalewayRequest{ + Method: "POST", + Path: "/mongodb/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/instances/" + fmt.Sprint(req.InstanceID) + "/users/" + fmt.Sprint(req.Name) + "", + } + + 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 +} + // UpdateUser: Update the parameters of a user on a Database Instance. You can update the `password` parameter, but you cannot change the name of the user. func (s *API) UpdateUser(req *UpdateUserRequest, opts ...scw.RequestOption) (*User, error) { var err error