Files
decort-golang-sdk/pkg/cloudbroker/compute/pfw_add.go

59 lines
1.4 KiB
Go
Raw Normal View History

2022-12-22 17:56:47 +03:00
package compute
import (
"context"
"net/http"
"strconv"
2023-03-17 12:54:34 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-12-22 17:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// PFWAddRequest struct to add port forward rule
2022-12-22 17:56:47 +03:00
type PFWAddRequest struct {
// ID of compute instance
// Required: true
2023-03-24 17:09:30 +03:00
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
2022-12-22 17:56:47 +03:00
// External start port number for the rule
// Required: true
2023-03-24 17:09:30 +03:00
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
2022-12-22 17:56:47 +03:00
// End port number (inclusive) for the ranged rule
2023-05-15 10:55:36 +03:00
// Default value: -1
2022-12-22 17:56:47 +03:00
// Required: false
2023-05-15 10:55:36 +03:00
PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
2022-12-22 17:56:47 +03:00
// Internal base port number
2024-04-16 14:26:06 +03:00
// Required: false
LocalBasePort uint64 `url:"localBasePort,omitempty" json:"localBasePort,omitempty"`
2022-12-22 17:56:47 +03:00
// Network protocol
// Should be one of:
// - tcp
// - udp
// Required: true
2023-03-24 17:09:30 +03:00
Proto string `url:"proto" json:"proto" validate:"proto"`
2022-12-22 17:56:47 +03:00
}
2023-10-25 17:37:18 +03:00
// PFWAdd adds port forward rule
2022-12-22 17:56:47 +03:00
func (c Compute) PFWAdd(ctx context.Context, req PFWAddRequest) (uint64, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-12-22 17:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return 0, validators.ValidationErrors(validators.GetErrors(err))
2022-12-22 17:56:47 +03:00
}
url := "/cloudbroker/compute/pfwAdd"
res, err := c.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
}