mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-30 00:09:42 +01:00
Preload namespace so the name can be shown
This commit is contained in:
parent
7287e0259c
commit
7ce4738d8a
@ -231,7 +231,7 @@ func (h *Headscale) GetMachine(namespace string, name string) (*Machine, error)
|
|||||||
// GetMachineByID finds a Machine by ID and returns the Machine struct
|
// GetMachineByID finds a Machine by ID and returns the Machine struct
|
||||||
func (h *Headscale) GetMachineByID(id uint64) (*Machine, error) {
|
func (h *Headscale) GetMachineByID(id uint64) (*Machine, error) {
|
||||||
m := Machine{}
|
m := Machine{}
|
||||||
if result := h.db.Find(&Machine{ID: id}).First(&m); result.Error != nil {
|
if result := h.db.Preload("Namespace").Find(&Machine{ID: id}).First(&m); result.Error != nil {
|
||||||
return nil, result.Error
|
return nil, result.Error
|
||||||
}
|
}
|
||||||
return &m, nil
|
return &m, nil
|
||||||
|
@ -104,13 +104,17 @@ func (h *Headscale) ListSharedMachinesInNamespace(name string) (*[]Machine, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sharedNodes := []SharedNode{}
|
sharedNodes := []SharedNode{}
|
||||||
if err := h.db.Preload("Namespace").Preload("Machine").Where(&SharedNode{NamespaceID: n.ID}).Find(&sharedNodes).Error; err != nil {
|
if err := h.db.Preload("Namespace").Where(&SharedNode{NamespaceID: n.ID}).Find(&sharedNodes).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
machines := []Machine{}
|
machines := []Machine{}
|
||||||
for _, sn := range sharedNodes {
|
for _, sn := range sharedNodes {
|
||||||
machines = append(machines, sn.Machine)
|
m, err := h.GetMachineByID(sn.MachineID) // otherwise not everything comes filled
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
machines = append(machines, *m)
|
||||||
}
|
}
|
||||||
return &machines, nil
|
return &machines, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user