Renamed SharedNode to SharedMachine

This commit is contained in:
Juan Font 2021-09-06 14:43:43 +02:00
parent 75a342f96e
commit 2780623076
4 changed files with 8 additions and 8 deletions

2
db.go
View File

@ -44,7 +44,7 @@ func (h *Headscale) initDB() error {
return err
}
err = db.AutoMigrate(&SharedNode{})
err = db.AutoMigrate(&SharedMachine{})
if err != nil {
return err
}

View File

@ -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

View File

@ -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
}

View File

@ -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,