mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 11:56:39 +08:00
Net 509 515 (#2496)
* NET-509 * External client config files with IPv6 endpoints now have the [] separating the address and port. * NET-515 * Increased network name max length to 32 * NET-509-515 * Updated unit test for network name max length check. * Updated extclient endpoint ip string manipulation to use sprintf * Added proper error message for network name length more than max allowed. * NET-515 small typo fix for error strings should not be capitalized
This commit is contained in:
parent
bbd1c31ccd
commit
449f3f947b
4 changed files with 20 additions and 7 deletions
|
@ -217,7 +217,12 @@ func getExtClientConf(w http.ResponseWriter, r *http.Request) {
|
||||||
if network.DefaultKeepalive != 0 {
|
if network.DefaultKeepalive != 0 {
|
||||||
keepalive = "PersistentKeepalive = " + strconv.Itoa(int(network.DefaultKeepalive))
|
keepalive = "PersistentKeepalive = " + strconv.Itoa(int(network.DefaultKeepalive))
|
||||||
}
|
}
|
||||||
gwendpoint := host.EndpointIP.String() + ":" + strconv.Itoa(host.ListenPort)
|
gwendpoint := ""
|
||||||
|
if host.EndpointIP.To4() == nil {
|
||||||
|
gwendpoint = fmt.Sprintf("[%s]:%d", host.EndpointIP.String(), host.ListenPort)
|
||||||
|
} else {
|
||||||
|
gwendpoint = fmt.Sprintf("%s:%d", host.EndpointIP.String(), host.ListenPort)
|
||||||
|
}
|
||||||
newAllowedIPs := network.AddressRange
|
newAllowedIPs := network.AddressRange
|
||||||
if newAllowedIPs != "" && network.AddressRange6 != "" {
|
if newAllowedIPs != "" && network.AddressRange6 != "" {
|
||||||
newAllowedIPs += ","
|
newAllowedIPs += ","
|
||||||
|
|
|
@ -245,6 +245,14 @@ func createNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(network.NetID) > 32 {
|
||||||
|
err := errors.New("network name shouldn't exceed 32 characters")
|
||||||
|
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
|
||||||
|
err.Error())
|
||||||
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if network.AddressRange == "" && network.AddressRange6 == "" {
|
if network.AddressRange == "" && network.AddressRange6 == "" {
|
||||||
err := errors.New("IPv4 or IPv6 CIDR required")
|
err := errors.New("IPv4 or IPv6 CIDR required")
|
||||||
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
|
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
|
||||||
|
|
|
@ -80,7 +80,7 @@ func TestDeleteNetwork(t *testing.T) {
|
||||||
err := logic.DeleteNetwork("skynet")
|
err := logic.DeleteNetwork("skynet")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
})
|
})
|
||||||
t.Run("NonExistantNetwork", func(t *testing.T) {
|
t.Run("NonExistentNetwork", func(t *testing.T) {
|
||||||
err := logic.DeleteNetwork("skynet")
|
err := logic.DeleteNetwork("skynet")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
})
|
})
|
||||||
|
@ -151,7 +151,7 @@ func TestValidateNetwork(t *testing.T) {
|
||||||
{
|
{
|
||||||
testname: "NetIDTooLong",
|
testname: "NetIDTooLong",
|
||||||
network: models.Network{
|
network: models.Network{
|
||||||
NetID: "LongNetIDName",
|
NetID: "LongNetIDNameForMaxCharactersTest",
|
||||||
},
|
},
|
||||||
errMessage: "Field validation for 'NetID' failed on the 'max' tag",
|
errMessage: "Field validation for 'NetID' failed on the 'max' tag",
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,10 +11,10 @@ import (
|
||||||
type Network struct {
|
type Network struct {
|
||||||
AddressRange string `json:"addressrange" bson:"addressrange" validate:"omitempty,cidrv4"`
|
AddressRange string `json:"addressrange" bson:"addressrange" validate:"omitempty,cidrv4"`
|
||||||
AddressRange6 string `json:"addressrange6" bson:"addressrange6" validate:"omitempty,cidrv6"`
|
AddressRange6 string `json:"addressrange6" bson:"addressrange6" validate:"omitempty,cidrv6"`
|
||||||
NetID string `json:"netid" bson:"netid" validate:"required,min=1,max=12,netid_valid"`
|
NetID string `json:"netid" bson:"netid" validate:"required,min=1,max=32,netid_valid"`
|
||||||
NodesLastModified int64 `json:"nodeslastmodified" bson:"nodeslastmodified"`
|
NodesLastModified int64 `json:"nodeslastmodified" bson:"nodeslastmodified"`
|
||||||
NetworkLastModified int64 `json:"networklastmodified" bson:"networklastmodified"`
|
NetworkLastModified int64 `json:"networklastmodified" bson:"networklastmodified"`
|
||||||
DefaultInterface string `json:"defaultinterface" bson:"defaultinterface" validate:"min=1,max=15"`
|
DefaultInterface string `json:"defaultinterface" bson:"defaultinterface" validate:"min=1,max=35"`
|
||||||
DefaultListenPort int32 `json:"defaultlistenport,omitempty" bson:"defaultlistenport,omitempty" validate:"omitempty,min=1024,max=65535"`
|
DefaultListenPort int32 `json:"defaultlistenport,omitempty" bson:"defaultlistenport,omitempty" validate:"omitempty,min=1024,max=65535"`
|
||||||
NodeLimit int32 `json:"nodelimit" bson:"nodelimit"`
|
NodeLimit int32 `json:"nodelimit" bson:"nodelimit"`
|
||||||
DefaultPostDown string `json:"defaultpostdown" bson:"defaultpostdown"`
|
DefaultPostDown string `json:"defaultpostdown" bson:"defaultpostdown"`
|
||||||
|
@ -30,7 +30,7 @@ type Network struct {
|
||||||
|
|
||||||
// SaveData - sensitive fields of a network that should be kept the same
|
// SaveData - sensitive fields of a network that should be kept the same
|
||||||
type SaveData struct { // put sensitive fields here
|
type SaveData struct { // put sensitive fields here
|
||||||
NetID string `json:"netid" bson:"netid" validate:"required,min=1,max=12,netid_valid"`
|
NetID string `json:"netid" bson:"netid" validate:"required,min=1,max=32,netid_valid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Network.SetNodesLastModified - sets nodes last modified on network, depricated
|
// Network.SetNodesLastModified - sets nodes last modified on network, depricated
|
||||||
|
@ -49,7 +49,7 @@ func (network *Network) SetDefaults() {
|
||||||
network.DefaultUDPHolePunch = "no"
|
network.DefaultUDPHolePunch = "no"
|
||||||
}
|
}
|
||||||
if network.DefaultInterface == "" {
|
if network.DefaultInterface == "" {
|
||||||
if len(network.NetID) < 13 {
|
if len(network.NetID) < 33 {
|
||||||
network.DefaultInterface = "nm-" + network.NetID
|
network.DefaultInterface = "nm-" + network.NetID
|
||||||
} else {
|
} else {
|
||||||
network.DefaultInterface = network.NetID
|
network.DefaultInterface = network.NetID
|
||||||
|
|
Loading…
Add table
Reference in a new issue