mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-28 12:35:21 +00:00
Renamed SharedNode to SharedMachine
This commit is contained in:
parent
75a342f96e
commit
2780623076
2
db.go
2
db.go
@ -44,7 +44,7 @@ func (h *Headscale) initDB() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.AutoMigrate(&SharedNode{})
|
err = db.AutoMigrate(&SharedMachine{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -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
|
// 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 = ?",
|
if err := h.db.Preload("Namespace").Preload("Machine").Where("namespace_id = ?",
|
||||||
m.NamespaceID).Find(&sharedNodes).Error; err != nil {
|
m.NamespaceID).Find(&sharedNodes).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -103,8 +103,8 @@ func (h *Headscale) ListSharedMachinesInNamespace(name string) (*[]Machine, erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sharedNodes := []SharedNode{}
|
sharedNodes := []SharedMachine{}
|
||||||
if err := h.db.Preload("Namespace").Where(&SharedNode{NamespaceID: n.ID}).Find(&sharedNodes).Error; err != nil {
|
if err := h.db.Preload("Namespace").Where(&SharedMachine{NamespaceID: n.ID}).Find(&sharedNodes).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ import "gorm.io/gorm"
|
|||||||
const errorSameNamespace = Error("Destination namespace same as origin")
|
const errorSameNamespace = Error("Destination namespace same as origin")
|
||||||
const errorNodeAlreadyShared = Error("Node already shared to this namespace")
|
const errorNodeAlreadyShared = Error("Node already shared to this namespace")
|
||||||
|
|
||||||
// SharedNode is a join table to support sharing nodes between namespaces
|
// SharedMachine is a join table to support sharing nodes between namespaces
|
||||||
type SharedNode struct {
|
type SharedMachine struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
MachineID uint64
|
MachineID uint64
|
||||||
Machine Machine
|
Machine Machine
|
||||||
@ -20,12 +20,12 @@ func (h *Headscale) AddSharedMachineToNamespace(m *Machine, ns *Namespace) error
|
|||||||
return errorSameNamespace
|
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 {
|
if err := h.db.Where("machine_id = ? AND namespace_id", m.ID, ns.ID).First(&sn).Error; err == nil {
|
||||||
return errorNodeAlreadyShared
|
return errorNodeAlreadyShared
|
||||||
}
|
}
|
||||||
|
|
||||||
sn = SharedNode{
|
sn = SharedMachine{
|
||||||
MachineID: m.ID,
|
MachineID: m.ID,
|
||||||
Machine: *m,
|
Machine: *m,
|
||||||
NamespaceID: ns.ID,
|
NamespaceID: ns.ID,
|
||||||
|
Loading…
Reference in New Issue
Block a user