2
0
Эх сурвалжийг харах

Release v1.1.0 Fixes (#3644)

* fix(go): check for all networks access;

* fix(go): skip group on error;

* fix(go): stabilize get user remote access gw;

* fix(go): use existing extclient sort function;

---------

Co-authored-by: Abhishek K <[email protected]>
Vishal Dalwadi 15 цаг өмнө
parent
commit
57bf34da16

+ 25 - 11
controllers/ext_client.go

@@ -703,20 +703,34 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
 			logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
 			return
 		}
-		for _, extclient := range extclients {
-			// if device id is sent, then make sure extclient with the same device id
-			// does not exist.
-			if customExtClient.DeviceID != "" && extclient.DeviceID == customExtClient.DeviceID &&
-				extclient.OwnerID == caller.UserName && nodeid == extclient.IngressGatewayID {
-				err = errors.New("remote client config already exists on the gateway")
-				slog.Error("failed to create extclient", "user", userName, "error", err)
-				logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
-				return
+
+		// if device id is sent, we don't want to create another extclient for the same user
+		// and gw, with the same device id.
+		if customExtClient.DeviceID != "" {
+			// let's first confirm that none of the user's extclients for this gw have device id.
+			for _, extclient := range extclients {
+				if extclient.DeviceID == customExtClient.DeviceID &&
+					extclient.OwnerID == caller.UserName && nodeid == extclient.IngressGatewayID {
+					err = errors.New("remote client config already exists on the gateway")
+					slog.Error("failed to create extclient", "user", userName, "error", err)
+					logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
+					return
+				}
 			}
+		}
 
+		for _, extclient := range extclients {
 			if extclient.RemoteAccessClientID != "" &&
-				extclient.RemoteAccessClientID == customExtClient.RemoteAccessClientID && extclient.OwnerID == caller.UserName && nodeid == extclient.IngressGatewayID {
-				// extclient on the gw already exists for the remote access client
+				extclient.RemoteAccessClientID == customExtClient.RemoteAccessClientID &&
+				extclient.OwnerID == caller.UserName && nodeid == extclient.IngressGatewayID {
+				if customExtClient.DeviceID != "" && extclient.DeviceID == "" {
+					// This extclient doesn’t include a device ID (and neither do the others).
+					// We patch it by assigning the device ID from the incoming request.
+					// When clients see that the config already exists, they will fetch
+					// the one with their device ID. And we will return this one.
+					extclient.DeviceID = customExtClient.DeviceID
+					_ = logic.SaveExtClient(&extclient)
+				}
 				err = errors.New("remote client config already exists on the gateway")
 				slog.Error("failed to create extclient", "user", userName, "error", err)
 				logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))

+ 6 - 5
pro/controllers/users.go

@@ -10,11 +10,6 @@ import (
 	"strings"
 	"time"
 
-	"github.com/gravitl/netmaker/pro/idp"
-	"github.com/gravitl/netmaker/pro/idp/azure"
-	"github.com/gravitl/netmaker/pro/idp/google"
-	"github.com/gravitl/netmaker/pro/idp/okta"
-
 	"github.com/google/uuid"
 	"github.com/gorilla/mux"
 	"github.com/gravitl/netmaker/database"
@@ -24,6 +19,10 @@ import (
 	"github.com/gravitl/netmaker/mq"
 	proAuth "github.com/gravitl/netmaker/pro/auth"
 	"github.com/gravitl/netmaker/pro/email"
+	"github.com/gravitl/netmaker/pro/idp"
+	"github.com/gravitl/netmaker/pro/idp/azure"
+	"github.com/gravitl/netmaker/pro/idp/google"
+	"github.com/gravitl/netmaker/pro/idp/okta"
 	proLogic "github.com/gravitl/netmaker/pro/logic"
 	"github.com/gravitl/netmaker/servercfg"
 	"github.com/gravitl/netmaker/utils"
@@ -1508,6 +1507,8 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
 	}
 
 	for ingressGatewayID, extClients := range userExtClients {
+		logic.SortExtClient(extClients)
+
 		node, ok := userGwNodes[ingressGatewayID]
 		if !ok {
 			continue