From a4efe66cf2a7648dbcf5b9993bf351925b905b5b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 26 Sep 2017 13:59:45 +0200 Subject: [PATCH] Replace uses of filters.ToParam(), FromParam() with filters.ToJSON(), FromJSON() `filters.ToParam()` and `filters.FromParam()` were deprecated in favor of `filters.ToJSON()` and `filters.FromJSON()` in 065118390a3ecaf0dbd2fa752d54d43f8f1e8ec6, but still used in various locations. This patch replaces uses of `filters.ToParam()` and `filters.FromParam()` with `filters.ToJSON()` and `filters.FromJSON()`. Signed-off-by: Sebastiaan van Stijn --- api/server/router/container/container_routes.go | 4 ++-- api/server/router/image/image_routes.go | 4 ++-- api/server/router/network/network_routes.go | 4 ++-- api/server/router/plugin/plugin_routes.go | 2 +- api/server/router/swarm/cluster_routes.go | 10 +++++----- api/server/router/system/system_routes.go | 2 +- api/server/router/volume/volume_routes.go | 2 +- api/types/filters/parse_test.go | 14 +++++++------- client/config_list.go | 2 +- client/image_search.go | 2 +- client/node_list.go | 2 +- client/secret_list.go | 2 +- client/service_list.go | 2 +- client/task_list.go | 2 +- client/utils.go | 2 +- daemon/cluster/tasks.go | 6 +++--- daemon/list.go | 2 +- daemon/search.go | 2 +- integration-cli/docker_api_network_test.go | 2 +- 19 files changed, 34 insertions(+), 34 deletions(-) diff --git a/api/server/router/container/container_routes.go b/api/server/router/container/container_routes.go index 30fd3a15bf..95bbe0e533 100644 --- a/api/server/router/container/container_routes.go +++ b/api/server/router/container/container_routes.go @@ -28,7 +28,7 @@ func (s *containerRouter) getContainersJSON(ctx context.Context, w http.Response if err := httputils.ParseForm(r); err != nil { return err } - filter, err := filters.FromParam(r.Form.Get("filters")) + filter, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } @@ -588,7 +588,7 @@ func (s *containerRouter) postContainersPrune(ctx context.Context, w http.Respon return err } - pruneFilters, err := filters.FromParam(r.Form.Get("filters")) + pruneFilters, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return validationError{err} } diff --git a/api/server/router/image/image_routes.go b/api/server/router/image/image_routes.go index 86d73df0e1..7214f4eb7e 100644 --- a/api/server/router/image/image_routes.go +++ b/api/server/router/image/image_routes.go @@ -302,7 +302,7 @@ func (s *imageRouter) getImagesJSON(ctx context.Context, w http.ResponseWriter, return err } - imageFilters, err := filters.FromParam(r.Form.Get("filters")) + imageFilters, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } @@ -385,7 +385,7 @@ func (s *imageRouter) postImagesPrune(ctx context.Context, w http.ResponseWriter return err } - pruneFilters, err := filters.FromParam(r.Form.Get("filters")) + pruneFilters, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } diff --git a/api/server/router/network/network_routes.go b/api/server/router/network/network_routes.go index ad3e74e6eb..ebf4bf635e 100644 --- a/api/server/router/network/network_routes.go +++ b/api/server/router/network/network_routes.go @@ -37,7 +37,7 @@ func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWrit } filter := r.Form.Get("filters") - netFilters, err := filters.FromParam(filter) + netFilters, err := filters.FromJSON(filter) if err != nil { return err } @@ -489,7 +489,7 @@ func (n *networkRouter) postNetworksPrune(ctx context.Context, w http.ResponseWr return err } - pruneFilters, err := filters.FromParam(r.Form.Get("filters")) + pruneFilters, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } diff --git a/api/server/router/plugin/plugin_routes.go b/api/server/router/plugin/plugin_routes.go index 79e3cf5de8..d74a01f300 100644 --- a/api/server/router/plugin/plugin_routes.go +++ b/api/server/router/plugin/plugin_routes.go @@ -290,7 +290,7 @@ func (pr *pluginRouter) listPlugins(ctx context.Context, w http.ResponseWriter, return err } - pluginFilters, err := filters.FromParam(r.Form.Get("filters")) + pluginFilters, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } diff --git a/api/server/router/swarm/cluster_routes.go b/api/server/router/swarm/cluster_routes.go index 55743a6218..5b6c19d9c1 100644 --- a/api/server/router/swarm/cluster_routes.go +++ b/api/server/router/swarm/cluster_routes.go @@ -151,7 +151,7 @@ func (sr *swarmRouter) getServices(ctx context.Context, w http.ResponseWriter, r if err := httputils.ParseForm(r); err != nil { return err } - filter, err := filters.FromParam(r.Form.Get("filters")) + filter, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return invalidRequestError{err} } @@ -277,7 +277,7 @@ func (sr *swarmRouter) getNodes(ctx context.Context, w http.ResponseWriter, r *h if err := httputils.ParseForm(r); err != nil { return err } - filter, err := filters.FromParam(r.Form.Get("filters")) + filter, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } @@ -339,7 +339,7 @@ func (sr *swarmRouter) getTasks(ctx context.Context, w http.ResponseWriter, r *h if err := httputils.ParseForm(r); err != nil { return err } - filter, err := filters.FromParam(r.Form.Get("filters")) + filter, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } @@ -367,7 +367,7 @@ func (sr *swarmRouter) getSecrets(ctx context.Context, w http.ResponseWriter, r if err := httputils.ParseForm(r); err != nil { return err } - filters, err := filters.FromParam(r.Form.Get("filters")) + filters, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } @@ -434,7 +434,7 @@ func (sr *swarmRouter) getConfigs(ctx context.Context, w http.ResponseWriter, r if err := httputils.ParseForm(r); err != nil { return err } - filters, err := filters.FromParam(r.Form.Get("filters")) + filters, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } diff --git a/api/server/router/system/system_routes.go b/api/server/router/system/system_routes.go index 5884388ebe..62060a4ccf 100644 --- a/api/server/router/system/system_routes.go +++ b/api/server/router/system/system_routes.go @@ -127,7 +127,7 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r * } } - ef, err := filters.FromParam(r.Form.Get("filters")) + ef, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } diff --git a/api/server/router/volume/volume_routes.go b/api/server/router/volume/volume_routes.go index f0f490119b..bfff51ab1e 100644 --- a/api/server/router/volume/volume_routes.go +++ b/api/server/router/volume/volume_routes.go @@ -72,7 +72,7 @@ func (v *volumeRouter) postVolumesPrune(ctx context.Context, w http.ResponseWrit return err } - pruneFilters, err := filters.FromParam(r.Form.Get("filters")) + pruneFilters, err := filters.FromJSON(r.Form.Get("filters")) if err != nil { return err } diff --git a/api/types/filters/parse_test.go b/api/types/filters/parse_test.go index a0a4f2a8d5..67b2ec930c 100644 --- a/api/types/filters/parse_test.go +++ b/api/types/filters/parse_test.go @@ -42,14 +42,14 @@ func TestParseArgsEdgeCase(t *testing.T) { } } -func TestToParam(t *testing.T) { +func TestToJSON(t *testing.T) { fields := map[string]map[string]bool{ "created": {"today": true}, "image.name": {"ubuntu*": true, "*untu": true}, } a := Args{fields: fields} - _, err := ToParam(a) + _, err := ToJSON(a) if err != nil { t.Errorf("failed to marshal the filters: %s", err) } @@ -80,7 +80,7 @@ func TestToParamWithVersion(t *testing.T) { } } -func TestFromParam(t *testing.T) { +func TestFromJSON(t *testing.T) { invalids := []string{ "anything", "['a','list']", @@ -103,14 +103,14 @@ func TestFromParam(t *testing.T) { } for _, invalid := range invalids { - if _, err := FromParam(invalid); err == nil { + if _, err := FromJSON(invalid); err == nil { t.Fatalf("Expected an error with %v, got nothing", invalid) } } for expectedArgs, matchers := range valid { for _, json := range matchers { - args, err := FromParam(json) + args, err := FromJSON(json) if err != nil { t.Fatal(err) } @@ -136,11 +136,11 @@ func TestFromParam(t *testing.T) { func TestEmpty(t *testing.T) { a := Args{} - v, err := ToParam(a) + v, err := ToJSON(a) if err != nil { t.Errorf("failed to marshal the filters: %s", err) } - v1, err := FromParam(v) + v1, err := FromJSON(v) if err != nil { t.Errorf("%s", err) } diff --git a/client/config_list.go b/client/config_list.go index 8483ca14d1..57febc9ffb 100644 --- a/client/config_list.go +++ b/client/config_list.go @@ -18,7 +18,7 @@ func (cli *Client) ConfigList(ctx context.Context, options types.ConfigListOptio query := url.Values{} if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) + filterJSON, err := filters.ToJSON(options.Filters) if err != nil { return nil, err } diff --git a/client/image_search.go b/client/image_search.go index b0fcd5c23d..5566e92555 100644 --- a/client/image_search.go +++ b/client/image_search.go @@ -21,7 +21,7 @@ func (cli *Client) ImageSearch(ctx context.Context, term string, options types.I query.Set("limit", fmt.Sprintf("%d", options.Limit)) if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) + filterJSON, err := filters.ToJSON(options.Filters) if err != nil { return results, err } diff --git a/client/node_list.go b/client/node_list.go index 3e8440f08e..fed22992c9 100644 --- a/client/node_list.go +++ b/client/node_list.go @@ -15,7 +15,7 @@ func (cli *Client) NodeList(ctx context.Context, options types.NodeListOptions) query := url.Values{} if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) + filterJSON, err := filters.ToJSON(options.Filters) if err != nil { return nil, err diff --git a/client/secret_list.go b/client/secret_list.go index 0d33ecfbc9..fdee6e2e0b 100644 --- a/client/secret_list.go +++ b/client/secret_list.go @@ -18,7 +18,7 @@ func (cli *Client) SecretList(ctx context.Context, options types.SecretListOptio query := url.Values{} if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) + filterJSON, err := filters.ToJSON(options.Filters) if err != nil { return nil, err } diff --git a/client/service_list.go b/client/service_list.go index c29e6d407d..eb3ff9739c 100644 --- a/client/service_list.go +++ b/client/service_list.go @@ -15,7 +15,7 @@ func (cli *Client) ServiceList(ctx context.Context, options types.ServiceListOpt query := url.Values{} if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) + filterJSON, err := filters.ToJSON(options.Filters) if err != nil { return nil, err } diff --git a/client/task_list.go b/client/task_list.go index 66324da959..01bd695257 100644 --- a/client/task_list.go +++ b/client/task_list.go @@ -15,7 +15,7 @@ func (cli *Client) TaskList(ctx context.Context, options types.TaskListOptions) query := url.Values{} if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) + filterJSON, err := filters.ToJSON(options.Filters) if err != nil { return nil, err } diff --git a/client/utils.go b/client/utils.go index f3d8877df7..137705065c 100644 --- a/client/utils.go +++ b/client/utils.go @@ -24,7 +24,7 @@ func getDockerOS(serverHeader string) string { func getFiltersQuery(f filters.Args) (url.Values, error) { query := url.Values{} if f.Len() > 0 { - filterJSON, err := filters.ToParam(f) + filterJSON, err := filters.ToJSON(f) if err != nil { return query, err } diff --git a/daemon/cluster/tasks.go b/daemon/cluster/tasks.go index 26706a2fa5..f52301fe47 100644 --- a/daemon/cluster/tasks.go +++ b/daemon/cluster/tasks.go @@ -15,7 +15,7 @@ func (c *Cluster) GetTasks(options apitypes.TaskListOptions) ([]types.Task, erro if err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error { filterTransform := func(filter filters.Args) error { - if filter.Include("service") { + if filter.Contains("service") { serviceFilters := filter.Get("service") for _, serviceFilter := range serviceFilters { service, err := getService(ctx, state.controlClient, serviceFilter, false) @@ -26,7 +26,7 @@ func (c *Cluster) GetTasks(options apitypes.TaskListOptions) ([]types.Task, erro filter.Add("service", service.ID) } } - if filter.Include("node") { + if filter.Contains("node") { nodeFilters := filter.Get("node") for _, nodeFilter := range nodeFilters { node, err := getNode(ctx, state.controlClient, nodeFilter) @@ -37,7 +37,7 @@ func (c *Cluster) GetTasks(options apitypes.TaskListOptions) ([]types.Task, erro filter.Add("node", node.ID) } } - if !filter.Include("runtime") { + if !filter.Contains("runtime") { // default to only showing container tasks filter.Add("runtime", "container") filter.Add("runtime", "") diff --git a/daemon/list.go b/daemon/list.go index 417f7b253d..9d43be2720 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -585,7 +585,7 @@ func (daemon *Daemon) Volumes(filter string) ([]*types.Volume, []string, error) var ( volumesOut []*types.Volume ) - volFilters, err := filters.FromParam(filter) + volFilters, err := filters.FromJSON(filter) if err != nil { return nil, nil, err } diff --git a/daemon/search.go b/daemon/search.go index 45484f3a10..25744cb723 100644 --- a/daemon/search.go +++ b/daemon/search.go @@ -23,7 +23,7 @@ func (daemon *Daemon) SearchRegistryForImages(ctx context.Context, filtersArgs s authConfig *types.AuthConfig, headers map[string][]string) (*registrytypes.SearchResults, error) { - searchFilters, err := filters.FromParam(filtersArgs) + searchFilters, err := filters.FromJSON(filtersArgs) if err != nil { return nil, err } diff --git a/integration-cli/docker_api_network_test.go b/integration-cli/docker_api_network_test.go index a49fbae3d4..108dd4c6ac 100644 --- a/integration-cli/docker_api_network_test.go +++ b/integration-cli/docker_api_network_test.go @@ -282,7 +282,7 @@ func getNetworkIDByName(c *check.C, name string) string { filterArgs = filters.NewArgs() ) filterArgs.Add("name", name) - filterJSON, err := filters.ToParam(filterArgs) + filterJSON, err := filters.ToJSON(filterArgs) c.Assert(err, checker.IsNil) v.Set("filters", filterJSON)