Remove RequestMapUpdates function

This commit is contained in:
Kristoffer Dalby 2022-02-12 21:04:00 +00:00
parent 6fa0903a8e
commit bb80b679bc
4 changed files with 5 additions and 75 deletions

View file

@ -1,9 +1,7 @@
package headscale
import (
"encoding/json"
"errors"
"fmt"
"strconv"
"time"
@ -104,11 +102,6 @@ func (h *Headscale) RenameNamespace(oldName, newName string) error {
return result.Error
}
err = h.RequestMapUpdates(oldNamespace.ID)
if err != nil {
return err
}
return nil
}
@ -187,54 +180,6 @@ func (h *Headscale) SetMachineNamespace(machine *Machine, namespaceName string)
return nil
}
// TODO(kradalby): Remove the need for this.
// RequestMapUpdates signals the KV worker to update the maps for this namespace.
func (h *Headscale) RequestMapUpdates(namespaceID uint) error {
namespace := Namespace{}
if err := h.db.First(&namespace, namespaceID).Error; err != nil {
return err
}
namespacesPendingUpdates, err := h.getValue("namespaces_pending_updates")
if err != nil || namespacesPendingUpdates == "" {
err = h.setValue(
"namespaces_pending_updates",
fmt.Sprintf(`["%s"]`, namespace.Name),
)
if err != nil {
return err
}
return nil
}
names := []string{}
err = json.Unmarshal([]byte(namespacesPendingUpdates), &names)
if err != nil {
err = h.setValue(
"namespaces_pending_updates",
fmt.Sprintf(`["%s"]`, namespace.Name),
)
if err != nil {
return err
}
return nil
}
names = append(names, namespace.Name)
data, err := json.Marshal(names)
if err != nil {
log.Error().
Str("func", "RequestMapUpdates").
Err(err).
Msg("Could not marshal namespaces_pending_updates")
return err
}
return h.setValue("namespaces_pending_updates", string(data))
}
func (n *Namespace) toUser() *tailcfg.User {
user := tailcfg.User{
ID: tailcfg.UserID(n.ID),