Skip to content

Commit b2d3c6d

Browse files
authored
feat(iam/v1alpha1): add method to create a user (#1786)
1 parent 6966aee commit b2d3c6d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

api/iam/v1alpha1/iam_sdk.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,43 @@ func (s *API) DeleteUser(req *DeleteUserRequest, opts ...scw.RequestOption) erro
11561156
return nil
11571157
}
11581158

1159+
type CreateUserRequest struct {
1160+
// OrganizationID: ID of the Organization.
1161+
OrganizationID string `json:"organization_id"`
1162+
// Email: email of the user.
1163+
Email string `json:"email"`
1164+
}
1165+
1166+
// CreateUser: create a new user.
1167+
// Create a new user. You must define the `organization_id` and the `email` in your request.
1168+
func (s *API) CreateUser(req *CreateUserRequest, opts ...scw.RequestOption) (*User, error) {
1169+
var err error
1170+
1171+
if req.OrganizationID == "" {
1172+
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
1173+
req.OrganizationID = defaultOrganizationID
1174+
}
1175+
1176+
scwReq := &scw.ScalewayRequest{
1177+
Method: "POST",
1178+
Path: "/iam/v1alpha1/users",
1179+
Headers: http.Header{},
1180+
}
1181+
1182+
err = scwReq.SetBody(req)
1183+
if err != nil {
1184+
return nil, err
1185+
}
1186+
1187+
var resp User
1188+
1189+
err = s.client.Do(scwReq, &resp, opts...)
1190+
if err != nil {
1191+
return nil, err
1192+
}
1193+
return &resp, nil
1194+
}
1195+
11591196
type ListApplicationsRequest struct {
11601197
// OrderBy: criteria for sorting results.
11611198
// Default value: created_at_asc

0 commit comments

Comments
 (0)