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.
decort-golang-sdk/pkg/cloudapi/vins/nat_rule_add.go

62 lines
1.5 KiB

package vins
import (
"context"
"net/http"
"strconv"
3 years ago
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
2 years ago
// NATRuleAddRequest struct to create NAT rules
3 years ago
type NATRuleAddRequest struct {
// VINS ID
// Required: true
3 years ago
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
3 years ago
// Internal IP address to apply this rule to
// Required: true
3 years ago
IntIP string `url:"intIp" json:"intIp" validate:"required"`
3 years ago
// External IP start port to use for this rule
// Required: true
3 years ago
ExtPortStart uint `url:"extPortStart" json:"extPortStart" validate:"required"`
3 years ago
2 years ago
// Internal IP port number to use for this rule
// Required: false
IntPort uint `url:"intPort,omitempty" json:"intPort,omitempty"`
3 years ago
// External IP end port to use for this rule
// Required: false
3 years ago
ExtPortEnd uint `url:"extPortEnd,omitempty" json:"extPortEnd,omitempty"`
3 years ago
// IP protocol type
// Should be one of:
// - "tcp"
// - "udp"
// Required: false
3 years ago
Proto string `url:"proto,omitempty" json:"proto,omitempty" validate:"omitempty,proto"`
}
3 years ago
// NATRuleAdd create NAT (port forwarding) rule on VINS
2 years ago
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (uint64, error) {
3 years ago
err := validators.ValidateRequest(req)
if err != nil {
2 years ago
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/natRuleAdd"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
2 years ago
return 0, err
}
2 years ago
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
2 years ago
return 0, err
}
return result, nil
}