fix: populate console defaults on register when unset (setOnInsert never fired)
This commit is contained in:
@@ -122,25 +122,27 @@ func RegisterServer(serverID, preRegToken, hostname, ipAddress, osInfo string) (
|
||||
osType := OSTypeFromInfo(osInfo)
|
||||
protocols, sshPort, rdpPort := defaultConsoleFields(osType)
|
||||
|
||||
setFields := bson.M{
|
||||
"hostname": hostname,
|
||||
"ip_address": ipAddress,
|
||||
"os_info": osInfo,
|
||||
"os_type": osType,
|
||||
"agent_token_hash": tokenHash,
|
||||
"status": "active",
|
||||
"last_seen": now,
|
||||
"pre_reg_token": "",
|
||||
"pre_reg_expires": nil,
|
||||
}
|
||||
if len(s.ConsoleProtocols) == 0 {
|
||||
setFields["console_protocols"] = protocols
|
||||
setFields["ssh_port"] = sshPort
|
||||
setFields["rdp_port"] = rdpPort
|
||||
}
|
||||
|
||||
_, err = db.Col("servers").UpdateOne(ctx,
|
||||
bson.M{"server_id": serverID},
|
||||
bson.M{
|
||||
"$set": bson.M{
|
||||
"hostname": hostname,
|
||||
"ip_address": ipAddress,
|
||||
"os_info": osInfo,
|
||||
"os_type": osType,
|
||||
"agent_token_hash": tokenHash,
|
||||
"status": "active",
|
||||
"last_seen": now,
|
||||
"pre_reg_token": "",
|
||||
"pre_reg_expires": nil,
|
||||
},
|
||||
"$setOnInsert": bson.M{
|
||||
"console_protocols": protocols,
|
||||
"ssh_port": sshPort,
|
||||
"rdp_port": rdpPort,
|
||||
},
|
||||
"$set": setFields,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user