v1.3.0
This commit is contained in:
@@ -2,67 +2,53 @@ package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create NAT rules
|
||||
type NATRuleAddRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId"`
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||
|
||||
// Internal IP address to apply this rule to
|
||||
// Required: true
|
||||
IntIP string `url:"intIp " json:"intIp "`
|
||||
IntIP string `url:"intIp " json:"intIp " validate:"required"`
|
||||
|
||||
// Internal IP port number to use for this rule
|
||||
// Required: true
|
||||
IntPort uint `url:"intPort" json:"intPort"`
|
||||
IntPort uint64 `url:"intPort" json:"intPort" validate:"required"`
|
||||
|
||||
// External IP start port to use for this rule
|
||||
// Required: true
|
||||
ExtPortStart uint `url:"extPortStart" json:"extPortStart"`
|
||||
ExtPortStart uint64 `url:"extPortStart" json:"extPortStart" validate:"required"`
|
||||
|
||||
// External IP end port to use for this rule
|
||||
// Required: false
|
||||
ExtPortEnd uint `url:"extPortEnd,omitempty" json:"extPortEnd,omitempty"`
|
||||
ExtPortEnd uint64 `url:"extPortEnd,omitempty" json:"extPortEnd,omitempty"`
|
||||
|
||||
// IP protocol type
|
||||
// Should be one of:
|
||||
// - "tcp"
|
||||
// - "udp"
|
||||
// Required: false
|
||||
Proto string `url:"proto,omitempty" json:"proto,omitempty"`
|
||||
Proto string `url:"proto,omitempty" json:"proto,omitempty" validate:"omitempty,proto"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq NATRuleAddRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
if vrq.IntIP == "" {
|
||||
return errors.New("validation-error: field IntIP must be set")
|
||||
}
|
||||
if vrq.IntPort == 0 {
|
||||
return errors.New("validation-error: field IntPort must be set")
|
||||
}
|
||||
if vrq.ExtPortStart == 0 {
|
||||
return errors.New("validation-error: field ExtPortStart must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NATRuleAdd create NAT (port forwarding) rule on VINS
|
||||
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/natRuleAdd"
|
||||
|
||||
Reference in New Issue
Block a user