Add new resources, extend fields in config

This commit is contained in:
stSolo
2022-10-06 12:53:21 +03:00
parent 5fd450382c
commit 8712561853
39 changed files with 1784 additions and 3 deletions

View File

@@ -0,0 +1,50 @@
package rg
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/internal/validators"
"net/http"
"strconv"
)
type SetDefNetRequest struct {
RGID uint64 `url:"rgId"`
NetType string `url:"netType"`
NetID uint64 `url:"netId,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (rgrq SetDefNetRequest) Validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
validate := validators.StringInSlice(rgrq.NetType, []string{"PUBLIC", "PRIVATE"})
if !validate {
return errors.New("validation-error: field NetType must be one of PRIVATE or PUBLIC")
}
return nil
}
func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudbroker/rg/setDefNet"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}