From 7cb1efebec36e43bcfc256f4558610c13f289b05 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 6 Dec 2023 02:21:21 +0100 Subject: [PATCH] api/types: move NetworkListConfig to api/types/backend This struct is intended for internal use only for the backend, and is not intended to be used externally. This moves the plugin-related `NetworkListConfig` types to the backend package to prevent it being imported in the client, and to make it more clear that this is part of internal APIs, and not public-facing. Signed-off-by: Sebastiaan van Stijn --- api/server/router/network/backend.go | 3 ++- api/server/router/network/network_routes.go | 7 ++++--- api/types/backend/backend.go | 7 +++++++ api/types/configs.go | 11 ----------- daemon/network.go | 3 ++- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/api/server/router/network/backend.go b/api/server/router/network/backend.go index f1d4ed1cc8..eaf44982e1 100644 --- a/api/server/router/network/backend.go +++ b/api/server/router/network/backend.go @@ -4,6 +4,7 @@ import ( "context" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" ) @@ -11,7 +12,7 @@ import ( // Backend is all the methods that need to be implemented // to provide network specific functionality. type Backend interface { - GetNetworks(filters.Args, types.NetworkListConfig) ([]types.NetworkResource, error) + GetNetworks(filters.Args, backend.NetworkListConfig) ([]types.NetworkResource, error) CreateNetwork(nc types.NetworkCreateRequest) (*types.NetworkCreateResponse, error) ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error DisconnectContainerFromNetwork(containerName string, networkName string, force bool) error diff --git a/api/server/router/network/network_routes.go b/api/server/router/network/network_routes.go index a102b48d36..0fd67eb310 100644 --- a/api/server/router/network/network_routes.go +++ b/api/server/router/network/network_routes.go @@ -8,6 +8,7 @@ import ( "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/versions" @@ -39,7 +40,7 @@ func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWrit // Combine the network list returned by Docker daemon if it is not already // returned by the cluster manager - localNetworks, err := n.backend.GetNetworks(filter, types.NetworkListConfig{Detailed: versions.LessThan(httputils.VersionFromContext(ctx), "1.28")}) + localNetworks, err := n.backend.GetNetworks(filter, backend.NetworkListConfig{Detailed: versions.LessThan(httputils.VersionFromContext(ctx), "1.28")}) if err != nil { return err } @@ -117,7 +118,7 @@ func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r if networkScope != "" { filter.Add("scope", networkScope) } - networks, _ := n.backend.GetNetworks(filter, types.NetworkListConfig{Detailed: true, Verbose: verbose}) + networks, _ := n.backend.GetNetworks(filter, backend.NetworkListConfig{Detailed: true, Verbose: verbose}) for _, nw := range networks { if nw.ID == term { return httputils.WriteJSON(w, http.StatusOK, nw) @@ -311,7 +312,7 @@ func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, e listByPartialID := map[string]types.NetworkResource{} filter := filters.NewArgs(filters.Arg("idOrName", term)) - networks, _ := n.backend.GetNetworks(filter, types.NetworkListConfig{Detailed: true}) + networks, _ := n.backend.GetNetworks(filter, backend.NetworkListConfig{Detailed: true}) for _, nw := range networks { if nw.ID == term { return nw, nil diff --git a/api/types/backend/backend.go b/api/types/backend/backend.go index 678a8c1b6e..613da5517d 100644 --- a/api/types/backend/backend.go +++ b/api/types/backend/backend.go @@ -156,3 +156,10 @@ type PluginEnableConfig struct { type PluginDisableConfig struct { ForceDisable bool } + +// NetworkListConfig stores the options available for listing networks +type NetworkListConfig struct { + // TODO(@cpuguy83): naming is hard, this is pulled from what was being used in the router before moving here + Detailed bool + Verbose bool +} diff --git a/api/types/configs.go b/api/types/configs.go index e38d32663e..945b6efadd 100644 --- a/api/types/configs.go +++ b/api/types/configs.go @@ -1,9 +1,5 @@ package types // import "github.com/docker/docker/api/types" -// configs holds structs used for internal communication between the -// frontend (such as an http server) and the backend (such as the -// docker daemon). - // ExecConfig is a small subset of the Config struct that holds the configuration // for the exec feature of docker. type ExecConfig struct { @@ -20,10 +16,3 @@ type ExecConfig struct { WorkingDir string // Working directory Cmd []string // Execution commands and args } - -// NetworkListConfig stores the options available for listing networks -type NetworkListConfig struct { - // TODO(@cpuguy83): naming is hard, this is pulled from what was being used in the router before moving here - Detailed bool - Verbose bool -} diff --git a/daemon/network.go b/daemon/network.go index 961c45ea96..d3e49e8b3b 100644 --- a/daemon/network.go +++ b/daemon/network.go @@ -12,6 +12,7 @@ import ( "github.com/containerd/log" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/backend" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" @@ -550,7 +551,7 @@ func (daemon *Daemon) deleteNetwork(nw *libnetwork.Network, dynamic bool) error } // GetNetworks returns a list of all networks -func (daemon *Daemon) GetNetworks(filter filters.Args, config types.NetworkListConfig) (networks []types.NetworkResource, err error) { +func (daemon *Daemon) GetNetworks(filter filters.Args, config backend.NetworkListConfig) (networks []types.NetworkResource, err error) { var idx map[string]*libnetwork.Network if config.Detailed { idx = make(map[string]*libnetwork.Network)