Skip to content

Commit 57bf34d

Browse files
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]>
1 parent e2b576a commit 57bf34d

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

controllers/ext_client.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -703,20 +703,34 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
703703
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
704704
return
705705
}
706-
for _, extclient := range extclients {
707-
// if device id is sent, then make sure extclient with the same device id
708-
// does not exist.
709-
if customExtClient.DeviceID != "" && extclient.DeviceID == customExtClient.DeviceID &&
710-
extclient.OwnerID == caller.UserName && nodeid == extclient.IngressGatewayID {
711-
err = errors.New("remote client config already exists on the gateway")
712-
slog.Error("failed to create extclient", "user", userName, "error", err)
713-
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
714-
return
706+
707+
// if device id is sent, we don't want to create another extclient for the same user
708+
// and gw, with the same device id.
709+
if customExtClient.DeviceID != "" {
710+
// let's first confirm that none of the user's extclients for this gw have device id.
711+
for _, extclient := range extclients {
712+
if extclient.DeviceID == customExtClient.DeviceID &&
713+
extclient.OwnerID == caller.UserName && nodeid == extclient.IngressGatewayID {
714+
err = errors.New("remote client config already exists on the gateway")
715+
slog.Error("failed to create extclient", "user", userName, "error", err)
716+
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
717+
return
718+
}
715719
}
720+
}
716721

722+
for _, extclient := range extclients {
717723
if extclient.RemoteAccessClientID != "" &&
718-
extclient.RemoteAccessClientID == customExtClient.RemoteAccessClientID && extclient.OwnerID == caller.UserName && nodeid == extclient.IngressGatewayID {
719-
// extclient on the gw already exists for the remote access client
724+
extclient.RemoteAccessClientID == customExtClient.RemoteAccessClientID &&
725+
extclient.OwnerID == caller.UserName && nodeid == extclient.IngressGatewayID {
726+
if customExtClient.DeviceID != "" && extclient.DeviceID == "" {
727+
// This extclient doesn’t include a device ID (and neither do the others).
728+
// We patch it by assigning the device ID from the incoming request.
729+
// When clients see that the config already exists, they will fetch
730+
// the one with their device ID. And we will return this one.
731+
extclient.DeviceID = customExtClient.DeviceID
732+
_ = logic.SaveExtClient(&extclient)
733+
}
720734
err = errors.New("remote client config already exists on the gateway")
721735
slog.Error("failed to create extclient", "user", userName, "error", err)
722736
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))

pro/controllers/users.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ import (
1010
"strings"
1111
"time"
1212

13-
"github.com/gravitl/netmaker/pro/idp"
14-
"github.com/gravitl/netmaker/pro/idp/azure"
15-
"github.com/gravitl/netmaker/pro/idp/google"
16-
"github.com/gravitl/netmaker/pro/idp/okta"
17-
1813
"github.com/google/uuid"
1914
"github.com/gorilla/mux"
2015
"github.com/gravitl/netmaker/database"
@@ -24,6 +19,10 @@ import (
2419
"github.com/gravitl/netmaker/mq"
2520
proAuth "github.com/gravitl/netmaker/pro/auth"
2621
"github.com/gravitl/netmaker/pro/email"
22+
"github.com/gravitl/netmaker/pro/idp"
23+
"github.com/gravitl/netmaker/pro/idp/azure"
24+
"github.com/gravitl/netmaker/pro/idp/google"
25+
"github.com/gravitl/netmaker/pro/idp/okta"
2726
proLogic "github.com/gravitl/netmaker/pro/logic"
2827
"github.com/gravitl/netmaker/servercfg"
2928
"github.com/gravitl/netmaker/utils"
@@ -1508,6 +1507,8 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
15081507
}
15091508

15101509
for ingressGatewayID, extClients := range userExtClients {
1510+
logic.SortExtClient(extClients)
1511+
15111512
node, ok := userGwNodes[ingressGatewayID]
15121513
if !ok {
15131514
continue

0 commit comments

Comments
 (0)