mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-07 21:54:54 +08:00
fixing some bool problems
This commit is contained in:
parent
6bc3a543f9
commit
61958d8109
6 changed files with 33 additions and 7 deletions
BIN
controllers/.nodeHttpController.go.swp
Normal file
BIN
controllers/.nodeHttpController.go.swp
Normal file
Binary file not shown.
|
@ -177,6 +177,12 @@ func UpdateNode(nodechange models.Node, node models.Node) (models.Node, error) {
|
|||
if nodechange.MacAddress != "" {
|
||||
node.MacAddress = nodechange.MacAddress
|
||||
}
|
||||
if nodechange.IsGateway != nil {
|
||||
node.IsGateway = nodechange.IsGateway
|
||||
}
|
||||
if nodechange.GatewayRange != "" {
|
||||
node.GatewayRange = nodechange.GatewayRange
|
||||
}
|
||||
if nodechange.PublicKey != "" {
|
||||
node.PublicKey = nodechange.PublicKey
|
||||
node.KeyUpdateTimeStamp = time.Now().Unix()
|
||||
|
@ -210,6 +216,8 @@ func UpdateNode(nodechange models.Node, node models.Node) (models.Node, error) {
|
|||
{"persistentkeepalive", node.PersistentKeepalive},
|
||||
{"saveconfig", node.SaveConfig},
|
||||
{"accesskey", node.AccessKey},
|
||||
{"isgateway", node.IsGateway},
|
||||
{"gatewayrange", node.GatewayRange},
|
||||
{"interface", node.Interface},
|
||||
{"lastmodified", node.LastModified},
|
||||
}},
|
||||
|
@ -221,12 +229,12 @@ func UpdateNode(nodechange models.Node, node models.Node) (models.Node, error) {
|
|||
return nodeupdate, errN
|
||||
}
|
||||
|
||||
returnnode, errN := GetNode(node.MacAddress, node.Network)
|
||||
returnnode, errN := GetNode(queryMac, queryNetwork)
|
||||
|
||||
defer cancel()
|
||||
|
||||
if notifynetwork {
|
||||
errN = SetNetworkNodesLastModified(node.Network)
|
||||
errN = SetNetworkNodesLastModified(queryNetwork)
|
||||
}
|
||||
|
||||
return returnnode, errN
|
||||
|
|
|
@ -589,7 +589,8 @@ func createGateway(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var nodechange models.Node
|
||||
|
||||
nodechange.IsGateway = true
|
||||
isgateway := true
|
||||
nodechange.IsGateway = &isgateway
|
||||
nodechange.GatewayRange = gateway.RangeString
|
||||
if gateway.PostUp == "" {
|
||||
nodechange.PostUp = "iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
|
||||
|
@ -622,7 +623,7 @@ func createGateway(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func validateGateway(gateway models.GatewayRequest) error {
|
||||
var err error
|
||||
isIpv4 := functions.IsIpv4Net(gateway.RangeString)
|
||||
isIpv4 := functions.IsIpv4CIDR(gateway.RangeString)
|
||||
empty := gateway.RangeString == ""
|
||||
if empty || !isIpv4 {
|
||||
err = errors.New("IP Range Not Valid")
|
||||
|
@ -646,7 +647,8 @@ func deleteGateway(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var nodechange models.Node
|
||||
|
||||
nodechange.IsGateway = false
|
||||
isgateway := false
|
||||
nodechange.IsGateway = &isgateway
|
||||
nodechange.GatewayRange = ""
|
||||
nodechange.PostUp = ""
|
||||
nodechange.PostDown = ""
|
||||
|
|
|
@ -41,7 +41,7 @@ type Node struct {
|
|||
Password string `json:"password" bson:"password" validate:"password_check"`
|
||||
Network string `json:"network" bson:"network" validate:"network_exists"`
|
||||
IsPending bool `json:"ispending" bson:"ispending"`
|
||||
IsGateway bool `json:"isgateway" bson:"isgateway"`
|
||||
IsGateway *bool `json:"isgateway" bson:"isgateway"`
|
||||
GatewayRange string `json:"gatewayrange" bson:"gatewayrange"`
|
||||
PostChanges string `json:"postchanges" bson:"postchanges"`
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ type ReturnNode struct {
|
|||
Interface string `json:"interface" bson:"interface"`
|
||||
Network string `json:"network" bson:"network"`
|
||||
IsPending *bool `json:"ispending" bson:"ispending"`
|
||||
IsGateway *bool `json:"isgateway" bson:"ispending"`
|
||||
IsGateway *bool `json:"isgateway" bson:"isgateway"`
|
||||
GatewayRange string `json:"gatewayrange" bson:"gatewayrange"`
|
||||
LocalAddress string `json:"localaddress" bson:"localaddress" validate:"localaddress_check"`
|
||||
ExpirationDateTime int64 `json:"expdatetime" bson:"expdatetime"`
|
||||
|
|
16
test/gatewaycreate.sh
Executable file
16
test/gatewaycreate.sh
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
generate_post_json ()
|
||||
{
|
||||
cat <<EOF
|
||||
{
|
||||
"rangestring": "172.31.0.0/16",
|
||||
"interface": "eth0"
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
POST_JSON=$(generate_post_json)
|
||||
|
||||
curl --max-time 5.0 -d "$POST_JSON" -H 'Content-Type: application/json' -H "authorization: Bearer secretkey" 3.86.23.0:8081/api/nodes/default/12:5a:ac:3f:03:2d
|
||||
|
Loading…
Add table
Reference in a new issue