Skip to content

Commit

Permalink
fix(NET-1540): add expiry time to rac connection data
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceix committed Sep 5, 2024
1 parent 8308c2f commit 884d27f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions models/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type UserRemoteGws struct {
Metadata string `json:"metadata"`
AllowedEndpoints []string `json:"allowed_endpoints"`
NetworkAddresses []string `json:"network_addresses"`
ExpiryTime time.Time `json:"expiry_time"`
}

// UserRemoteGwsReq - struct to hold user remote acccess gws req
Expand Down
2 changes: 2 additions & 0 deletions pro/controllers/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
Metadata: node.Metadata,
AllowedEndpoints: getAllowedRagEndpoints(&node, host),
NetworkAddresses: []string{network.AddressRange, network.AddressRange6},
ExpiryTime: proLogic.GetExtClientExpiryTime(user),
})
userGws[node.Network] = gws
delete(userGwNodes, node.ID.String())
Expand Down Expand Up @@ -918,6 +919,7 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
Metadata: node.Metadata,
AllowedEndpoints: getAllowedRagEndpoints(&node, host),
NetworkAddresses: []string{network.AddressRange, network.AddressRange6},
ExpiryTime: proLogic.GetExtClientExpiryTime(user),
})
userGws[node.Network] = gws
}
Expand Down
20 changes: 20 additions & 0 deletions pro/logic/extclients.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package logic

import (
"time"

"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/servercfg"
)

// GetExtClientExpiryTime - returns the expiry time for the external client
func GetExtClientExpiryTime(owner *models.User) time.Time {
if servercfg.GetServerConfig().RacAutoDisable {
if owner.PlatformRoleID == models.SuperAdminRole || owner.PlatformRoleID == models.AdminRole {
return time.Time{}
}
validityDuration := servercfg.GetJwtValidityDuration()
return owner.LastLoginTime.Add(validityDuration)
}
return time.Time{}
}

0 comments on commit 884d27f

Please sign in to comment.