mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 09:32:32 +08:00
add update check for validate relay
This commit is contained in:
parent
d69d0ed2e2
commit
8ac864fec8
3 changed files with 5 additions and 5 deletions
|
@ -650,7 +650,7 @@ func updateNode(w http.ResponseWriter, r *http.Request) {
|
||||||
NodeID: newNode.ID.String(),
|
NodeID: newNode.ID.String(),
|
||||||
NetID: newNode.Network,
|
NetID: newNode.Network,
|
||||||
RelayedNodes: newNode.RelayedNodes,
|
RelayedNodes: newNode.RelayedNodes,
|
||||||
})
|
}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
||||||
return
|
return
|
||||||
|
|
|
@ -29,6 +29,6 @@ var RelayUpdates = func(currentNode, newNode *models.Node) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var ValidateRelay = func(relay models.RelayRequest) error {
|
var ValidateRelay = func(relay models.RelayRequest, update bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ func CreateRelay(relay models.RelayRequest) ([]models.Node, models.Node, error)
|
||||||
if host.OS != "linux" {
|
if host.OS != "linux" {
|
||||||
return returnnodes, models.Node{}, fmt.Errorf("only linux machines can be relay nodes")
|
return returnnodes, models.Node{}, fmt.Errorf("only linux machines can be relay nodes")
|
||||||
}
|
}
|
||||||
err = ValidateRelay(relay)
|
err = ValidateRelay(relay, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return returnnodes, models.Node{}, err
|
return returnnodes, models.Node{}, err
|
||||||
}
|
}
|
||||||
|
@ -101,14 +101,14 @@ func SetRelayedNodes(setRelayed bool, relay string, relayed []string) []models.N
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// ValidateRelay - checks if relay is valid
|
// ValidateRelay - checks if relay is valid
|
||||||
func ValidateRelay(relay models.RelayRequest) error {
|
func ValidateRelay(relay models.RelayRequest, update bool) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
node, err := logic.GetNodeByID(relay.NodeID)
|
node, err := logic.GetNodeByID(relay.NodeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if node.IsRelay {
|
if !update && node.IsRelay {
|
||||||
return errors.New("node is already acting as a relay")
|
return errors.New("node is already acting as a relay")
|
||||||
}
|
}
|
||||||
for _, relayedNodeID := range relay.RelayedNodes {
|
for _, relayedNodeID := range relay.RelayedNodes {
|
||||||
|
|
Loading…
Reference in a new issue