You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
62 lines
1.5 KiB
package vins
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// NATRuleAddRequest struct to create NAT rules
|
|
type NATRuleAddRequest struct {
|
|
// VINS ID
|
|
// Required: true
|
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
|
|
|
// Internal IP address to apply this rule to
|
|
// Required: true
|
|
IntIP string `url:"intIp" json:"intIp" validate:"required"`
|
|
|
|
// External IP start port to use for this rule
|
|
// Required: true
|
|
ExtPortStart uint64 `url:"extPortStart" json:"extPortStart" validate:"required"`
|
|
|
|
// Internal IP port number to use for this rule
|
|
// Required: false
|
|
IntPort uint64 `url:"intPort,omitempty" json:"intPort,omitempty"`
|
|
|
|
// External IP end port to use for this rule
|
|
// Required: false
|
|
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" validate:"omitempty,proto"`
|
|
}
|
|
|
|
// NATRuleAdd creates NAT (port forwarding) rule on VINS
|
|
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (uint64, error) {
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudbroker/vins/natRuleAdd"
|
|
|
|
res, err := v.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
|
|
}
|