Merge branch 'main' into main

This commit is contained in:
Kristoffer Dalby
2021-10-17 13:26:37 +01:00
committed by GitHub
3 changed files with 87 additions and 0 deletions

View File

@@ -59,6 +59,35 @@ func (h *Headscale) DestroyNamespace(name string) error {
}
if result := h.db.Unscoped().Delete(&n); result.Error != nil {
return result.Error
}
return nil
}
// RenameNamespace renames a Namespace. Returns error if the Namespace does
// not exist or if another Namespace exists with the new name.
func (h *Headscale) RenameNamespace(oldName, newName string) error {
n, err := h.GetNamespace(oldName)
if err != nil {
return err
}
_, err = h.GetNamespace(newName)
if err == nil {
return errorNamespaceExists
}
if !errors.Is(err, errorNamespaceNotFound) {
return err
}
n.Name = newName
if result := h.db.Save(&n); result.Error != nil {
return result.Error
}
err = h.RequestMapUpdates(n.ID)
if err != nil {
return err
}