Skip to content

Commit

Permalink
Fix network disconnect when using name instead of id
Browse files Browse the repository at this point in the history
  • Loading branch information
joyrex2001 committed May 24, 2023
1 parent 058b2ab commit 7fc53c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 0 additions & 3 deletions internal/model/types/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions internal/server/routes/docker/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 7fc53c5

Please sign in to comment.