This commit is contained in:
2023-03-24 17:09:30 +03:00
parent 437841c8dd
commit 84b64b7d80
433 changed files with 4246 additions and 6516 deletions

View File

@@ -2,7 +2,6 @@ package sep
import (
"context"
"errors"
"net/http"
"strconv"
@@ -13,15 +12,15 @@ import (
type ConfigFieldEditRequest struct {
// Storage endpoint provider ID
// Required: true
SEPID uint64 `url:"sep_id" json:"sep_id"`
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
// Field name
// Required: true
FieldName string `url:"field_name" json:"field_name"`
FieldName string `url:"field_name" json:"field_name" validate:"required"`
// Field value
// Required: true
FieldValue string `url:"field_value" json:"field_value"`
FieldValue string `url:"field_value" json:"field_value" validate:"required"`
// Field type
// Should be one of:
@@ -31,35 +30,16 @@ type ConfigFieldEditRequest struct {
// - list
// - dict
// Required: true
FieldType string `url:"field_type" json:"field_type"`
}
func (srq ConfigFieldEditRequest) validate() error {
if srq.SEPID == 0 {
return errors.New("validation-error: field SEPID must be set")
}
if srq.FieldName == "" {
return errors.New("validation-error: field FieldName must be set")
}
if srq.FieldValue == "" {
return errors.New("validation-error: field FieldValue must be set")
}
if srq.FieldType == "" {
return errors.New("validation-error: field FieldType must be set")
}
validate := validators.StringInSlice(srq.FieldType, []string{"int", "str", "bool", "list", "dict"})
if !validate {
return errors.New("validation-error: field FieldType must be one of int, str, bool, list, dict")
}
return nil
FieldType string `url:"field_type" json:"field_type" validate:"sepFieldType"`
}
// ConfigFieldEdit edit SEP config field value
func (s SEP) ConfigFieldEdit(ctx context.Context, req ConfigFieldEditRequest) (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 := "/cloudbroker/sep/configFieldEdit"