diff --git a/db.go b/db.go index 4435f04..42c5eee 100644 --- a/db.go +++ b/db.go @@ -44,7 +44,7 @@ func (h *Headscale) initDB() error { return err } - err = db.AutoMigrate(&SharedNode{}) + err = db.AutoMigrate(&SharedMachine{}) if err != nil { return err } diff --git a/machine.go b/machine.go index bbacee5..c5a8a2a 100644 --- a/machine.go +++ b/machine.go @@ -183,7 +183,7 @@ func (h *Headscale) getPeers(m Machine) (*[]*tailcfg.Node, error) { } // We fetch here machines that are shared to the `Namespace` of the machine we are getting peers for - sharedNodes := []SharedNode{} + sharedNodes := []SharedMachine{} if err := h.db.Preload("Namespace").Preload("Machine").Where("namespace_id = ?", m.NamespaceID).Find(&sharedNodes).Error; err != nil { return nil, err diff --git a/namespaces.go b/namespaces.go index 57674ff..e7d207b 100644 --- a/namespaces.go +++ b/namespaces.go @@ -103,8 +103,8 @@ func (h *Headscale) ListSharedMachinesInNamespace(name string) (*[]Machine, erro if err != nil { return nil, err } - sharedNodes := []SharedNode{} - if err := h.db.Preload("Namespace").Where(&SharedNode{NamespaceID: n.ID}).Find(&sharedNodes).Error; err != nil { + sharedNodes := []SharedMachine{} + if err := h.db.Preload("Namespace").Where(&SharedMachine{NamespaceID: n.ID}).Find(&sharedNodes).Error; err != nil { return nil, err } diff --git a/sharing.go b/sharing.go index 54d9976..db16ef3 100644 --- a/sharing.go +++ b/sharing.go @@ -5,8 +5,8 @@ import "gorm.io/gorm" const errorSameNamespace = Error("Destination namespace same as origin") const errorNodeAlreadyShared = Error("Node already shared to this namespace") -// SharedNode is a join table to support sharing nodes between namespaces -type SharedNode struct { +// SharedMachine is a join table to support sharing nodes between namespaces +type SharedMachine struct { gorm.Model MachineID uint64 Machine Machine @@ -20,12 +20,12 @@ func (h *Headscale) AddSharedMachineToNamespace(m *Machine, ns *Namespace) error return errorSameNamespace } - sn := SharedNode{} + sn := SharedMachine{} if err := h.db.Where("machine_id = ? AND namespace_id", m.ID, ns.ID).First(&sn).Error; err == nil { return errorNodeAlreadyShared } - sn = SharedNode{ + sn = SharedMachine{ MachineID: m.ID, Machine: *m, NamespaceID: ns.ID,