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.
82 lines
1.7 KiB
82 lines
1.7 KiB
package vins
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
// Request struct for create NAT rules
|
|
type NATRuleAddRequest struct {
|
|
// VINS ID
|
|
// Required: true
|
|
VINSID uint64 `url:"vinsId"`
|
|
|
|
// Internal IP address to apply this rule to
|
|
// Required: true
|
|
IntIP string `url:"intIp "`
|
|
|
|
// Internal IP port number to use for this rule
|
|
// Required: true
|
|
IntPort uint `url:"intPort"`
|
|
|
|
// External IP start port to use for this rule
|
|
// Required: true
|
|
ExtPortStart uint `url:"extPortStart"`
|
|
|
|
// External IP end port to use for this rule
|
|
// Required: false
|
|
ExtPortEnd uint `url:"extPortEnd,omitempty"`
|
|
|
|
// IP protocol type
|
|
// Should be one of:
|
|
// - "tcp"
|
|
// - "udp"
|
|
// Required: false
|
|
Proto string `url:"proto,omitempty"`
|
|
|
|
// Reason for action
|
|
// Required: false
|
|
Reason string `url:"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()
|
|
if err != nil {
|
|
return 0, 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
|
|
}
|