Files
dynamix-golang-sdk/pkg/cloudbroker/user/create.go

51 lines
1.3 KiB
Go
Raw Normal View History

2025-09-23 14:34:24 +03:00
package user
import (
"context"
"net/http"
2025-12-08 16:30:08 +03:00
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v13/internal/validators"
2025-09-23 14:34:24 +03:00
)
// CreateRequest struct for creating a user.
type CreateRequest struct {
// ID of user.
// Required: true
Username string `url:"username" json:"username" validate:"required"`
2025-12-16 14:40:04 +03:00
// Email address of the user.
2025-09-23 14:34:24 +03:00
// Required: true
2025-12-16 14:40:04 +03:00
EmailAddress string `url:"emailaddress" json:"emailaddress" validate:"required"`
2025-09-23 14:34:24 +03:00
// Password of user
// Required: false
2025-09-27 01:06:15 +03:00
// Default: strongpassword
2025-09-23 14:34:24 +03:00
Password string `url:"password,omitempty" json:"password,omitempty"`
// List of apiaccess groups this user belongs to.
// Required: false
APIAccess []uint64 `url:"apiaccess,omitempty" json:"apiaccess,omitempty"`
2025-09-27 01:06:15 +03:00
// Provider of user
// one of: bvs, decs3o
// Required: false
Provider string `url:"provider,omitempty" json:"provider,omitempty" validate:"omitempty,userProvider"`
2025-09-23 14:34:24 +03:00
}
// Create creates a user.
2025-12-16 14:40:04 +03:00
func (u User) Create(ctx context.Context, req CreateRequest) (string, error) {
2025-09-23 14:34:24 +03:00
err := validators.ValidateRequest(req)
if err != nil {
2025-12-16 14:40:04 +03:00
return "", validators.ValidationErrors(validators.GetErrors(err))
2025-09-23 14:34:24 +03:00
}
url := "/cloudbroker/user/create"
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
2025-12-16 14:40:04 +03:00
return "", err
2025-09-23 14:34:24 +03:00
}
2025-12-16 14:40:04 +03:00
return string(res), nil
2025-09-23 14:34:24 +03:00
}