update go.mod and imports
This commit is contained in:
@@ -2,22 +2,21 @@ package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update user access
|
||||
type UserUpdateRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId"`
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Name of the user to update
|
||||
// Required: true
|
||||
Username string `url:"userName" json:"userName"`
|
||||
Username string `url:"userName" json:"userName" validate:"required"`
|
||||
|
||||
// Access type
|
||||
// Should be one of:
|
||||
@@ -25,32 +24,16 @@ type UserUpdateRequest struct {
|
||||
// - 'RCX' for Write
|
||||
// - 'ARCXDU' for Admin
|
||||
// Required: true
|
||||
AccessType string `url:"accesstype" json:"accesstype"`
|
||||
}
|
||||
|
||||
func (crq UserUpdateRequest) validate() error {
|
||||
if crq.ComputeID == 0 {
|
||||
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
|
||||
}
|
||||
if crq.Username == "" {
|
||||
return errors.New("validation-error: field UserName can not be empty")
|
||||
}
|
||||
if crq.AccessType == "" {
|
||||
return errors.New("validation-error: field AccessType can not be empty")
|
||||
}
|
||||
validator := validators.StringInSlice(crq.AccessType, []string{"R", "RCX", "ARCXDU"})
|
||||
if !validator {
|
||||
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccessType string `url:"accesstype" json:"accesstype" validate:"accountAccessType"`
|
||||
}
|
||||
|
||||
// UserUpdate updates user access to the compute
|
||||
func (c Compute) UserUpdate(ctx context.Context, req UserUpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/userUpdate"
|
||||
|
||||
Reference in New Issue
Block a user