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

View File

@@ -2,20 +2,21 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for create backend
type BackendCreateRequest struct {
// ID of the load balancer instance to backendCreate
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Must be unique among all backends of this load balancer - name of the new backend to create
// Required: true
BackendName string `url:"backendName" json:"backendName"`
BackendName string `url:"backendName" json:"backendName" validate:"required"`
// Algorithm
// Should be one of:
@@ -23,7 +24,7 @@ type BackendCreateRequest struct {
// - static-rr
// - leastconn
// Required: false
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty"`
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty" validate:"omitempty,lbAlgorithm"`
// Interval in milliseconds between two consecutive availability
// checks of the server that is considered available
@@ -66,22 +67,13 @@ type BackendCreateRequest struct {
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
}
func (lbrq BackendCreateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName can not be empty")
}
return nil
}
// BackendCreate creates new backend on the specified load balancer
func (l LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/backendCreate"

View File

@@ -2,39 +2,31 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete backend
type BackendDeleteRequest struct {
// ID of the load balancer instance to BackendDelete
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Cannot be emtpy string - name of the backend to delete
// Required: true
BackendName string `url:"backendName" json:"backendName"`
}
func (lbrq BackendDeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName can not be empty")
}
return nil
BackendName string `url:"backendName" json:"backendName" validate:"required"`
}
// BackendDelete deletes backend from the specified load balancer.
// Warning: you cannot undo this action!
func (l LB) BackendDelete(ctx context.Context, req BackendDeleteRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/backendDelete"

View File

@@ -2,32 +2,33 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for add server definition to the backend
type BackendServerAddRequest struct {
// ID of the load balancer instance to BackendServerAdd
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Must match one of the existing backens - name of the backend to add servers to
// Required: true
BackendName string `url:"backendName" json:"backendName"`
BackendName string `url:"backendName" json:"backendName" validate:"required"`
// Must be unique among all servers defined for this backend - name of the server definition to add
// Required: true
ServerName string `url:"serverName" json:"serverName"`
ServerName string `url:"serverName" json:"serverName" validate:"required"`
// IP address of the server
// Required: true
Address string `url:"address" json:"address"`
Address string `url:"address" json:"address" validate:"required"`
// Port number on the server
// Required: true
Port uint64 `url:"port" json:"port"`
Port uint64 `url:"port" json:"port" validate:"required"`
// Set to disabled if this server should be used regardless of its state
// Required: false
@@ -71,31 +72,13 @@ type BackendServerAddRequest struct {
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
}
func (lbrq BackendServerAddRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName can not be empty")
}
if lbrq.ServerName == "" {
return errors.New("validation-error: field ServerName can not be empty")
}
if lbrq.Address == "" {
return errors.New("validation-error: field Address can not be empty")
}
if lbrq.Port == 0 {
return errors.New("validation-error: field Port can not be empty or equal to 0")
}
return nil
}
// BackendServerAdd adds server definition to the backend on the specified load balancer
func (l LB) BackendServerAdd(ctx context.Context, req BackendServerAddRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/backendServerAdd"

View File

@@ -2,46 +2,35 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete server definition
type BackendServerDeleteRequest struct {
// ID of the load balancer instance to BackendServerDelete
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Must match one of the existing backens - name of the backend to add servers to
// Required: true
BackendName string `url:"backendName" json:"backendName"`
BackendName string `url:"backendName" json:"backendName" validate:"required"`
// Must be unique among all servers defined for this backend - name of the server definition to add
// Required: true
ServerName string `url:"serverName" json:"serverName"`
}
func (lbrq BackendServerDeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName can not be empty")
}
if lbrq.ServerName == "" {
return errors.New("validation-error: field ServerName can not be empty")
}
return nil
ServerName string `url:"serverName" json:"serverName" validate:"required"`
}
// BackendServerDelete deletes server definition from the backend on the specified load balancer.
// Warning: you cannot undo this action!
func (l LB) BackendServerDelete(ctx context.Context, req BackendServerDeleteRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/backendServerDelete"

View File

@@ -2,32 +2,33 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update server
type BackendServerUpdateRequest struct {
// ID of the load balancer instance to BackendServerAdd
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Must match one of the existing backens - name of the backend to add servers to
// Required: true
BackendName string `url:"backendName" json:"backendName"`
BackendName string `url:"backendName" json:"backendName" validate:"required"`
// Must be unique among all servers defined for this backend - name of the server definition to add
// Required: true
ServerName string `url:"serverName" json:"serverName"`
ServerName string `url:"serverName" json:"serverName" validate:"required"`
// IP address of the server
// Required: true
Address string `url:"address" json:"address"`
Address string `url:"address" json:"address" validate:"required"`
// Port number on the server
// Required: true
Port uint64 `url:"port" json:"port"`
Port uint64 `url:"port" json:"port" validate:"required"`
// Set to disabled if this server should be used regardless of its state
// Required: false
@@ -71,31 +72,13 @@ type BackendServerUpdateRequest struct {
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
}
func (lbrq BackendServerUpdateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName can not be empty")
}
if lbrq.ServerName == "" {
return errors.New("validation-error: field ServerName can not be empty")
}
if lbrq.Address == "" {
return errors.New("validation-error: field Address can not be empty")
}
if lbrq.Port == 0 {
return errors.New("validation-error: field Port can not be empty or equal to 0")
}
return nil
}
// BackendServerUpdate updates server definition on the backend of load balancer
func (l LB) BackendServerUpdate(ctx context.Context, req BackendServerUpdateRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/backendServerUpdate"

View File

@@ -2,20 +2,21 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update backend
type BackendUpdateRequest struct {
// ID of the load balancer instance to backendCreate
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Must be unique among all backends of this load balancer - name of the new backend to create
// Required: true
BackendName string `url:"backendName" json:"backendName"`
BackendName string `url:"backendName" json:"backendName" validate:"required"`
// Algorithm
// Should be one of:
@@ -23,7 +24,7 @@ type BackendUpdateRequest struct {
// - static-rr
// - leastconn
// Required: false
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty"`
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty" validate:"omitempty,lbAlgorithm"`
// Interval in milliseconds between two consecutive availability
// checks of the server that is considered available
@@ -66,22 +67,13 @@ type BackendUpdateRequest struct {
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
}
func (lbrq BackendUpdateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName can not be empty")
}
return nil
}
// BackendUpdate updates existing backend on the specified load balancer. Note that backend name cannot be changed
func (l LB) BackendUpdate(ctx context.Context, req BackendUpdateRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/backendUpdate"

View File

@@ -2,32 +2,27 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for reset config
type ConfigResetRequest struct {
// ID of the load balancer instance to ConfigReset
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
}
func (lbrq ConfigResetRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
return nil
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
}
// ConfigReset reset current software configuration of the specified load balancer.
// Warning: this action cannot be undone!
func (l LB) ConfigReset(ctx context.Context, req ConfigResetRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/configReset"

View File

@@ -2,61 +2,47 @@ package lb
import (
"context"
"errors"
"net/http"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for create load balancer
type CreateRequest struct {
// ID of the resource group where this load balancer instance will be located
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Name of the load balancer.
// Must be unique among all load balancers in this Resource Group
// Required: true
Name string `url:"name" json:"name"`
Name string `url:"name" json:"name" validate:"required"`
// External network to connect this load balancer to
// Required: true
ExtNetID uint64 `url:"extnetId" json:"extnetId"`
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
// Internal network (VINS) to connect this load balancer to
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId"`
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Start now Load balancer
// Required: false
Start bool `url:"start" json:"start"`
// Required: true
Start bool `url:"start" json:"start" validate:"required"`
// Text description of this load balancer
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
}
func (lbrq CreateRequest) validate() error {
if lbrq.RGID == 0 {
return errors.New("validation-error: field RGID can not be empty or equal to 0")
}
if lbrq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
if lbrq.ExtNetID == 0 {
return errors.New("validation-error: field ExtNetID can not be empty or equal to 0")
}
if lbrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
return nil
}
// Create method will create a new load balancer instance
func (l LB) Create(ctx context.Context, req CreateRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/create"

View File

@@ -2,35 +2,30 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete load balancer
type DeleteRequest struct {
// ID of the load balancer instance to delete
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Set to true to delete load balancer immediately bypassing recycle bin
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
}
func (lbrq DeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
return nil
}
// Delete deletes specified load balancer
func (l LB) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/delete"

View File

@@ -2,31 +2,26 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for disable/enable load balancer
type DisableEnableRequest struct {
// ID of the load balancer instance to disable/enable
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
}
func (lbrq DisableEnableRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
return nil
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
}
// Disable disables specified load balancer instance
func (l LB) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/disable"
@@ -46,9 +41,11 @@ func (l LB) Disable(ctx context.Context, req DisableEnableRequest) (bool, error)
// Enable enables specified load balancer instance
func (l LB) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/enable"

View File

@@ -1,5 +1,12 @@
package lb
import (
"context"
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
)
// FilterByID returns ListLB with specified ID.
func (ll ListLB) FilterByID(id uint64) ListLB {
predicate := func(ill ItemLoadBalancer) bool {
@@ -36,6 +43,26 @@ func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
return ll.FilterFunc(predicate)
}
// FilterByK8SID returns ListLB used by specified K8S cluster.
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListLB, error) {
caller := k8s.New(decortClient)
req := k8s.GetRequest{
K8SID: k8sID,
}
cluster, err := caller.Get(ctx, req)
if err != nil {
return nil, err
}
predicate := func(ill ItemLoadBalancer) bool {
return cluster.LBID == ill.ID
}
return ll.FilterFunc(predicate), nil
}
// FilterFunc allows filtering ListLB based on a user-specified predicate.
func (ll ListLB) FilterFunc(predicate func(ItemLoadBalancer) bool) ListLB {
var result ListLB

View File

@@ -2,20 +2,21 @@ package lb
import (
"context"
"errors"
"net/http"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for frontend bind
type FrontendBindRequest struct {
// ID of the load balancer instance to FrontendBind
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Name of the frontend to update
// Required: true
FrontendName string `url:"frontendName" json:"frontendName"`
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
// Name of the binding to update
// Required: true
@@ -33,25 +34,13 @@ type FrontendBindRequest struct {
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
}
func (lbrq FrontendBindRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName can not be empty")
}
if lbrq.BindingName == "" {
return errors.New("validation-error: field BindingName can not be empty")
}
return nil
}
// FrontendBind bind frontend from specified load balancer instance
func (l LB) FrontendBind(ctx context.Context, req FrontendBindRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/frontendBind"

View File

@@ -2,45 +2,34 @@ package lb
import (
"context"
"errors"
"net/http"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete bind
type FrontendBindDeleteRequest struct {
// ID of the load balancer instance to FrontendBindDelete
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Name of the frontend to delete
// Required: true
FrontendName string `url:"frontendName" json:"frontendName"`
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
// Name of the binding to delete
// Required: true
BindingName string `url:"bindingName" json:"bindingName"`
}
func (lbrq FrontendBindDeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName can not be empty")
}
if lbrq.BindingName == "" {
return errors.New("validation-error: field BindingName can not be empty")
}
return nil
BindingName string `url:"bindingName" json:"bindingName" validate:"required"`
}
// FrontendBindDelete deletes binding from the specified load balancer frontend
func (l LB) FrontendBindDelete(ctx context.Context, req FrontendBindDeleteRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/frontendBindDelete"

View File

@@ -2,24 +2,25 @@ package lb
import (
"context"
"errors"
"net/http"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update binding
type FrontendBindUpdateRequest struct {
// ID of the load balancer instance to FrontendBindUpdate
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Name of the frontend to update
// Required: true
FrontendName string `url:"frontendName" json:"frontendName"`
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
// Name of the binding to update
// Required: true
BindingName string `url:"bindingName" json:"bindingName"`
BindingName string `url:"bindingName" json:"bindingName" validate:"required"`
// If specified must be within the IP range of either Ext Net or ViNS,
// where this load balancer is connected - new IP address to use for this binding.
@@ -33,25 +34,13 @@ type FrontendBindUpdateRequest struct {
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
}
func (lbrq FrontendBindUpdateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName can not be empty")
}
if lbrq.BindingName == "" {
return errors.New("validation-error: field BindingName can not be empty")
}
return nil
}
// FrontendBindUpdate updates binding for the specified load balancer frontend
func (l LB) FrontendBindUpdate(ctx context.Context, req FrontendBindUpdateRequest) (string, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/frontendBindingUpdate"

View File

@@ -2,47 +2,36 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for create frontend
type FrontendCreateRequest struct {
// ID of the load balancer instance to FrontendCreate
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Must be unique among all frontends of
// this load balancer - name of the new frontend to create
// Required: true
FrontendName string `url:"frontendName" json:"frontendName"`
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
// Should be one of the backends existing on
// this load balancer - name of the backend to use
// Required: true
BackendName string `url:"backendName" json:"backendName"`
}
func (lbrq FrontendCreateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName can not be empty")
}
if lbrq.BackendName == "" {
return errors.New("validation-error: field BackendName can not be empty")
}
return nil
BackendName string `url:"backendName" json:"backendName" validate:"required"`
}
// FrontendCreate creates new frontend on the specified load balancer
func (l LB) FrontendCreate(ctx context.Context, req FrontendCreateRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/frontendCreate"

View File

@@ -2,39 +2,31 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete frontend
type FrontendDeleteRequest struct {
// ID of the load balancer instance to FrontendDelete
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// Name of the frontend to delete
// Required: true
FrontendName string `url:"frontendName" json:"frontendName"`
}
func (lbrq FrontendDeleteRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.FrontendName == "" {
return errors.New("validation-error: field FrontendName can not be empty")
}
return nil
FrontendName string `url:"frontendName" json:"frontendName" validate:"required"`
}
// FrontendDelete deletes frontend from the specified load balancer.
// Warning: you cannot undo this action!
func (l LB) FrontendDelete(ctx context.Context, req FrontendDeleteRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/frontendDelete"

View File

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

View File

@@ -2,31 +2,26 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for restart load balancer
type RestartRequest struct {
// ID of the load balancer instance to restart
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
}
func (lbrq RestartRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
return nil
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
}
// Restart restarts specified load balancer instance
func (l LB) Restart(ctx context.Context, req RestartRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/restart"

View File

@@ -2,31 +2,26 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for restore load balancer
type RestoreRequest struct {
// ID of the load balancer instance to restore
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
}
func (lbrq RestoreRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
return nil
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
}
// Restore restore load balancer from recycle bin
func (l LB) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/restore"

View File

@@ -2,31 +2,26 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for start load balancer
type StartRequest struct {
// ID of the load balancer instance to start
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
}
func (lbrq StartRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
return nil
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
}
// Start starts specified load balancer instance
func (l LB) Start(ctx context.Context, req StartRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/start"

View File

@@ -2,31 +2,26 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for stop load balancer
type StopRequest struct {
// ID of the load balancer instance to stop
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
}
func (lbrq StopRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
return nil
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
}
// Stop stops specified load balancer instance
func (l LB) Stop(ctx context.Context, req StopRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/start"

View File

@@ -2,39 +2,31 @@ package lb
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update load balancer
type UpdateRequest struct {
// ID of the load balancer to update
// Required: true
LBID uint64 `url:"lbId" json:"lbId"`
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
// New description of this load balancer.
// If omitted, current description is retained
// Required: true
Description string `url:"desc" json:"desc"`
}
func (lbrq UpdateRequest) validate() error {
if lbrq.LBID == 0 {
return errors.New("validation-error: field LBID can not be empty or equal to 0")
}
if lbrq.Description == "" {
return errors.New("validation-error: field Description can not be empty")
}
return nil
Description string `url:"desc" json:"desc" validate:"required"`
}
// Update updates some of load balancer attributes
func (l LB) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/lb/update"