mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
feat: allow to customise WireGuard listen port with --wg-port for machine init/add (#366)
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/psviderski/uncloud/internal/machine/api/pb"
|
||||
"github.com/psviderski/uncloud/internal/machine/network"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -40,18 +39,18 @@ func BindEnvToFlag(cmd *cobra.Command, flagName, envVar string) {
|
||||
}
|
||||
|
||||
// ParseWireGuardEndpoints parses a list of endpoint strings into a list of IPPort protobuf messages. Each value can
|
||||
// be an IP address, IP:PORT, IPv6, or [IPv6]:PORT. If the port is omitted, the default WireGuard port is used.
|
||||
func ParseWireGuardEndpoints(values []string) ([]*pb.IPPort, error) {
|
||||
// be an IP address, IP:PORT, IPv6, or [IPv6]:PORT. If the port is omitted, defaultPort is used.
|
||||
func ParseWireGuardEndpoints(values []string, defaultPort uint16) ([]*pb.IPPort, error) {
|
||||
endpoints := make([]*pb.IPPort, 0, len(values))
|
||||
for _, v := range values {
|
||||
ap, err := netip.ParseAddrPort(v)
|
||||
if err != nil {
|
||||
// Try parsing as a bare IP address and use the default WireGuard port.
|
||||
// Try parsing as a bare IP address and use the provided default port.
|
||||
addr, addrErr := netip.ParseAddr(v)
|
||||
if addrErr != nil {
|
||||
return nil, fmt.Errorf("invalid endpoint '%s': must be IP, IPv6, IP:PORT, or [IPv6]:PORT", v)
|
||||
}
|
||||
ap = netip.AddrPortFrom(addr, network.WireGuardPort)
|
||||
ap = netip.AddrPortFrom(addr, defaultPort)
|
||||
}
|
||||
endpoints = append(endpoints, pb.NewIPPort(ap))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user