Browse Source

Merge pull request #1031 from gravitl/feature_v0.13.0_reorder_join_register

gen new key and re-register on pull
dcarns 3 years ago
parent
commit
6c024dd5e5
2 changed files with 18 additions and 3 deletions
  1. 16 0
      netclient/command/commands.go
  2. 2 3
      netclient/functions/pull.go

+ 16 - 0
netclient/command/commands.go

@@ -1,6 +1,8 @@
 package command
 
 import (
+	"crypto/ed25519"
+	"crypto/rand"
 	"strings"
 
 	"github.com/gravitl/netmaker/logger"
@@ -8,6 +10,7 @@ import (
 	"github.com/gravitl/netmaker/netclient/daemon"
 	"github.com/gravitl/netmaker/netclient/functions"
 	"github.com/gravitl/netmaker/netclient/ncutils"
+	"github.com/gravitl/netmaker/tls"
 )
 
 // Join - join command to run from cli
@@ -87,7 +90,20 @@ func Pull(cfg *config.ClientConfig) error {
 		}
 		err = nil
 	} else {
+
 		_, err = functions.Pull(cfg.Network, true)
+		_, newKey, kerr := ed25519.GenerateKey(rand.Reader)
+		if kerr == nil {
+			if kerr := tls.SaveKey(ncutils.GetNetclientPath(), "/client.key", newKey); err != nil {
+				logger.Log(0, "error saving key", kerr.Error())
+			} else {
+				if kerr = functions.RegisterWithServer(&newKey, cfg); err != nil {
+					logger.Log(0, "registration error", kerr.Error())
+				} else {
+					daemon.Restart()
+				}
+			}
+		}
 	}
 	logger.Log(1, "reset network and peer configs")
 	if err == nil {

+ 2 - 3
netclient/functions/pull.go

@@ -19,7 +19,7 @@ import (
 )
 
 // Pull - pulls the latest config from the server, if manual it will overwrite
-func Pull(network string, manual bool) (*models.Node, error) {
+func Pull(network string, iface bool) (*models.Node, error) {
 	cfg, err := config.ReadConfig(network)
 	if err != nil {
 		return nil, err
@@ -52,7 +52,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
 	}
 	// ensure that the OS never changes
 	resNode.OS = runtime.GOOS
-	if manual {
+	if iface {
 		// check for interface change
 		if cfg.Node.Interface != resNode.Interface {
 			if err = DeleteInterface(cfg.Node.Interface, cfg.Node.PostDown); err != nil {
@@ -78,6 +78,5 @@ func Pull(network string, manual bool) (*models.Node, error) {
 	if bkupErr != nil {
 		logger.Log(0, "unable to update backup file")
 	}
-
 	return &resNode, err
 }