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/cloudbroker/vins/nat_rule_add.go

62 lines
1.5 KiB

3 years ago
package vins
import (
"context"
"net/http"
"strconv"
3 years ago
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
3 years ago
)
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
2 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 uint64 `url:"extPortStart" json:"extPortStart" validate:"required"`
3 years ago
2 years ago
// Internal IP port number to use for this rule
// Required: false
IntPort uint64 `url:"intPort,omitempty" json:"intPort,omitempty"`
3 years ago
// External IP end port to use for this rule
// Required: false
3 years ago
ExtPortEnd uint64 `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
}
2 years ago
// NATRuleAdd creates NAT (port forwarding) rule on VINS
3 years ago
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (uint64, error) {
3 years ago
err := validators.ValidateRequest(req)
3 years ago
if err != nil {
2 years ago
return 0, validators.ValidationErrors(validators.GetErrors(err))
3 years ago
}
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
}