mirror of
https://github.com/juanfont/headscale.git
synced 2026-03-31 14:33:42 +02:00
TS2021: Expose Register handler in Noise
This commit is contained in:
17
machine.go
17
machine.go
@@ -335,7 +335,7 @@ func (h *Headscale) GetMachineByID(id uint64) (*Machine, error) {
|
||||
return &m, nil
|
||||
}
|
||||
|
||||
// GetMachineByMachineKey finds a Machine by ID and returns the Machine struct.
|
||||
// GetMachineByMachineKey finds a Machine by its MachineKey and returns the Machine struct.
|
||||
func (h *Headscale) GetMachineByMachineKey(
|
||||
machineKey key.MachinePublic,
|
||||
) (*Machine, error) {
|
||||
@@ -347,6 +347,19 @@ func (h *Headscale) GetMachineByMachineKey(
|
||||
return &m, nil
|
||||
}
|
||||
|
||||
// GetMachineByNodeKeys finds a Machine by its current NodeKey or the old one, and returns the Machine struct.
|
||||
func (h *Headscale) GetMachineByNodeKeys(
|
||||
nodeKey key.NodePublic, oldNodeKey key.NodePublic,
|
||||
) (*Machine, error) {
|
||||
m := Machine{}
|
||||
if result := h.db.Preload("Namespace").First(&m, "node_key = ? OR node_key = ?",
|
||||
NodePublicKeyStripPrefix(nodeKey), NodePublicKeyStripPrefix(oldNodeKey)); result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
|
||||
return &m, nil
|
||||
}
|
||||
|
||||
// UpdateMachine takes a Machine struct pointer (typically already loaded from database
|
||||
// and updates it with the latest data from the database.
|
||||
func (h *Headscale) UpdateMachine(machine *Machine) error {
|
||||
@@ -677,7 +690,7 @@ func (h *Headscale) RegisterMachine(machine Machine,
|
||||
) (*Machine, error) {
|
||||
log.Trace().
|
||||
Caller().
|
||||
Str("machine_key", machine.MachineKey).
|
||||
Str("node_key", machine.NodeKey).
|
||||
Msg("Registering machine")
|
||||
|
||||
log.Trace().
|
||||
|
||||
Reference in New Issue
Block a user