feat: add forcedTags field and update proto

This commit is contained in:
Adrien Raffin-Caboisse 2022-04-15 13:11:41 +02:00
parent bc63c577a9
commit 02f68ebac8
No known key found for this signature in database
GPG key ID: 7FB60532DEBEAD6A
9 changed files with 688 additions and 253 deletions

View file

@ -45,6 +45,8 @@ type Machine struct {
RegisterMethod string
ForcedTags StringList
// TODO(kradalby): This seems like irrelevant information?
AuthKeyID uint
AuthKey *PreAuthKey
@ -357,6 +359,22 @@ func (h *Headscale) UpdateMachine(machine *Machine) error {
return nil
}
// UpdateDBMachine takes a Machine struct pointer (typically already loaded from database
// search for the same machine in the database and update the latter
func (h *Headscale) UpdateDBMachine(machine Machine) error {
destMachine := Machine{}
if result := h.db.Where("id = ?", machine.ID).Find(&destMachine); result.Error != nil {
return result.Error
}
destMachine.Name = machine.Name
destMachine.NamespaceID = machine.NamespaceID
destMachine.ForcedTags = machine.ForcedTags
h.db.Save(destMachine)
return nil
}
// ExpireMachine takes a Machine struct and sets the expire field to now.
func (h *Headscale) ExpireMachine(machine *Machine) {
now := time.Now()
@ -613,6 +631,7 @@ func (machine *Machine) toProto() *v1.Machine {
IpAddresses: machine.IPAddresses.ToStringSlice(),
Name: machine.Name,
Namespace: machine.Namespace.toProto(),
ForcedTags: machine.ForcedTags,
// TODO(kradalby): Implement register method enum converter
// RegisterMethod: ,