mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 01:07:41 +08:00
NET-1440: scale test changes (#3014)
* NET-1440 scale test changes * fix UT error and add error info * load metric data into cacha in startup * remove debug info for metric * add server telemetry and hasSuperAdmin to cache * fix user UT case * update sqlite connection string for performance * update check-in TS in cache only if cache enabled * update metric data in cache only if cache enabled and write to DB once in stop * update server status in mq topic * add failover existed to server status update * only send mq messsage when there is server status change * batch peerUpdate * code changes for scale for review * update UT case * update mq client check * mq connection code change * revert server status update changes * revert batch peerUpdate * remove server status update info * code changes based on review and setupmqtt in keepalive * set the mq message order to false for PIN * remove setupmqtt in keepalive * recycle ip in node deletion * update ip allocation logic * remove ip addr cap * remove ippool file * update get extClient func * remove ip from cache map when extClient is removed
This commit is contained in:
@@ -20,9 +20,21 @@ const (
|
||||
auth_key = "netmaker_auth"
|
||||
)
|
||||
|
||||
var (
|
||||
superUser = models.User{}
|
||||
)
|
||||
|
||||
func ClearSuperUserCache() {
|
||||
superUser = models.User{}
|
||||
}
|
||||
|
||||
// HasSuperAdmin - checks if server has an superadmin/owner
|
||||
func HasSuperAdmin() (bool, error) {
|
||||
|
||||
if superUser.IsSuperAdmin {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
collection, err := database.FetchRecords(database.USERS_TABLE_NAME)
|
||||
if err != nil {
|
||||
if database.IsEmptyRecord(err) {
|
||||
@@ -38,6 +50,7 @@ func HasSuperAdmin() (bool, error) {
|
||||
continue
|
||||
}
|
||||
if user.IsSuperAdmin {
|
||||
superUser = user
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
@@ -116,7 +129,7 @@ func CreateUser(user *models.User) error {
|
||||
|
||||
tokenString, _ := CreateUserJWT(user.UserName, user.IsSuperAdmin, user.IsAdmin)
|
||||
if tokenString == "" {
|
||||
logger.Log(0, "failed to generate token", err.Error())
|
||||
logger.Log(0, "failed to generate token")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -204,6 +217,9 @@ func UpsertUser(user models.User) error {
|
||||
slog.Error("error inserting user", "user", user.UserName, "error", err.Error())
|
||||
return err
|
||||
}
|
||||
if user.IsSuperAdmin {
|
||||
superUser = user
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user