fix(poll): Normalize hostname

This function is called often. Normalization of the hostname will be written in database.
This commit is contained in:
Adrien Raffin-Caboisse 2022-03-03 23:52:25 +01:00
parent f2ea6fb30f
commit 44a5372c53
No known key found for this signature in database
GPG Key ID: 7FB60532DEBEAD6A

13
poll.go
View File

@ -83,7 +83,18 @@ func (h *Headscale) PollNetMapHandler(ctx *gin.Context) {
Str("machine", machine.Name).
Msg("Found machine in database")
machine.Name = req.Hostinfo.Hostname
hname, err := NormalizeNamespaceName(
req.Hostinfo.Hostname,
h.cfg.OIDC.StripEmaildomain,
)
if err != nil {
log.Error().
Caller().
Str("func", "handleAuthKey").
Str("hostinfo.name", req.Hostinfo.Hostname).
Err(err)
}
machine.Name = hname
machine.HostInfo = HostInfo(*req.Hostinfo)
machine.DiscoKey = DiscoPublicKeyStripPrefix(req.DiscoKey)
now := time.Now().UTC()