From 7fc53c5953433657b87f8f35f30d1aa0142dca47 Mon Sep 17 00:00:00 2001 From: Vincent van Dam Date: Wed, 24 May 2023 11:56:25 +0200 Subject: [PATCH] Fix network disconnect when using name instead of id --- internal/model/types/container.go | 3 --- internal/server/routes/docker/networks.go | 8 ++++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/model/types/container.go b/internal/model/types/container.go index 7f599c4..f76c5f8 100644 --- a/internal/model/types/container.go +++ b/internal/model/types/container.go @@ -418,9 +418,6 @@ func (co *Container) ConnectNetwork(id string) { // DisconnectNetwork will detach a network from the container. func (co *Container) DisconnectNetwork(id string) error { - if id == "bridge" { - return fmt.Errorf("can't delete bridge network") - } if _, ok := co.Networks[id]; !ok { return fmt.Errorf("container is not connected to network %s", id) } diff --git a/internal/server/routes/docker/networks.go b/internal/server/routes/docker/networks.go index 7548605..e1f897d 100644 --- a/internal/server/routes/docker/networks.go +++ b/internal/server/routes/docker/networks.go @@ -164,7 +164,7 @@ func NetworksDisconnect(cr *common.ContextRouter, c *gin.Context) { return } id := c.Param("id") - _, err := cr.DB.GetNetworkByNameOrID(id) + netw, err := cr.DB.GetNetworkByNameOrID(id) if err != nil { httputil.Error(c, http.StatusNotFound, err) return @@ -174,7 +174,11 @@ func NetworksDisconnect(cr *common.ContextRouter, c *gin.Context) { httputil.Error(c, http.StatusNotFound, err) return } - if err := tainr.DisconnectNetwork(id); err != nil { + if netw.IsPredefined() { + httputil.Error(c, http.StatusInternalServerError, fmt.Errorf("can not disconnect from predefined network")) + return + } + if err := tainr.DisconnectNetwork(netw.ID); err != nil { httputil.Error(c, http.StatusNotFound, err) return }