From 66ebbf3ecb4a95190bdfba0cfae781a483dde535 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Wed, 28 Dec 2022 16:42:52 +0000 Subject: [PATCH] Preload AuthKey in machine getters --- machine.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/machine.go b/machine.go index a77d222..41270b2 100644 --- a/machine.go +++ b/machine.go @@ -392,7 +392,7 @@ func (h *Headscale) GetMachineByGivenName(namespace string, givenName string) (* // GetMachineByID finds a Machine by ID and returns the Machine struct. func (h *Headscale) GetMachineByID(id uint64) (*Machine, error) { m := Machine{} - if result := h.db.Preload("Namespace").Find(&Machine{ID: id}).First(&m); result.Error != nil { + if result := h.db.Preload("AuthKey").Preload("Namespace").Find(&Machine{ID: id}).First(&m); result.Error != nil { return nil, result.Error } @@ -404,7 +404,7 @@ func (h *Headscale) GetMachineByMachineKey( machineKey key.MachinePublic, ) (*Machine, error) { m := Machine{} - if result := h.db.Preload("Namespace").First(&m, "machine_key = ?", MachinePublicKeyStripPrefix(machineKey)); result.Error != nil { + if result := h.db.Preload("AuthKey").Preload("Namespace").First(&m, "machine_key = ?", MachinePublicKeyStripPrefix(machineKey)); result.Error != nil { return nil, result.Error } @@ -416,7 +416,7 @@ func (h *Headscale) GetMachineByNodeKey( nodeKey key.NodePublic, ) (*Machine, error) { machine := Machine{} - if result := h.db.Preload("Namespace").First(&machine, "node_key = ?", + if result := h.db.Preload("AuthKey").Preload("Namespace").First(&machine, "node_key = ?", NodePublicKeyStripPrefix(nodeKey)); result.Error != nil { return nil, result.Error } @@ -429,7 +429,7 @@ func (h *Headscale) GetMachineByAnyKey( machineKey key.MachinePublic, nodeKey key.NodePublic, oldNodeKey key.NodePublic, ) (*Machine, error) { machine := Machine{} - if result := h.db.Preload("Namespace").First(&machine, "machine_key = ? OR node_key = ? OR node_key = ?", + if result := h.db.Preload("AuthKey").Preload("Namespace").First(&machine, "machine_key = ? OR node_key = ? OR node_key = ?", MachinePublicKeyStripPrefix(machineKey), NodePublicKeyStripPrefix(nodeKey), NodePublicKeyStripPrefix(oldNodeKey)); result.Error != nil {