update go.mod and imports

1.5.8-k8s-extnet-branch v1.2.2
stSolo 2 years ago
parent f3a1a4c83f
commit 437841c8dd

@ -33,7 +33,7 @@ Decort SDK - это библиотека, написанная на языке G
Выполните команду в терминале: Выполните команду в терминале:
```bash ```bash
go get -u github.com/rudecs/decort-sdk go get -u repository.basistech.ru/BASIS/decort-golang-sdk
``` ```
## Список API ## Список API

@ -7,12 +7,12 @@ import (
"net/http" "net/http"
"strings" "strings"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/client" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/client"
) )
// HTTP-client for platform // HTTP-client for platform

@ -1,5 +1,17 @@
module repos.digitalenergy.online/BASIS/decort-golang-sdk module repository.basistech.ru/BASIS/decort-golang-sdk
go 1.20 go 1.20
require github.com/google/go-querystring v1.1.0 require (
github.com/go-playground/validator/v10 v10.11.2
github.com/google/go-querystring v1.1.0
)
require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
)

@ -1,5 +1,30 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
"time" "time"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
) )
func NewHttpClient(cfg config.Config) *http.Client { func NewHttpClient(cfg config.Config) *http.Client {

@ -6,7 +6,7 @@ import (
"net/url" "net/url"
"time" "time"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
) )
// NewLegacyHttpClient creates legacy HTTP Client // NewLegacyHttpClient creates legacy HTTP Client

@ -0,0 +1,110 @@
package validators
import "github.com/go-playground/validator/v10"
// accountCUTypeValidator is used to validate CUType field.
func accountCUTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, accountCUTypeValues)
}
// accountAccessTypeValidator is used to validate AccessType field.
func accountAccessTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, accountAccessTypeValues)
}
// bserviceDriverValidator is used to validate Driver field.
func bserviceDriverValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, bserviceDriverValues)
}
// bserviceModeValidator is used to validate Mode field.
func bserviceModeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, bserviceModeValues)
}
// computeTopologyValidator is used to validate Topology field.
func computeTopologyValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeTopologyValues)
}
// computePolicyValidator is used to validate Policy field.
func computePolicyValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computePolicyValues)
}
// computeModeValidator is used to validate Mode field.
func computeModeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeModeValues)
}
// computeDiskTypeValidator is used to validate DiskType field.
func computeDiskTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeDiskTypeValues)
}
// computeNetTypeValidator is used to validate NetType field.
func computeNetTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeNetTypeValues)
}
// computeProtoValidator is used to validate Proto field.
func computeProtoValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, computeProtoValues)
}
// imageBootTypeValidator is used to validate BootType field.
func imageBootTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, imageBootTypeValues)
}
// imageTypeValidator is used to validate ImageType field.
func imageTypeValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, imageTypeValues)
}
// imageDriversValidator is used to validate Drivers field.
func imageDriversValidator(fe validator.FieldLevel) bool {
fieldSlice, ok := fe.Field().Interface().([]string)
if !ok {
return false
}
for _, item := range fieldSlice {
if !StringInSlice(item, imageDriversValues) {
return false
}
}
return true
}
// imageArchitectureValidator is used to validate Architecture field.
func imageArchitectureValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
return StringInSlice(fieldValue, imageArchitectureValues)
}

@ -1,5 +1,25 @@
package validators package validators
import (
"errors"
"github.com/go-playground/validator/v10"
)
func ValidateRequest(req interface{}) error {
validate := getDecortValidator()
return validate.Struct(req)
}
func ValidationError(fe validator.FieldError) error {
return errors.New(errorMessage(fe))
}
//nolint:errorlint
func GetErrors(err error) validator.ValidationErrors {
return err.(validator.ValidationErrors)
}
func StringInSlice(str string, target []string) bool { func StringInSlice(str string, target []string) bool {
for _, v := range target { for _, v := range target {
if v == str { if v == str {

@ -0,0 +1,124 @@
package validators
import (
"fmt"
"strings"
"github.com/go-playground/validator/v10"
)
func errorMessage(fe validator.FieldError) string {
prefix := "validation-error:"
switch fe.Tag() {
// Default Validators
case "required":
return fmt.Sprintf("%s %s is required", prefix, fe.Field())
case "gt":
return fmt.Sprintf("%s %s can't be less or equal to zero", prefix, fe.Field())
case "min":
return fmt.Sprintf("%s %s: not enough elements", prefix, fe.Field())
case "max":
return fmt.Sprintf("%s %s: too many elements", prefix, fe.Field())
case "url":
return fmt.Sprintf("%s %s: unexpected URL format", prefix, fe.Field())
case "email":
return fmt.Sprintf("%s %s: unexpected E-Mail format", prefix, fe.Field())
// Account Validators
case "accountAccessType":
return fmt.Sprintf("%s %s must be one of the followng: %s",
prefix,
fe.Field(),
joinValues(accountAccessTypeValues))
case "accountCUType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(accountCUTypeValues))
// BService Validators
case "bserviceDriver":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(bserviceDriverValues))
case "bserviceMode":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(bserviceModeValues))
// Compute Validators
case "computeTopology":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeTopologyValues))
case "computePolicy":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computePolicyValues))
case "computeMode":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeModeValues))
case "computeDiskType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeDiskTypeValues))
case "computeNetType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeNetTypeValues))
case "computeProto":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(computeProtoValues))
// Image Validators
case "bootType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(imageBootTypeValues))
case "imageType":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(imageTypeValues))
case "imageDrivers":
return fmt.Sprintf("%s %s must contain only the following: %s",
prefix,
fe.Field(),
joinValues(imageDriversValues))
case "imageArchitecture":
return fmt.Sprintf("%s %s must be one of the following: %s",
prefix,
fe.Field(),
joinValues(imageArchitectureValues))
}
return fe.Error()
}
func joinValues(values []string) string {
return strings.Join(values, ", ")
}

@ -0,0 +1,108 @@
package validators
import (
"sync"
"github.com/go-playground/validator/v10"
)
var (
once sync.Once
instance *DecortValidator
)
type DecortValidator struct {
decortValidator *validator.Validate
}
// getDecortValidator returns singleton instance of DecortValidator.
func getDecortValidator() *validator.Validate {
if instance == nil {
once.Do(func() {
instance = new(DecortValidator)
instance.decortValidator = validator.New()
err := registerAllValidators(instance.decortValidator)
if err != nil {
panic(err)
}
})
}
return instance.decortValidator
}
// registerAllValidators registers all custom validators in DecortValidator.
func registerAllValidators(validate *validator.Validate) error {
err := validate.RegisterValidation("bootType", imageBootTypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("imageType", imageTypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("imageDrivers", imageDriversValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("imageArchitecture", imageArchitectureValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("accountAccessType", accountAccessTypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("accountCUType", accountCUTypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("bserviceDriver", bserviceDriverValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("bserviceMode", bserviceModeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("computeTopology", computeTopologyValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("computePolicy", computePolicyValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("computeMode", computeModeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("computeDiskType", computeDiskTypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("computeNetType", computeNetTypeValidator)
if err != nil {
return err
}
err = validate.RegisterValidation("computeProto", computeProtoValidator)
if err != nil {
return err
}
return nil
}

@ -0,0 +1,21 @@
package validators
var (
accountAccessTypeValues = []string{"R", "RCX", "ARCXDU"}
accountCUTypeValues = []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"}
bserviceDriverValues = []string{"KVM_X86, KVM_PPC"}
bserviceModeValues = []string{"ABSOLUTE", "RELATIVE"}
computeTopologyValues = []string{"compute", "node"}
computePolicyValues = []string{"RECOMMENDED", "REQUIRED"}
computeModeValues = []string{"EQ", "EN", "ANY"}
computeDiskTypeValues = []string{"D", "B"}
computeNetTypeValues = []string{"EXTNET", "VINS"}
computeProtoValues = []string{"tcp", "udp"}
imageBootTypeValues = []string{"uefi", "bios"}
imageTypeValues = []string{"windows", "linux", "other"}
imageDriversValues = []string{"KVM_X86"}
imageArchitectureValues = []string{"X86_64", "PPC64_LE"}
)

@ -8,10 +8,10 @@ import (
"strings" "strings"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/client" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/client"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudbroker" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
) )
// Legacy HTTP-client for platform // Legacy HTTP-client for platform

@ -1,7 +1,7 @@
package cloudapi package cloudapi
import ( import (
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
) )
// Accessing the Account method group // Accessing the Account method group

@ -2,7 +2,7 @@
package account package account
import ( import (
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces" "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
) )
// Structure for creating request to account // Structure for creating request to account

@ -2,54 +2,37 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for adding permission to access to account for a user // Request struct for adding permission to access to account for a user
type AddUserRequest struct { type AddUserRequest struct {
// ID of account to add to // ID of account to add to
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Name of the user to be given rights // Name of the user to be given rights
// Required: true // Required: true
UserID string `url:"userId" json:"userId"` UserID string `url:"userId" json:"userId" validate:"required"`
// Account permission types: // Account permission types:
// - 'R' for read only access // - 'R' for read only access
// - 'RCX' for Write // - 'RCX' for Write
// - 'ARCXDU' for Admin // - 'ARCXDU' for Admin
// Required: true // Required: true
AccessType string `url:"accesstype" json:"accesstype"` AccessType string `url:"accesstype" json:"accesstype" validate:"required,accountAccessType"`
}
func (arq AddUserRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if arq.UserID == "" {
return errors.New("validation-error: field UserID can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
} }
// AddUser gives a user access rights. // AddUser gives a user access rights.
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) { func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/addUser" url := "/cloudapi/account/addUser"

@ -3,30 +3,25 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for give list account audits // Request struct for give list account audits
type AuditsRequest struct { type AuditsRequest struct {
// ID of the account // ID of the account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq AuditsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// Audits gets audit records for the specified account object // Audits gets audit records for the specified account object
func (a Account) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) { func (a Account) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/audits" url := "/cloudapi/account/audits"

@ -2,24 +2,25 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for creating account // Request struct for creating account
type CreateRequest struct { type CreateRequest struct {
// Display name // Display name
// Required: true // Required: true
Name string `url:"name" json:"name"` Name string `url:"name" json:"name" validate:"required"`
// Name of the account // Name of the account
// Required: true // Required: true
Username string `url:"username" json:"username"` Username string `url:"username" json:"username" validate:"required"`
// Email // Email
// Required: false // Required: false
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty"` EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
// Max size of memory in MB // Max size of memory in MB
// Required: false // Required: false
@ -50,23 +51,14 @@ type CreateRequest struct {
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"` GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
} }
func (arq CreateRequest) validate() error {
if arq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
if arq.Username == "" {
return errors.New("validation-error: field Username can not be empty")
}
return nil
}
// Create creates account // Create creates account
// Setting a cloud unit maximum to -1 or empty will not put any restrictions on the resource // Setting a cloud unit maximum to -1 or empty will not put any restrictions on the resource
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) { func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, err for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/create" url := "/cloudapi/account/create"

@ -2,33 +2,29 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for delete account // Request struct for delete account
type DeleteRequest struct { type DeleteRequest struct {
// ID of account to delete // ID of account to delete
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Whether to completely delete the account // Whether to completely delete the account
// Required: false // Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"` Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
} }
func (arq DeleteRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
return nil
}
// Delete completes delete an account from the system Returns true if account is deleted or was already deleted or never existed // Delete completes delete an account from the system Returns true if account is deleted or was already deleted or never existed
func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) { func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/delete" url := "/cloudapi/account/delete"

@ -2,42 +2,34 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for revoke access to account // Request struct for revoke access to account
type DeleteUserRequest struct { type DeleteUserRequest struct {
// ID of the account // ID of the account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// ID or emailaddress of the user to remove // ID or emailaddress of the user to remove
// Required: true // Required: true
UserID string `url:"userId" json:"userId"` UserID string `url:"userId" json:"userId" validate:"required"`
// Recursively revoke access rights from owned cloudspaces and vmachines // Recursively revoke access rights from owned cloudspaces and vmachines
// Required: false // Required: false
RecursiveDelete bool `url:"recursivedelete,omitempty" json:"recursivedelete,omitempty"` RecursiveDelete bool `url:"recursivedelete,omitempty" json:"recursivedelete,omitempty"`
} }
func (arq DeleteUserRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if arq.UserID == "" {
return errors.New("validation-error: field UserID can not be empty")
}
return nil
}
// DeleteUser revokes user access from the account // DeleteUser revokes user access from the account
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) { func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/deleteUser" url := "/cloudapi/account/deleteUser"

@ -2,31 +2,26 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for change status of account // Request struct for change status of account
type DisabelEnableRequest struct { type DisableEnableRequest struct {
// ID of account // ID of account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq DisabelEnableRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// Disable disables an account // Disable disables an account
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) { func (a Account) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/disable" url := "/cloudapi/account/disable"
@ -45,10 +40,12 @@ func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, e
} }
// Enable enables an account // Enable enables an account
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) { func (a Account) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/enable" url := "/cloudapi/account/enable"

@ -3,30 +3,25 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get information about account // Request struct for get information about account
type GetRequest struct { type GetRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq GetRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// Get gets account details // Get gets account details
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) { func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/get" url := "/cloudapi/account/get"

@ -3,23 +3,16 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for calculate the currently consumed units for all cloudspaces and resource groups in the account // Request struct for calculate the currently consumed units for all cloudspaces and resource groups in the account
type GetConsumedAccountUnitsRequest struct { type GetConsumedAccountUnitsRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq GetConsumedAccountUnitsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// GetConsumedAccountUnits calculates the currently consumed units for all cloudspaces and resource groups in the account. // GetConsumedAccountUnits calculates the currently consumed units for all cloudspaces and resource groups in the account.
@ -29,9 +22,11 @@ func (arq GetConsumedAccountUnitsRequest) validate() error {
// - CU_D: consumed vdisk storage in GB // - CU_D: consumed vdisk storage in GB
// - CU_I: number of public IPs // - CU_I: number of public IPs
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest) (*ResourceLimits, error) { func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest) (*ResourceLimits, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/getConsumedAccountUnits" url := "/cloudapi/account/getConsumedAccountUnits"

@ -2,37 +2,21 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for calculate the currently consumed cloud units of the specified type for all cloudspaces and resource groups in the account // Request struct for calculate the currently consumed cloud units of the specified type for all cloudspaces and resource groups in the account
type GetConsumedCloudUnitsByTypeRequest struct { type GetConsumedCloudUnitsByTypeRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Cloud unit resource type // Cloud unit resource type
// Required: true // Required: true
CUType string `url:"cutype" json:"cutype"` CUType string `url:"cutype" json:"cutype" validate:"required,accountCUType"`
}
func (arq GetConsumedCloudUnitsByTypeRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if arq.CUType == "" {
return errors.New("validation-error: field CUType can not be empty")
}
isValid := validators.StringInSlice(arq.CUType, []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"})
if !isValid {
return errors.New("validation-error: field AccessType can be only CU_M, CU_C, CU_D, CU_S, CU_A, CU_NO, CU_I or CU_NP")
}
return nil
} }
// GetConsumedCloudUnitsByType calculates the currently consumed cloud units of the specified type for all cloudspaces // GetConsumedCloudUnitsByType calculates the currently consumed cloud units of the specified type for all cloudspaces
@ -48,9 +32,11 @@ func (arq GetConsumedCloudUnitsByTypeRequest) validate() error {
// - CU_NP: returns sent/received network transfer peering in GB // - CU_NP: returns sent/received network transfer peering in GB
// - CU_I: returns number of public IPs // - CU_I: returns number of public IPs
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest) (float64, error) { func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest) (float64, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, err for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/getConsumedCloudUnitsByType" url := "/cloudapi/account/getConsumedCloudUnitsByType"

@ -2,47 +2,36 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for download the resources tracking files for an account // Request struct for download the resources tracking files for an account
type GetConsumtionRequest struct { type GetConsumptionRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Epoch represents the start time // Epoch represents the start time
// Required: true // Required: true
Start uint64 `url:"start" json:"start"` Start uint64 `url:"start" json:"start" validate:"required"`
// Epoch represents the end time // Epoch represents the end time
// Required: true // Required: true
End uint64 `url:"end" json:"end"` End uint64 `url:"end" json:"end" validate:"required"`
} }
func (arq GetConsumtionRequest) validate() error { // GetConsumption downloads the resources tracking files for an account within a given period
if arq.AccountID == 0 { func (a Account) GetConsumption(ctx context.Context, req GetConsumptionRequest) (string, error) {
return errors.New("validation-error: field AccountID can not be empty or equal to 0") err := validators.ValidateRequest(req)
}
if arq.Start == 0 {
return errors.New("validation-error: field Start can not be empty or equal to 0")
}
if arq.End == 0 {
return errors.New("validation-error: field End can not be empty or equal to 0")
}
return nil
}
// GetConsumtion downloads the resources tracking files for an account within a given period
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest) (string, error) {
err := req.validate()
if err != nil { if err != nil {
return "", err for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/getConsumtion" url := "/cloudapi/account/getConsumption"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req) res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil { if err != nil {
@ -53,14 +42,16 @@ func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest) (s
} }
// GetConsumtionGet downloads the resources tracking files for an account within a given period // GetConsumptionGet downloads the resources tracking files for an account within a given period
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest) (string, error) { func (a Account) GetConsumptionGet(ctx context.Context, req GetConsumptionRequest) (string, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return "", err for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
} }
url := "/cloudapi//account/getConsumtion" url := "/cloudapi/account/getConsumption"
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req) res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil { if err != nil {

@ -3,23 +3,16 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for calculate the reserved units for all cloudspaces and resource groups in the account // Request struct for calculate the reserved units for all cloudspaces and resource groups in the account
type GetReservedAccountUnitsRequest struct { type GetReservedAccountUnitsRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq GetReservedAccountUnitsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// GetReservedAccountUnits calculates the reserved units for all cloudspaces and resource groups in the account. // GetReservedAccountUnits calculates the reserved units for all cloudspaces and resource groups in the account.
@ -30,9 +23,11 @@ func (arq GetReservedAccountUnitsRequest) validate() error {
// - CU_D: reserved vdisk storage in GB // - CU_D: reserved vdisk storage in GB
// - CU_I: number of public IPs // - CU_I: number of public IPs
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest) (*ResourceLimits, error) { func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest) (*ResourceLimits, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/getReservedAccountUnits" url := "/cloudapi/account/getReservedAccountUnits"

@ -3,30 +3,25 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for a get list compute instances // Request struct for a get list compute instances
type ListComputesRequest struct { type ListComputesRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq ListComputesRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// ListComputes gets list all compute instances under specified account, accessible by the user // ListComputes gets list all compute instances under specified account, accessible by the user
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) { func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/listComputes" url := "/cloudapi/account/listComputes"

@ -3,30 +3,25 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get list deleted disks // Request struct for get list deleted disks
type ListDisksRequest struct { type ListDisksRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq ListDisksRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// ListDisks gets list all currently unattached disks under specified account // ListDisks gets list all currently unattached disks under specified account
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) { func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/listDisks" url := "/cloudapi/account/listDisks"

@ -3,30 +3,25 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get list FLIPGroups // Request struct for get list FLIPGroups
type ListFLIPGroupsRequest struct { type ListFLIPGroupsRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq ListFLIPGroupsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user // ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user
func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (ListFLIPGroups, error) { func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (ListFLIPGroups, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/listFlipGroups" url := "/cloudapi/account/listFlipGroups"

@ -3,30 +3,25 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get list resource groups // Request struct for get list resource groups
type ListRGRequest struct { type ListRGRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq ListRGRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// ListRG gets list all resource groups under specified account, accessible by the user // ListRG gets list all resource groups under specified account, accessible by the user
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) { func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/listRG" url := "/cloudapi/account/listRG"

@ -3,34 +3,29 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get list templates // Request struct for get list templates
type ListTemplatesRequest struct { type ListTemplatesRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Include deleted images // Include deleted images
// Required: false // Required: false
IncludeDeleted bool `url:"includedeleted" json:"includedeleted"` IncludeDeleted bool `url:"includedeleted" json:"includedeleted"`
} }
func (arq ListTemplatesRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
}
// ListTemplates gets list templates which can be managed by this account // ListTemplates gets list templates which can be managed by this account
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (ListTemplates, error) { func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (ListTemplates, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/listTemplates" url := "/cloudapi/account/listTemplates"

@ -3,30 +3,25 @@ package account
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get list VINS // Request struct for get list VINS
type ListVINSRequest struct { type ListVINSRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq ListVINSRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// ListVINS gets list all ViNSes under specified account, accessible by the user // ListVINS gets list all ViNSes under specified account, accessible by the user
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) { func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/listVins" url := "/cloudapi/account/listVins"

@ -2,31 +2,26 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for restore a deleted account // Request struct for restore a deleted account
type RestoreRequest struct { type RestoreRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
func (arq RestoreRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
} }
// Restore restores a deleted account // Restore restores a deleted account
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) { func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/restore" url := "/cloudapi/account/restore"

@ -3,7 +3,7 @@ package account
import ( import (
"encoding/json" "encoding/json"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
) )
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions. // Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.

@ -2,16 +2,17 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for updaate account // Request struct for updaate account
type UpdateRequest struct { type UpdateRequest struct {
// ID an account // ID an account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Name of the account // Name of the account
// Required: false // Required: false
@ -46,19 +47,13 @@ type UpdateRequest struct {
GPUUnits uint64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"` GPUUnits uint64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
} }
func (arq UpdateRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
}
// Update updates an account name and resource types and limits // Update updates an account name and resource types and limits
func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) { func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/update" url := "/cloudapi/account/update"

@ -2,54 +2,37 @@ package account
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "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 rights // Request struct for update user access rights
type UpdateUserRequest struct { type UpdateUserRequest struct {
// ID of the account // ID of the account
// Required: true // Required: true
AccountID uint64 `url:"accountId" json:"accountId"` AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Userid/Email for registered users or emailaddress for unregistered users // Userid/Email for registered users or emailaddress for unregistered users
// Required: true // Required: true
UserID string `url:"userId" json:"userId"` UserID string `url:"userId" json:"userId" validate:"required"`
// Account permission types: // Account permission types:
// - 'R' for read only access // - 'R' for read only access
// - 'RCX' for Write // - 'RCX' for Write
// - 'ARCXDU' for Admin // - 'ARCXDU' for Admin
// Required: true // Required: true
AccessType string `url:"accesstype" json:"accesstype"` AccessType string `url:"accesstype" json:"accesstype" validate:"required,accountAccessType"`
}
func (arq UpdateUserRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if arq.UserID == "" {
return errors.New("validation-error: field UserID can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
} }
// UpdateUser updates user access rights // UpdateUser updates user access rights
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) { func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/account/updateUser" url := "/cloudapi/account/updateUser"

@ -1,6 +1,6 @@
package cloudapi package cloudapi
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/bservice" import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
// Accessing the BService method group // Accessing the BService method group
func (ca *CloudAPI) BService() *bservice.BService { func (ca *CloudAPI) BService() *bservice.BService {

@ -1,7 +1,7 @@
// API Actor for managing Compute Group. This actor is a final API for endusers to manage Compute Group // API Actor for managing Compute Group. This actor is a final API for endusers to manage Compute Group
package bservice package bservice
import "repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces" import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to bservice // Structure for creating request to bservice
type BService struct { type BService struct {

@ -2,20 +2,21 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for BasicService // Request struct for BasicService
type CreateRequest struct { type CreateRequest struct {
// Name of the service // Name of the service
// Required: true // Required: true
Name string `url:"name" json:"name"` Name string `url:"name" json:"name" validate:"required"`
// ID of the Resource Group where this service will be placed // ID of the Resource Group where this service will be placed
// Required: true // Required: true
RGID uint64 `url:"rgId" json:"rgId"` RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Name of the user to deploy SSH key for. Pass empty string if no SSH key deployment is required // Name of the user to deploy SSH key for. Pass empty string if no SSH key deployment is required
// Required: false // Required: false
@ -26,22 +27,13 @@ type CreateRequest struct {
SSHKey string `url:"sshKey,omitempty" json:"sshKey,omitempty"` SSHKey string `url:"sshKey,omitempty" json:"sshKey,omitempty"`
} }
func (bsrq CreateRequest) validate() error {
if bsrq.Name == "" {
return errors.New("field Name can not be empty")
}
if bsrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// Create creates blank BasicService instance // Create creates blank BasicService instance
func (b BService) Create(ctx context.Context, req CreateRequest) (uint64, error) { func (b BService) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, err for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/create" url := "/cloudapi/bservice/create"

@ -2,35 +2,30 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for delete basic service // Request struct for delete basic service
type DeleteRequest struct { type DeleteRequest struct {
// ID of the BasicService to be delete // ID of the BasicService to be delete
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// If set to False, Basic service will be deleted to recycle bin. Otherwise destroyed immediately // If set to False, Basic service will be deleted to recycle bin. Otherwise destroyed immediately
// Required: true // Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"` Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
} }
func (bsrq DeleteRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
}
// Delete deletes BasicService instance // Delete deletes BasicService instance
func (b BService) Delete(ctx context.Context, req DeleteRequest) (bool, error) { func (b BService) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/delete" url := "/cloudapi/bservice/delete"

@ -2,33 +2,28 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for disable service // Request struct for disable service
type DisableRequest struct { type DisableRequest struct {
// ID of the service to disable // ID of the service to disable
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
}
func (bsrq DisableRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
} }
// Disable disables service. // Disable disables service.
// Disabling a service technically means setting model status // Disabling a service technically means setting model status
// of all computes and service itself to DISABLED and stopping all computes. // of all computes and service itself to DISABLED and stopping all computes.
func (b BService) Disable(ctx context.Context, req DisableRequest) (bool, error) { func (b BService) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/delete" url := "/cloudapi/bservice/delete"

@ -2,24 +2,17 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for disable service // Request struct for disable service
type EnableRequest struct { type EnableRequest struct {
// ID of the service to enable // ID of the service to enable
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
}
func (bsrq EnableRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
} }
// Enable enables service. // Enable enables service.
@ -27,9 +20,11 @@ func (bsrq EnableRequest) validate() error {
// all computes and service itself to ENABLED. // all computes and service itself to ENABLED.
// It does not start computes. // It does not start computes.
func (b BService) Enable(ctx context.Context, req EnableRequest) (bool, error) { func (b BService) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/enable" url := "/cloudapi/bservice/enable"

@ -0,0 +1,152 @@
package bservice
import "testing"
var bservices = ListBasicServices{
{
AccountID: 1,
AccountName: "std_1",
BaseDomain: "",
CreatedBy: "sample_user_1@decs3o",
CreatedTime: 1677743675,
DeletedBy: "",
DeletedTime: 0,
GID: 212,
Groups: []uint64{},
GUID: 1,
ID: 1,
Name: "bservice_1",
ParentSrvID: 0,
ParentSrvType: "",
RGID: 7971,
RGName: "rg_1",
SSHUser: "",
Status: "CREATED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
UserManaged: true,
},
{
AccountID: 2,
AccountName: "std_2",
BaseDomain: "",
CreatedBy: "sample_user_1@decs3o",
CreatedTime: 1677743736,
DeletedBy: "",
DeletedTime: 0,
GID: 212,
Groups: []uint64{},
GUID: 2,
ID: 2,
Name: "bservice_2",
ParentSrvID: 0,
ParentSrvType: "",
RGID: 7972,
RGName: "rg_2",
SSHUser: "",
Status: "CREATED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
UserManaged: true,
},
{
AccountID: 3,
AccountName: "std_3",
BaseDomain: "",
CreatedBy: "sample_user_2@decs3o",
CreatedTime: 1677743830,
DeletedBy: "",
DeletedTime: 0,
GID: 212,
Groups: []uint64{},
GUID: 3,
ID: 3,
Name: "bservice_3",
ParentSrvID: 0,
ParentSrvType: "",
RGID: 7973,
RGName: "rg_3",
SSHUser: "",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
UserManaged: true,
},
}
func TestFilterByID(t *testing.T) {
actual := bservices.FilterByID(1).FindOne()
if actual.ID != 1 {
t.Fatal("expected ID 1, found: ", actual.ID)
}
}
func TestFilterByName(t *testing.T) {
actual := bservices.FilterByName("bservice_3").FindOne()
if actual.Name != "bservice_3" {
t.Fatal("expected Name 'bservice_3', found: ", actual.Name)
}
}
func TestFilterByRGID(t *testing.T) {
actual := bservices.FilterByRGID(7971).FindOne()
if actual.RGID != 7971 {
t.Fatal("expected RGID 7971, found: ", actual.RGID)
}
}
func TestFilterByStatus(t *testing.T) {
actual := bservices.FilterByStatus("CREATED")
if len(actual) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual))
}
for _, item := range actual {
if item.Status != "CREATED" {
t.Fatal("expected Status 'CREATED', found: ", item.Status)
}
}
}
func TestFilterByTechStatus(t *testing.T) {
actual := bservices.FilterByTechStatus("STOPPED")
if len(actual) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual))
}
for _, item := range actual {
if item.TechStatus != "STOPPED" {
t.Fatal("expected TechStatus 'STOPPED', found: ", item.TechStatus)
}
}
}
func TestFilterFunc(t *testing.T) {
actual := bservices.FilterFunc(func(ibs ItemBasicService) bool {
return ibs.CreatedBy == "sample_user_2@decs3o"
})
if len(actual) > 1 {
t.Fatal("expected 1 found, actual: ", len(actual))
}
if actual.FindOne().CreatedBy != "sample_user_2@decs3o" {
t.Fatal("expected 'sample_user_2@decs3o', found: ", actual.FindOne().CreatedBy)
}
}
func TestSortByCreatedTime(t *testing.T) {
actual := bservices.SortByCreatedTime(true)
if actual[0].CreatedTime != 1677743830 || actual[2].CreatedTime != 1677743675 {
t.Fatal("expected descending order, found ascending")
}
}

@ -3,30 +3,25 @@ package bservice
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get detailed information about service // Request struct for get detailed information about service
type GetRequest struct { type GetRequest struct {
// ID of the service to query information // ID of the service to query information
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
}
func (bsrq GetRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
} }
// Get gets detailed specifications for the BasicService. // Get gets detailed specifications for the BasicService.
func (b BService) Get(ctx context.Context, req GetRequest) (*RecordBasicService, error) { func (b BService) Get(ctx context.Context, req GetRequest) (*RecordBasicService, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/get" url := "/cloudapi/bservice/get"

@ -2,47 +2,48 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for create new compute group within BasicService // Request struct for create new compute group within BasicService
type GroupAddRequest struct { type GroupAddRequest struct {
// ID of the Basic Service to add a group to // ID of the Basic Service to add a group to
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// Name of the Compute Group to add // Name of the Compute Group to add
// Required: true // Required: true
Name string `url:"name" json:"name"` Name string `url:"name" json:"name" validate:"required"`
// Computes number. Defines how many computes must be there in the group // Computes number. Defines how many computes must be there in the group
// Required: true // Required: true
Count uint64 `url:"count" json:"count"` Count uint64 `url:"count" json:"count" validate:"required"`
// Compute CPU number. All computes in the group have the same CPU count // Compute CPU number. All computes in the group have the same CPU count
// Required: true // Required: true
CPU uint64 `url:"cpu" json:"cpu"` CPU uint64 `url:"cpu" json:"cpu" validate:"required"`
// Compute RAM volume in MB. All computes in the group have the same RAM volume // Compute RAM volume in MB. All computes in the group have the same RAM volume
// Required: true // Required: true
RAM uint64 `url:"ram" json:"ram"` RAM uint64 `url:"ram" json:"ram" validate:"required"`
// Compute boot disk size in GB // Compute boot disk size in GB
// Required: true // Required: true
Disk uint64 `url:"disk" json:"disk"` Disk uint64 `url:"disk" json:"disk" validate:"required"`
// OS image ID to create computes from // OS image ID to create computes from
// Required: true // Required: true
ImageID uint64 `url:"imageId" json:"imageId"` ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
// Compute driver // Compute driver
// should be one of: // should be one of:
// - KVM_X86 // - KVM_X86
// - KVM_PPC // - KVM_PPC
// Required: true // Required: true
Driver string `url:"driver" json:"driver"` Driver string `url:"driver" json:"driver" validate:"bserviceDriver"`
// Storage endpoint provider ID // Storage endpoint provider ID
// Required: false // Required: false
@ -66,45 +67,18 @@ type GroupAddRequest struct {
// Time of Compute Group readiness // Time of Compute Group readiness
// Required: false // Required: false
TimeoutStart uint64 `url:"timeoutStart" json:"timeoutStart"` TimeoutStart uint64 `url:"timeoutStart,omitempty" json:"timeoutStart,omitempty"`
}
func (bsrq GroupAddRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.Name == "" {
return errors.New("field Name can not be empty")
}
if bsrq.Count == 0 {
return errors.New("field Count can not be empty or equal to 0")
}
if bsrq.CPU == 0 {
return errors.New("field CPU can not be empty or equal to 0")
}
if bsrq.RAM == 0 {
return errors.New("field RAM can not be empty or equal to 0")
}
if bsrq.Disk == 0 {
return errors.New("field Disk can not be empty or equal to 0")
}
if bsrq.ImageID == 0 {
return errors.New("field ImageID can not be empty or equal to 0")
}
if bsrq.Driver == "" {
return errors.New("field Driver can not be empty")
}
return nil
} }
// GroupAdd creates new Compute Group within BasicService. // GroupAdd creates new Compute Group within BasicService.
// Compute Group is NOT started automatically, // Compute Group is NOT started automatically,
// so you need to explicitly start it // so you need to explicitly start it
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest) (uint64, error) { func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest) (uint64, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, err for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupAdd" url := "/cloudapi/bservice/groupAdd"

@ -2,45 +2,34 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for remove group compute // Request struct for remove group compute
type GroupComputeRemoveRequest struct { type GroupComputeRemoveRequest struct {
// ID of the Basic Service // ID of the Basic Service
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute GROUP // ID of the Compute GROUP
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
// ID of the Compute // ID of the Compute
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (bsrq GroupComputeRemoveRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
if bsrq.ComputeID == 0 {
return errors.New("field ComputeID can not be empty or equal to 0")
}
return nil
} }
// GroupComputeRemove makes group compute remove of the Basic Service // GroupComputeRemove makes group compute remove of the Basic Service
func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest) (bool, error) { func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupComputeRemove" url := "/cloudapi/bservice/groupComputeRemove"

@ -3,37 +3,29 @@ package bservice
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get detailed information about Compute Group // Request struct for get detailed information about Compute Group
type GroupGetRequest struct { type GroupGetRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group // ID of the Compute Group
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
}
func (bsrq GroupGetRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
return nil
} }
// GroupGet gets detailed specifications for the Compute Group // GroupGet gets detailed specifications for the Compute Group
func (b BService) GroupGet(ctx context.Context, req GroupGetRequest) (*RecordGroup, error) { func (b BService) GroupGet(ctx context.Context, req GroupGetRequest) (*RecordGroup, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupGet" url := "/cloudapi/bservice/groupGet"

@ -2,9 +2,10 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for add parent Compute Group relation emove parent Compute Group // Request struct for add parent Compute Group relation emove parent Compute Group
@ -12,36 +13,24 @@ import (
type GroupParentAddRequest struct { type GroupParentAddRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group // ID of the Compute Group
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
// ID of the parent Compute Group to register with the current Compute Group // ID of the parent Compute Group to register with the current Compute Group
// Required: true // Required: true
ParentID uint64 `url:"parentId" json:"parentId"` ParentID uint64 `url:"parentId" json:"parentId" validate:"required"`
}
func (bsrq GroupParentAddRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
if bsrq.ParentID == 0 {
return errors.New("field ParentID can not be empty or equal to 0")
}
return nil
} }
// GroupParentAdd add parent Compute Group relation to the specified Compute Group // GroupParentAdd add parent Compute Group relation to the specified Compute Group
func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest) (bool, error) { func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupParentAdd" url := "/cloudapi/bservice/groupParentAdd"

@ -2,9 +2,10 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for remove parent Compute Group // Request struct for remove parent Compute Group
@ -12,37 +13,25 @@ import (
type GroupParentRemoveRequest struct { type GroupParentRemoveRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group // ID of the Compute Group
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
// ID of the parent Compute Group // ID of the parent Compute Group
// to remove from the current Compute Group // to remove from the current Compute Group
// Required: true // Required: true
ParentID uint64 `url:"parentId" json:"parentId"` ParentID uint64 `url:"parentId" json:"parentId" validate:"required"`
}
func (bsrq GroupParentRemoveRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
if bsrq.ParentID == 0 {
return errors.New("field ParentID can not be empty or equal to 0")
}
return nil
} }
// GroupParentRemove removes parent Compute Group relation to the specified Compute Group // GroupParentRemove removes parent Compute Group relation to the specified Compute Group
func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest) (bool, error) { func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupParentRemove" url := "/cloudapi/bservice/groupParentRemove"

@ -2,38 +2,30 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for destroy the specified Compute Group // Request struct for destroy the specified Compute Group
type GroupRemoveRequest struct { type GroupRemoveRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group // ID of the Compute Group
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
}
func (bsrq GroupRemoveRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
return nil
} }
// GroupRemove destroy the specified Compute Group // GroupRemove destroy the specified Compute Group
func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest) (bool, error) { func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupRemove" url := "/cloudapi/bservice/groupRemove"

@ -2,58 +2,41 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for resize the group // Request struct for resize the group
type GroupResizeRequest struct { type GroupResizeRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group to resize // ID of the Compute Group to resize
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
// Either delta or absolute value of computes // Either delta or absolute value of computes
// Required: true // Required: true
Count int64 `url:"count" json:"count"` Count int64 `url:"count" json:"count" validate:"required"`
// Either delta or absolute value of computes // Either delta or absolute value of computes
// Should be one of: // Should be one of:
// - ABSOLUTE // - ABSOLUTE
// - RELATIVE // - RELATIVE
// Required: true // Required: true
Mode string `url:"mode" json:"mode"` Mode string `url:"mode" json:"mode" validate:"bserviceMode"`
}
func (bsrq GroupResizeRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
if bsrq.Mode == "RELATIVE" && bsrq.Count == 0 {
return errors.New("field Count can not be equal to 0 if Mode if 'RELATIVE'")
}
validate := validators.StringInSlice(bsrq.Mode, []string{"RELATIVE", "ABSOLUTE"})
if !validate {
return errors.New("field Mode can only be one of 'RELATIVE' or 'ABSOLUTE'")
}
return nil
} }
// GroupResize resize the group by changing the number of computes // GroupResize resize the group by changing the number of computes
func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest) (uint64, error) { func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest) (uint64, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, err for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupResize" url := "/cloudapi/bservice/groupResize"

@ -2,38 +2,30 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for start the specified Compute Group // Request struct for start the specified Compute Group
type GroupStartRequest struct { type GroupStartRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group to start // ID of the Compute Group to start
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
}
func (bsrq GroupStartRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
return nil
} }
// GroupStart starts the specified Compute Group within BasicService // GroupStart starts the specified Compute Group within BasicService
func (b BService) GroupStart(ctx context.Context, req GroupStartRequest) (bool, error) { func (b BService) GroupStart(ctx context.Context, req GroupStartRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupStart" url := "/cloudapi/bservice/groupStart"

@ -2,42 +2,34 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for stop the specified Compute Group // Request struct for stop the specified Compute Group
type GroupStopRequest struct { type GroupStopRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group to stop // ID of the Compute Group to stop
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
// Force stop Compute Group // Force stop Compute Group
// Required: true // Required: false
Force bool `url:"force,omitempty" json:"force,omitempty"` Force bool `url:"force,omitempty" json:"force,omitempty"`
} }
func (bsrq GroupStopRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
return nil
}
// GroupStop stops the specified Compute Group within BasicService // GroupStop stops the specified Compute Group within BasicService
func (b BService) GroupStop(ctx context.Context, req GroupStopRequest) (bool, error) { func (b BService) GroupStop(ctx context.Context, req GroupStopRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupStop" url := "/cloudapi/bservice/groupStop"

@ -2,20 +2,21 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for update existing Compute group // Request struct for update existing Compute group
type GroupUpdateRequest struct { type GroupUpdateRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group // ID of the Compute Group
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
// Specify non-empty string to update Compute Group name // Specify non-empty string to update Compute Group name
// Required: false // Required: false
@ -42,22 +43,13 @@ type GroupUpdateRequest struct {
Force bool `url:"force,omitempty" json:"force,omitempty"` Force bool `url:"force,omitempty" json:"force,omitempty"`
} }
func (bsrq GroupUpdateRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
return nil
}
// GroupUpdate updates existing Compute group within Basic Service and apply new settings to its computes as necessary // GroupUpdate updates existing Compute group within Basic Service and apply new settings to its computes as necessary
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) { func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupUpdate" url := "/cloudapi/bservice/groupUpdate"

@ -2,42 +2,34 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for update External Network settings // Request struct for update External Network settings
type GroupUpdateExtNetRequest struct { type GroupUpdateExtNetRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group // ID of the Compute Group
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
// List of Extnets to connect computes // List of Extnets to connect computes
// Required: false // Required: false
ExtNets []uint64 `url:"extnets,omitempty" json:"extnets,omitempty"` ExtNets []uint64 `url:"extnets,omitempty" json:"extnets,omitempty"`
} }
func (bsrq GroupUpdateExtNetRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
return nil
}
// GroupUpdateExtNet updates External Network settings for the group according to the new list // GroupUpdateExtNet updates External Network settings for the group according to the new list
func (b BService) GroupUpdateExtNet(ctx context.Context, req GroupUpdateExtNetRequest) (bool, error) { func (b BService) GroupUpdateExtNet(ctx context.Context, req GroupUpdateExtNetRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupUpdateExtnet" url := "/cloudapi/bservice/groupUpdateExtnet"

@ -2,42 +2,34 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for update VINS settings // Request struct for update VINS settings
type GroupUpdateVINSRequest struct { type GroupUpdateVINSRequest struct {
// ID of the Basic Service of Compute Group // ID of the Basic Service of Compute Group
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// ID of the Compute Group // ID of the Compute Group
// Required: true // Required: true
CompGroupID uint64 `url:"compgroupId" json:"compgroupId"` CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
// List of ViNSes to connect computes // List of ViNSes to connect computes
// Required: false // Required: false
VINSes []uint64 `url:"vinses,omitempty" json:"vinses,omitempty"` VINSes []uint64 `url:"vinses,omitempty" json:"vinses,omitempty"`
} }
func (bsrq GroupUpdateVINSRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.CompGroupID == 0 {
return errors.New("field CompGroupID can not be empty or equal to 0")
}
return nil
}
// GroupUpdateVINS update ViNS settings for the group according to the new list // GroupUpdateVINS update ViNS settings for the group according to the new list
func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest) (bool, error) { func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/groupUpdateVins" url := "/cloudapi/bservice/groupUpdateVins"

@ -2,31 +2,26 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for restores BasicService instance // Request struct for restores BasicService instance
type RestoreRequest struct { type RestoreRequest struct {
// ID of the BasicService to be restored // ID of the BasicService to be restored
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
}
func (bsrq RestoreRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
} }
// Restore restores BasicService instance // Restore restores BasicService instance
func (b BService) Restore(ctx context.Context, req RestoreRequest) (bool, error) { func (b BService) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/restore" url := "/cloudapi/bservice/restore"

@ -3,7 +3,7 @@ package bservice
import ( import (
"encoding/json" "encoding/json"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
) )
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions. // Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.

@ -2,38 +2,30 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for create snapshot // Request struct for create snapshot
type SnapshotCreateRequest struct { type SnapshotCreateRequest struct {
// ID of the Basic Service // ID of the Basic Service
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// Label of the snapshot // Label of the snapshot
// Required: true // Required: true
Label string `url:"label" json:"label"` Label string `url:"label" json:"label" validate:"required"`
}
func (bsrq SnapshotCreateRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.Label == "" {
return errors.New("field Label can not be empty")
}
return nil
} }
// SnapshotCreate create snapshot of the Basic Service // SnapshotCreate create snapshot of the Basic Service
func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (bool, error) { func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/snapshotCreate" url := "/cloudapi/bservice/snapshotCreate"

@ -2,38 +2,30 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for delete snapshot // Request struct for delete snapshot
type SnapshotDeleteRequest struct { type SnapshotDeleteRequest struct {
// ID of the Basic Service // ID of the Basic Service
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// Label of the snapshot // Label of the snapshot
// Required: true // Required: true
Label string `url:"label" json:"label"` Label string `url:"label" json:"label" validate:"required"`
}
func (bsrq SnapshotDeleteRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.Label == "" {
return errors.New("field Label can not be empty")
}
return nil
} }
// SnapshotDelete delete snapshot of the Basic Service // SnapshotDelete delete snapshot of the Basic Service
func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) { func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/snapshotDelete" url := "/cloudapi/bservice/snapshotDelete"

@ -3,30 +3,25 @@ package bservice
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get list existing snapshots // Request struct for get list existing snapshots
type SnapshotListRequest struct { type SnapshotListRequest struct {
// ID of the Basic Service // ID of the Basic Service
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
}
func (bsrq SnapshotListRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
} }
// SnapshotList gets list existing snapshots of the Basic Service // SnapshotList gets list existing snapshots of the Basic Service
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapshots, error) { func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapshots, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/snapshotList" url := "/cloudapi/bservice/snapshotList"

@ -2,38 +2,30 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for rollback snapshot // Request struct for rollback snapshot
type SnapshotRollbackRequest struct { type SnapshotRollbackRequest struct {
// ID of the Basic Service // ID of the Basic Service
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
// Label of the snapshot // Label of the snapshot
// Required: true // Required: true
Label string `url:"label" json:"label"` Label string `url:"label" json:"label" validate:"required"`
}
func (bsrq SnapshotRollbackRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
if bsrq.Label == "" {
return errors.New("field Label can not be empty")
}
return nil
} }
// SnapshotRollback rollback snapshot of the Basic Service // SnapshotRollback rollback snapshot of the Basic Service
func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) { func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/snapshotRollback" url := "/cloudapi/bservice/snapshotRollback"

@ -2,33 +2,28 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for start service // Request struct for start service
type StartRequest struct { type StartRequest struct {
// ID of the service to start // ID of the service to start
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
}
func (bsrq StartRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
} }
// Start starts service. // Start starts service.
// Starting a service technically means starting computes from all // Starting a service technically means starting computes from all
// service groups according to group relations // service groups according to group relations
func (b BService) Start(ctx context.Context, req StartRequest) (bool, error) { func (b BService) Start(ctx context.Context, req StartRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/start" url := "/cloudapi/bservice/start"

@ -2,33 +2,28 @@ package bservice
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for stop service // Request struct for stop service
type StopRequest struct { type StopRequest struct {
// ID of the service to stop // ID of the service to stop
// Required: true // Required: true
ServiceID uint64 `url:"serviceId" json:"serviceId"` ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
}
func (bsrq StopRequest) validate() error {
if bsrq.ServiceID == 0 {
return errors.New("field ServiceID can not be empty or equal to 0")
}
return nil
} }
// Stop stops service. // Stop stops service.
// Stopping a service technically means stopping computes from // Stopping a service technically means stopping computes from
// all service groups // all service groups
func (b BService) Stop(ctx context.Context, req StopRequest) (bool, error) { func (b BService) Stop(ctx context.Context, req StopRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/bservice/stop" url := "/cloudapi/bservice/stop"

@ -2,7 +2,7 @@
package cloudapi package cloudapi
import ( import (
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces" "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
) )
// Structure for creating request to CloudAPI groups // Structure for creating request to CloudAPI groups

@ -1,7 +1,7 @@
package cloudapi package cloudapi
import ( import (
"repos.digitalenergy.online/BASIS/decort-golang-sdk/pkg/cloudapi/compute" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
) )
// Accessing the Compute method group // Accessing the Compute method group

@ -2,37 +2,29 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for check all computes with current affinity label can start // Request struct for check all computes with current affinity label can start
type AffinityGroupCheckStartRequest struct { type AffinityGroupCheckStartRequest struct {
// ID of the resource group // ID of the resource group
// Required: true // Required: true
RGID uint64 `url:"rgId" json:"rgId"` RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Affinity group label // Affinity group label
// Required: true // Required: true
AffinityLabel string `url:"affinityLabel" json:"affinityLabel"` AffinityLabel string `url:"affinityLabel" json:"affinityLabel" validate:"required"`
}
func (crq AffinityGroupCheckStartRequest) validate() error {
if crq.RGID == 0 {
return errors.New("validation-error: field RGID can not be empty or equal to 0")
}
if crq.AffinityLabel == "" {
return errors.New("validation-error: field AffinityLabel can not be empty")
}
return nil
} }
// AffinityGroupCheckStart check all computes with current affinity label can start // AffinityGroupCheckStart check all computes with current affinity label can start
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) { func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return "", err for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/affinityGroupCheckStart" url := "/cloudapi/compute/affinityGroupCheckStart"

@ -2,31 +2,26 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for clear affinity label for compute // Request struct for clear affinity label for compute
type AffinityLabelRemoveRequest struct { type AffinityLabelRemoveRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq AffinityLabelRemoveRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// AffinityLabelRemove clear affinity label for compute // AffinityLabelRemove clear affinity label for compute
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) { func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/affinityLabelRemove" url := "/cloudapi/compute/affinityLabelRemove"

@ -2,38 +2,30 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for set affinity label for compute // Request struct for set affinity label for compute
type AffinityLabelSetRequest struct { type AffinityLabelSetRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Affinity group label // Affinity group label
// Required: true // Required: true
AffinityLabel string `url:"affinityLabel" json:"affinityLabel"` AffinityLabel string `url:"affinityLabel" json:"affinityLabel" validate:"required"`
}
func (crq AffinityLabelSetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.AffinityLabel == "" {
return errors.New("validation-error: field AffinityLabel can not be empty")
}
return nil
} }
// AffinityLabelSet set affinity label for compute // AffinityLabelSet set affinity label for compute
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) { func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/affinityLabelSet" url := "/cloudapi/compute/affinityLabelSet"

@ -3,30 +3,25 @@ package compute
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get dict of computes // Request struct for get dict of computes
type AffinityRelationsRequest struct { type AffinityRelationsRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq AffinityRelationsRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// AffinityRelations gets dict of computes divided by affinity and anti affinity rules // AffinityRelations gets dict of computes divided by affinity and anti affinity rules
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*RecordAffinityRelations, error) { func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*RecordAffinityRelations, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/affinityRelations" url := "/cloudapi/compute/affinityRelations"

@ -2,29 +2,28 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for add affinity rule // Request struct for add affinity rule
type AffinityRuleAddRequest struct { type AffinityRuleAddRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Compute or node, for whom rule applies // Compute or node, for whom rule applies
// Required: true // Required: true
Topology string `url:"topology" json:"topology"` Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule // The degree of 'strictness' of this rule
// Should be one of: // Should be one of:
// - RECOMMENDED // - RECOMMENDED
// - REQUIRED // - REQUIRED
// Required: true // Required: true
Policy string `url:"policy" json:"policy"` Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key' // The comparison mode is 'value', recorded by the specified 'key'
// Should be one of: // Should be one of:
@ -32,57 +31,24 @@ type AffinityRuleAddRequest struct {
// - EN // - EN
// - ANY // - ANY
// Required: true // Required: true
Mode string `url:"mode" json:"mode"` Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified // Key that are taken into account when analyzing this rule will be identified
// Required: true // Required: true
Key string `url:"key" json:"key"` Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule // Value that must match the key to be taken into account when analyzing this rule
// Required: true // Required: true
Value string `url:"value" json:"value"` Value string `url:"value" json:"value" validate:"required"`
}
func (crq AffinityRuleAddRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
} }
// AffinityRuleAdd add affinity rule // AffinityRuleAdd add affinity rule
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) { func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/affinityRuleAdd" url := "/cloudapi/compute/affinityRuleAdd"

@ -2,29 +2,28 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for remove affinity rule // Request struct for remove affinity rule
type AffinityRuleRemoveRequest struct { type AffinityRuleRemoveRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Compute or node, for whom rule applies // Compute or node, for whom rule applies
// Required: true // Required: true
Topology string `url:"topology" json:"topology"` Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule // The degree of 'strictness' of this rule
// Should be one of: // Should be one of:
// - RECOMMENDED // - RECOMMENDED
// - REQUIRED // - REQUIRED
// Required: true // Required: true
Policy string `url:"policy" json:"policy"` Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key' // The comparison mode is 'value', recorded by the specified 'key'
// Should be one of: // Should be one of:
@ -32,57 +31,24 @@ type AffinityRuleRemoveRequest struct {
// - EN // - EN
// - ANY // - ANY
// Required: true // Required: true
Mode string `url:"mode" json:"mode"` Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified // Key that are taken into account when analyzing this rule will be identified
// Required: true // Required: true
Key string `url:"key" json:"key"` Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule // Value that must match the key to be taken into account when analyzing this rule
// Required: true // Required: true
Value string `url:"value" json:"value"` Value string `url:"value" json:"value" validate:"required"`
}
func (crq AffinityRuleRemoveRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
} }
// AffinityRuleRemove remove affinity rule // AffinityRuleRemove remove affinity rule
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) { func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/affinityRuleRemove" url := "/cloudapi/compute/affinityRuleRemove"

@ -2,31 +2,26 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for clear affinity rules // Request struct for clear affinity rules
type AffinityRulesClearRequest struct { type AffinityRulesClearRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq AffinityRulesClearRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// AffinityRulesClear clear affinity rules // AffinityRulesClear clear affinity rules
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) { func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/affinityRulesClear" url := "/cloudapi/compute/affinityRulesClear"

@ -2,29 +2,28 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for add anti affinity rule // Request struct for add anti affinity rule
type AntiAffinityRuleAddRequest struct { type AntiAffinityRuleAddRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Compute or node, for whom rule applies // Compute or node, for whom rule applies
// Required: true // Required: true
Topology string `url:"topology" json:"topology"` Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule // The degree of 'strictness' of this rule
// Should be one of: // Should be one of:
// - RECOMMENDED // - RECOMMENDED
// - REQUIRED // - REQUIRED
// Required: true // Required: true
Policy string `url:"policy" json:"policy"` Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key' // The comparison mode is 'value', recorded by the specified 'key'
// Should be one of: // Should be one of:
@ -32,57 +31,24 @@ type AntiAffinityRuleAddRequest struct {
// - EN // - EN
// - ANY // - ANY
// Required: true // Required: true
Mode string `url:"mode" json:"mode"` Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified // Key that are taken into account when analyzing this rule will be identified
// Required: true // Required: true
Key string `url:"key" json:"key"` Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule // Value that must match the key to be taken into account when analyzing this rule
// Required: true // Required: true
Value string `url:"value" json:"value"` Value string `url:"value" json:"value" validate:"required"`
}
func (crq AntiAffinityRuleAddRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
} }
// AntiAffinityRuleAdd add anti affinity rule // AntiAffinityRuleAdd add anti affinity rule
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) { func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/antiAffinityRuleAdd" url := "/cloudapi/compute/antiAffinityRuleAdd"

@ -2,29 +2,28 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators" "repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for remove anti affinity rule // Request struct for remove anti affinity rule
type AntiAffinityRuleRemoveRequest struct { type AntiAffinityRuleRemoveRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Compute or node, for whom rule applies // Compute or node, for whom rule applies
// Required: true // Required: true
Topology string `url:"topology" json:"topology"` Topology string `url:"topology" json:"topology" validate:"computeTopology"`
// The degree of 'strictness' of this rule // The degree of 'strictness' of this rule
// Should be one of: // Should be one of:
// - RECOMMENDED // - RECOMMENDED
// - REQUIRED // - REQUIRED
// Required: true // Required: true
Policy string `url:"policy" json:"policy"` Policy string `url:"policy" json:"policy" validate:"computePolicy"`
// The comparison mode is 'value', recorded by the specified 'key' // The comparison mode is 'value', recorded by the specified 'key'
// Should be one of: // Should be one of:
@ -32,57 +31,24 @@ type AntiAffinityRuleRemoveRequest struct {
// - EN // - EN
// - ANY // - ANY
// Required: true // Required: true
Mode string `url:"mode" json:"mode"` Mode string `url:"mode" json:"mode" validate:"computeMode"`
// Key that are taken into account when analyzing this rule will be identified // Key that are taken into account when analyzing this rule will be identified
// Required: true // Required: true
Key string `url:"key" json:"key"` Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule // Value that must match the key to be taken into account when analyzing this rule
// Required: true // Required: true
Value string `url:"value" json:"value"` Value string `url:"value" json:"value" validate:"required"`
}
func (crq AntiAffinityRuleRemoveRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.Topology == "" {
return errors.New("validation-error: field Topology can not be empty")
}
validator := validators.StringInSlice(crq.Topology, []string{"compute", "node"})
if !validator {
return errors.New("validation-error: field Topology can be only compute or node")
}
if crq.Policy == "" {
return errors.New("validation-error: field Policy can not be empty")
}
validator = validators.StringInSlice(crq.Policy, []string{"RECOMMENDED", "REQUIRED"})
if !validator {
return errors.New("validation-error: field Policy can be only RECOMMENDED or REQUIRED")
}
if crq.Mode == "" {
return errors.New("validation-error: field Mode can not be empty")
}
validator = validators.StringInSlice(crq.Mode, []string{"EQ", "NE", "ANY"})
if !validator {
return errors.New("validation-error: field Mode can be only EQ, NE or ANY")
}
if crq.Key == "" {
return errors.New("validation-error: field Key can not be empty")
}
if crq.Value == "" {
return errors.New("validation-error: field Value can not be empty")
}
return nil
} }
// AntiAffinityRuleRemove remove anti affinity rule // AntiAffinityRuleRemove remove anti affinity rule
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) { func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/antiAffinityRuleRemove" url := "/cloudapi/compute/antiAffinityRuleRemove"

@ -2,31 +2,26 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for clear anti affinity rules // Request struct for clear anti affinity rules
type AntiAffinityRulesClearRequest struct { type AntiAffinityRulesClearRequest struct {
// ID of the compute instance // ID of the compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq AntiAffinityRulesClearRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// AntiAffinityRulesClear clear anti affinity rules // AntiAffinityRulesClear clear anti affinity rules
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) { func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/antiAffinityRulesClear" url := "/cloudapi/compute/antiAffinityRulesClear"

@ -2,38 +2,30 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for attach GPU for compute // Request struct for attach GPU for compute
type AttachGPURequest struct { type AttachGPURequest struct {
// Identifier compute // Identifier compute
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Identifier vGPU // Identifier vGPU
// Required: true // Required: true
VGPUID uint64 `url:"vgpuId" json:"vgpuId"` VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
}
func (crq AttachGPURequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.VGPUID == 0 {
return errors.New("validation-error: field VGPUID can not be empty or equal to 0")
}
return nil
} }
// AttachGPU attach GPU for compute, returns vgpu id on success // AttachGPU attach GPU for compute, returns vgpu id on success
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) { func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, err for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/attachGpu" url := "/cloudapi/compute/attachGpu"

@ -2,38 +2,30 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for atttach PCI device // Request struct for atttach PCI device
type AttachPCIDeviceRequest struct { type AttachPCIDeviceRequest struct {
// Identifier compute // Identifier compute
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// PCI device ID // PCI device ID
// Required: true // Required: true
DeviceID uint64 `url:"deviceId" json:"deviceId"` DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
}
func (crq AttachPCIDeviceRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.DeviceID == 0 {
return errors.New("validation-error: field DeviceID can not be empty or equal to 0")
}
return nil
} }
// AttachPCIDevice attach PCI device // AttachPCIDevice attach PCI device
func (c Compute) AttachPCIDevice(ctx context.Context, req AttachPCIDeviceRequest) (bool, error) { func (c Compute) AttachPCIDevice(ctx context.Context, req AttachPCIDeviceRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/attachPciDevice" url := "/cloudapi/compute/attachPciDevice"

@ -3,30 +3,25 @@ package compute
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get audit records // Request struct for get audit records
type AuditsRequest struct { type AuditsRequest struct {
// ID of the compute // ID of the compute
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq AuditsRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("field ComputeID can not be empty or equal to 0")
}
return nil
} }
// Audits gets audit records for the specified compute object // Audits gets audit records for the specified compute object
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) { func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/audits" url := "/cloudapi/compute/audits"

@ -2,31 +2,26 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for eject CD image // Request struct for eject CD image
type CDEjectRequest struct { type CDEjectRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq CDEjectRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// CDEject eject CD image to compute's CD-ROM // CDEject eject CD image to compute's CD-ROM
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) { func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/cdEject" url := "/cloudapi/compute/cdEject"

@ -2,38 +2,30 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for insert new CD image // Request struct for insert new CD image
type CDInsertRequest struct { type CDInsertRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of CD-ROM image // ID of CD-ROM image
// Required: true // Required: true
CDROMID uint64 `url:"cdromId" json:"cdromId"` CDROMID uint64 `url:"cdromId" json:"cdromId" validate:"required"`
}
func (crq CDInsertRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.CDROMID == 0 {
return errors.New("validation-error: field CDROMID can not be empty or equal to 0")
}
return nil
} }
// CDInsert insert new CD image to compute's CD-ROM // CDInsert insert new CD image to compute's CD-ROM
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) { func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/cdInsert" url := "/cloudapi/compute/cdInsert"

@ -2,46 +2,38 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for clone compute instance // Request struct for clone compute instance
type CloneRequest struct { type CloneRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name of the clone // Name of the clone
// Required: true // Required: true
Name string `url:"name" json:"name"` Name string `url:"name" json:"name" validate:"required"`
// Timestamp of the parent's snapshot to create clone from // Timestamp of the parent's snapshot to create clone from
// Required: false // Required: false
SnapshotTimestamp uint64 `url:"snapshotTimestamp" json:"snapshotTimestamp"` SnapshotTimestamp uint64 `url:"snapshotTimestamp,omitempty" json:"snapshotTimestamp,omitempty"`
// Name of the parent's snapshot to create clone from // Name of the parent's snapshot to create clone from
// Required: false // Required: false
SnapshotName string `url:"snapshotName" json:"snapshotName"` SnapshotName string `url:"snapshotName,omitempty" json:"snapshotName,omitempty"`
}
func (crq CloneRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.Name == "" {
return errors.New("validation-error: field Name can not be empty or equal to 0")
}
return nil
} }
// Clone clones compute instance // Clone clones compute instance
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) { func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, err for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/clone" url := "/cloudapi/compute/clone"

@ -2,7 +2,7 @@
package compute package compute
import ( import (
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces" "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
) )
// Structure for creating request to compute // Structure for creating request to compute

@ -2,21 +2,22 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for create template // Request struct for create template
type CreateTemplateRequest struct { type CreateTemplateRequest struct {
// ID of the compute to create template from // ID of the compute to create template from
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name to assign to the template being created // Name to assign to the template being created
// Required: true // Required: true
Name string `url:"name" json:"name"` Name string `url:"name" json:"name" validate:"required"`
// Async API call // Async API call
// For async call use CreateTemplateAsync // For async call use CreateTemplateAsync
@ -25,22 +26,13 @@ type CreateTemplateRequest struct {
async bool `url:"async"` async bool `url:"async"`
} }
func (crq CreateTemplateRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
return nil
}
// CreateTemplate create template from compute instance // CreateTemplate create template from compute instance
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) { func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, err for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
} }
req.async = false req.async = false
@ -62,9 +54,11 @@ func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest)
// CreateTemplateAsync create template from compute instance // CreateTemplateAsync create template from compute instance
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) { func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return "", err for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
} }
req.async = true req.async = true

@ -2,16 +2,17 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for delete compute // Request struct for delete compute
type DeleteRequest struct { type DeleteRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Delete permanently // Delete permanently
// Required: false // Required: false
@ -22,19 +23,13 @@ type DeleteRequest struct {
DetachDisks bool `url:"detachDisks,omitempty" json:"detachDisks,omitempty"` DetachDisks bool `url:"detachDisks,omitempty" json:"detachDisks,omitempty"`
} }
func (crq DeleteRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
}
// Delete deletes compute // Delete deletes compute
func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) { func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/delete" url := "/cloudapi/compute/delete"

@ -2,36 +2,31 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for detach vgpu for compute // Request struct for detach vgpu for compute
type DetachGPURequest struct { type DetachGPURequest struct {
// Identifier compute // Identifier compute
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Identifier virtual GPU // Identifier virtual GPU
// Required: false // Required: false
VGPUID int64 `url:"vgpuId,omitempty" json:"vgpuId,omitempty"` VGPUID int64 `url:"vgpuId,omitempty" json:"vgpuId,omitempty"`
} }
func (crq DetachGPURequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
}
// DetachGPU detach vgpu for compute. // DetachGPU detach vgpu for compute.
// If param vgpuid is equivalent -1, then detach all vgpu for compute // If param vgpuid is equivalent -1, then detach all vgpu for compute
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) { func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/detachGpu" url := "/cloudapi/compute/detachGpu"

@ -2,38 +2,30 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for detach PCI device // Request struct for detach PCI device
type DetachPCIDeviceRequest struct { type DetachPCIDeviceRequest struct {
// Identifier compute // Identifier compute
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Pci device ID // Pci device ID
// Required: true // Required: true
DeviceID uint64 `url:"deviceId" json:"deviceId"` DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
}
func (crq DetachPCIDeviceRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.DeviceID == 0 {
return errors.New("validation-error: field DeviceID can not be empty or equal to 0")
}
return nil
} }
// DetachPCIDevice detach PCI device // DetachPCIDevice detach PCI device
func (c Compute) DetachPCIDevice(ctx context.Context, req DetachPCIDeviceRequest) (bool, error) { func (c Compute) DetachPCIDevice(ctx context.Context, req DetachPCIDeviceRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/detachPciDevice" url := "/cloudapi/compute/detachPciDevice"

@ -2,31 +2,26 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for disable compute // Request struct for disable compute
type DisableRequest struct { type DisableRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq DisableRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// Disable disables compute // Disable disables compute
func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) { func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/disable" url := "/cloudapi/compute/disable"

@ -2,31 +2,32 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for create and attach disk to compute // Request struct for create and attach disk to compute
type DiskAddRequest struct { type DiskAddRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Name for disk // Name for disk
// Required: true // Required: true
DiskName string `url:"diskName" json:"diskName"` DiskName string `url:"diskName" json:"diskName" validate:"required"`
// Disk size in GB // Disk size in GB
// Required: true // Required: true
Size uint64 `url:"size" json:"size"` Size uint64 `url:"size" json:"size" validate:"required"`
// Type of the disk // Type of the disk
// Should be one of: // Should be one of:
// - D // - D
// - B // - B
// Required: false // Required: false
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty"` DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
// Storage endpoint provider ID // Storage endpoint provider ID
// By default the same with boot disk // By default the same with boot disk
@ -47,25 +48,13 @@ type DiskAddRequest struct {
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"` ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
} }
func (crq DiskAddRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.Size == 0 {
return errors.New("validation-error: field Size can not be empty or equal to 0")
}
if crq.DiskName == "" {
return errors.New("validation-error: field DiskName can not be empty or equal to 0")
}
return nil
}
// DiskAdd creates new disk and attach to compute // DiskAdd creates new disk and attach to compute
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) { func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return 0, err for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/diskAdd" url := "/cloudapi/compute/diskAdd"

@ -2,38 +2,30 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for attach disk to compute // Request struct for attach disk to compute
type DiskAttachRequest struct { type DiskAttachRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to attach // ID of the disk to attach
// Required: true // Required: true
DiskID uint64 `url:"diskId" json:"diskId"` DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
func (crq DiskAttachRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
return nil
} }
// DiskAttach attach disk to compute // DiskAttach attach disk to compute
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) { func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/diskAttach" url := "/cloudapi/compute/diskAttach"

@ -2,42 +2,34 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for detach and delete disk from compute // Request struct for detach and delete disk from compute
type DiskDelRequest struct { type DiskDelRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of disk instance // ID of disk instance
// Required: true // Required: true
DiskID uint64 `url:"diskId" json:"diskId"` DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// False if disk is to be deleted to recycle bin // False if disk is to be deleted to recycle bin
// Required: true // Required: true
Permanently bool `url:"permanently" json:"permanently"` Permanently bool `url:"permanently" json:"permanently" validate:"required"`
}
func (crq DiskDelRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
return nil
} }
// DiskDel delete disk and detach from compute // DiskDel delete disk and detach from compute
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) { func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/diskDel" url := "/cloudapi/compute/diskDel"

@ -2,38 +2,30 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for detach disk from compute // Request struct for detach disk from compute
type DiskDetachRequest struct { type DiskDetachRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to detach // ID of the disk to detach
// Required: true // Required: true
DiskID uint64 `url:"diskId" json:"diskId"` DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
func (crq DiskDetachRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
return nil
} }
// DiskDetach detach disk from compute // DiskDetach detach disk from compute
func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest) (bool, error) { func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/diskDetach" url := "/cloudapi/compute/diskDetach"

@ -2,45 +2,34 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for change QoS of the disk // Request struct for change QoS of the disk
type DiskQOSRequest struct { type DiskQOSRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to apply limits // ID of the disk to apply limits
// Required: true // Required: true
DiskID uint64 `url:"diskId" json:"diskId"` DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Limit IO for a certain disk total and read/write options are not allowed to be combined // Limit IO for a certain disk total and read/write options are not allowed to be combined
// Required: true // Required: true
Limits string `url:"limits" json:"limits"` Limits string `url:"limits" json:"limits" validate:"required"`
}
func (crq DiskQOSRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
if crq.Limits == "" {
return errors.New("validation-error: field Limits can not be empty")
}
return nil
} }
// DiskQOS change QoS of the disk // DiskQOS change QoS of the disk
func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest) (bool, error) { func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/diskQos" url := "/cloudapi/compute/diskQos"

@ -2,45 +2,34 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for change disk size // Request struct for change disk size
type DiskResizeRequest struct { type DiskResizeRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// ID of the disk to resize // ID of the disk to resize
// Required: true // Required: true
DiskID uint64 `url:"diskId" json:"diskId"` DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// New disk size // New disk size
// Required: true // Required: true
Size uint64 `url:"size" json:"size"` Size uint64 `url:"size" json:"size" validate:"required"`
}
func (crq DiskResizeRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
if crq.Size == 0 {
return errors.New("validation-error: field Size can not be empty or equal to 0")
}
return nil
} }
// DiskResize change disk size // DiskResize change disk size
func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest) (bool, error) { func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/diskResize" url := "/cloudapi/compute/diskResize"

@ -2,31 +2,26 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for enable compute // Request struct for enable compute
type EnableRequest struct { type EnableRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq EnableRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// Enable enables compute // Enable enables compute
func (c Compute) Enable(ctx context.Context, req EnableRequest) (bool, error) { func (c Compute) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return false, err for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/enable" url := "/cloudapi/compute/enable"

@ -3,30 +3,25 @@ package compute
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request for get information about compute // Request for get information about compute
type GetRequest struct { type GetRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq GetRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// Get Gets information about compute // Get Gets information about compute
func (c Compute) Get(ctx context.Context, req GetRequest) (*RecordCompute, error) { func (c Compute) Get(ctx context.Context, req GetRequest) (*RecordCompute, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/get" url := "/cloudapi/compute/get"

@ -3,30 +3,25 @@ package compute
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get compute audits // Request struct for get compute audits
type GetAuditsRequest struct { type GetAuditsRequest struct {
// ID of compute instance // ID of compute instance
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq GetAuditsRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// GetAudits gets compute audits // GetAudits gets compute audits
func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest) (ListShortAudits, error) { func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest) (ListShortAudits, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/getAudits" url := "/cloudapi/compute/getAudits"

@ -2,31 +2,26 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"strings" "strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get console URL // Request struct for get console URL
type GetConsoleURLRequest struct { type GetConsoleURLRequest struct {
// ID of compute instance to get console for // ID of compute instance to get console for
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq GetConsoleURLRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// GetConsoleURL gets computes console URL // GetConsoleURL gets computes console URL
func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest) (string, error) { func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest) (string, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return "", err for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/getConsoleUrl" url := "/cloudapi/compute/getConsoleUrl"

@ -2,37 +2,29 @@ package compute
import ( import (
"context" "context"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get compute logs // Request struct for get compute logs
type GetLogRequest struct { type GetLogRequest struct {
// ID of compute instance to get log for // ID of compute instance to get log for
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Path to log file // Path to log file
// Required: true // Required: true
Path string `url:"path" json:"path"` Path string `url:"path" json:"path" validate:"required"`
}
func (crq GetLogRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
if crq.Path == "" {
return errors.New("validation-error: field Path can not be empty")
}
return nil
} }
// GetLog gets compute's log file by path // GetLog gets compute's log file by path
func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error) { func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return "", err for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/getLog" url := "/cloudapi/compute/getLog"
@ -47,9 +39,11 @@ func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error)
// GetLogGet gets compute's log file by path // GetLogGet gets compute's log file by path
func (c Compute) GetLogGet(ctx context.Context, req GetLogRequest) (string, error) { func (c Compute) GetLogGet(ctx context.Context, req GetLogRequest) (string, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return "", err for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
} }
url := "/cloudapi//compute/getLog" url := "/cloudapi//compute/getLog"

@ -3,30 +3,25 @@ package compute
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get list PCI devices // Request struct for get list PCI devices
type ListPCIDeviceRequest struct { type ListPCIDeviceRequest struct {
// Identifier compute // Identifier compute
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq ListPCIDeviceRequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// ListPCIDevice gets list PCI device // ListPCIDevice gets list PCI device
func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([]interface{}, error) { func (c Compute) ListPCIDevice(ctx context.Context, req ListPCIDeviceRequest) ([]interface{}, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/listPciDevice" url := "/cloudapi/compute/listPciDevice"

@ -3,30 +3,25 @@ package compute
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
) )
// Request struct for get list vGPU // Request struct for get list vGPU
type ListVGPURequest struct { type ListVGPURequest struct {
// Identifier compute // Identifier compute
// Required: true // Required: true
ComputeID uint64 `url:"computeId" json:"computeId"` ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
func (crq ListVGPURequest) validate() error {
if crq.ComputeID == 0 {
return errors.New("validation-error: field ComputeID can not be empty or equal to 0")
}
return nil
} }
// ListVGPU gets list vGPU // ListVGPU gets list vGPU
func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface{}, error) { func (c Compute) ListVGPU(ctx context.Context, req ListVGPURequest) ([]interface{}, error) {
err := req.validate() err := validators.ValidateRequest(req)
if err != nil { if err != nil {
return nil, err for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
} }
url := "/cloudapi/compute/listVgpu" url := "/cloudapi/compute/listVgpu"

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save