Browse Source

Replace uses of filters.Include() with filters.Contains()

The `filters.Include()` method was deprecated in favor of `filters.Contains()`
in 065118390a3ecaf0dbd2fa752d54d43f8f1e8ec6, but still used in various
locations.

This patch replaces uses of `filters.Include()` with `filters.Contains()`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 7 years ago
parent
commit
97c5ae25c4

+ 6 - 6
api/server/router/network/filter.go

@@ -45,27 +45,27 @@ func filterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.N
 
 
 	displayNet := []types.NetworkResource{}
 	displayNet := []types.NetworkResource{}
 	for _, nw := range nws {
 	for _, nw := range nws {
-		if filter.Include("driver") {
+		if filter.Contains("driver") {
 			if !filter.ExactMatch("driver", nw.Driver) {
 			if !filter.ExactMatch("driver", nw.Driver) {
 				continue
 				continue
 			}
 			}
 		}
 		}
-		if filter.Include("name") {
+		if filter.Contains("name") {
 			if !filter.Match("name", nw.Name) {
 			if !filter.Match("name", nw.Name) {
 				continue
 				continue
 			}
 			}
 		}
 		}
-		if filter.Include("id") {
+		if filter.Contains("id") {
 			if !filter.Match("id", nw.ID) {
 			if !filter.Match("id", nw.ID) {
 				continue
 				continue
 			}
 			}
 		}
 		}
-		if filter.Include("label") {
+		if filter.Contains("label") {
 			if !filter.MatchKVList("label", nw.Labels) {
 			if !filter.MatchKVList("label", nw.Labels) {
 				continue
 				continue
 			}
 			}
 		}
 		}
-		if filter.Include("scope") {
+		if filter.Contains("scope") {
 			if !filter.ExactMatch("scope", nw.Scope) {
 			if !filter.ExactMatch("scope", nw.Scope) {
 				continue
 				continue
 			}
 			}
@@ -73,7 +73,7 @@ func filterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.N
 		displayNet = append(displayNet, nw)
 		displayNet = append(displayNet, nw)
 	}
 	}
 
 
-	if filter.Include("type") {
+	if filter.Contains("type") {
 		typeNet := []types.NetworkResource{}
 		typeNet := []types.NetworkResource{}
 		errFilter := filter.WalkValues("type", func(fval string) error {
 		errFilter := filter.WalkValues("type", func(fval string) error {
 			passList, err := filterNetworkByType(displayNet, fval)
 			passList, err := filterNetworkByType(displayNet, fval)

+ 11 - 0
api/types/filters/parse_test.go

@@ -337,6 +337,17 @@ func TestOnlyOneExactMatch(t *testing.T) {
 	}
 	}
 }
 }
 
 
+func TestContains(t *testing.T) {
+	f := NewArgs()
+	if f.Contains("status") {
+		t.Fatal("Expected to not contain a status key, got true")
+	}
+	f.Add("status", "running")
+	if !f.Contains("status") {
+		t.Fatal("Expected to contain a status key, got false")
+	}
+}
+
 func TestInclude(t *testing.T) {
 func TestInclude(t *testing.T) {
 	f := NewArgs()
 	f := NewArgs()
 	if f.Include("status") {
 	if f.Include("status") {

+ 1 - 1
daemon/cluster/services.go

@@ -74,7 +74,7 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
 	services := make([]types.Service, 0, len(r.Services))
 	services := make([]types.Service, 0, len(r.Services))
 
 
 	for _, service := range r.Services {
 	for _, service := range r.Services {
-		if options.Filters.Include("mode") {
+		if options.Filters.Contains("mode") {
 			var mode string
 			var mode string
 			switch service.Spec.GetMode().(type) {
 			switch service.Spec.GetMode().(type) {
 			case *swarmapi.ServiceSpec_Global:
 			case *swarmapi.ServiceSpec_Global:

+ 2 - 2
daemon/events/filter.go

@@ -49,14 +49,14 @@ func (ef *Filter) filterContains(field string, values map[string]struct{}) bool
 }
 }
 
 
 func (ef *Filter) matchScope(scope string) bool {
 func (ef *Filter) matchScope(scope string) bool {
-	if !ef.filter.Include("scope") {
+	if !ef.filter.Contains("scope") {
 		return true
 		return true
 	}
 	}
 	return ef.filter.ExactMatch("scope", scope)
 	return ef.filter.ExactMatch("scope", scope)
 }
 }
 
 
 func (ef *Filter) matchLabels(attributes map[string]string) bool {
 func (ef *Filter) matchLabels(attributes map[string]string) bool {
-	if !ef.filter.Include("label") {
+	if !ef.filter.Contains("label") {
 		return true
 		return true
 	}
 	}
 	return ef.filter.MatchKVList("label", attributes)
 	return ef.filter.MatchKVList("label", attributes)

+ 5 - 5
daemon/images.go

@@ -67,7 +67,7 @@ func (daemon *Daemon) Images(imageFilters filters.Args, all bool, withExtraAttrs
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	if imageFilters.Include("dangling") {
+	if imageFilters.Contains("dangling") {
 		if imageFilters.ExactMatch("dangling", "true") {
 		if imageFilters.ExactMatch("dangling", "true") {
 			danglingOnly = true
 			danglingOnly = true
 		} else if !imageFilters.ExactMatch("dangling", "false") {
 		} else if !imageFilters.ExactMatch("dangling", "false") {
@@ -116,7 +116,7 @@ func (daemon *Daemon) Images(imageFilters filters.Args, all bool, withExtraAttrs
 			}
 			}
 		}
 		}
 
 
-		if imageFilters.Include("label") {
+		if imageFilters.Contains("label") {
 			// Very old image that do not have image.Config (or even labels)
 			// Very old image that do not have image.Config (or even labels)
 			if img.Config == nil {
 			if img.Config == nil {
 				continue
 				continue
@@ -150,7 +150,7 @@ func (daemon *Daemon) Images(imageFilters filters.Args, all bool, withExtraAttrs
 		newImage := newImage(img, size)
 		newImage := newImage(img, size)
 
 
 		for _, ref := range daemon.referenceStore.References(id.Digest()) {
 		for _, ref := range daemon.referenceStore.References(id.Digest()) {
-			if imageFilters.Include("reference") {
+			if imageFilters.Contains("reference") {
 				var found bool
 				var found bool
 				var matchErr error
 				var matchErr error
 				for _, pattern := range imageFilters.Get("reference") {
 				for _, pattern := range imageFilters.Get("reference") {
@@ -173,11 +173,11 @@ func (daemon *Daemon) Images(imageFilters filters.Args, all bool, withExtraAttrs
 		if newImage.RepoDigests == nil && newImage.RepoTags == nil {
 		if newImage.RepoDigests == nil && newImage.RepoTags == nil {
 			if all || len(daemon.stores[platform].imageStore.Children(id)) == 0 {
 			if all || len(daemon.stores[platform].imageStore.Children(id)) == 0 {
 
 
-				if imageFilters.Include("dangling") && !danglingOnly {
+				if imageFilters.Contains("dangling") && !danglingOnly {
 					//dangling=false case, so dangling image is not needed
 					//dangling=false case, so dangling image is not needed
 					continue
 					continue
 				}
 				}
-				if imageFilters.Include("reference") { // skip images with no references if filtering by reference
+				if imageFilters.Contains("reference") { // skip images with no references if filtering by reference
 					continue
 					continue
 				}
 				}
 				newImage.RepoDigests = []string{"<none>@<none>"}
 				newImage.RepoDigests = []string{"<none>@<none>"}

+ 8 - 8
daemon/list.go

@@ -276,7 +276,7 @@ func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerLis
 	}
 	}
 
 
 	var taskFilter, isTask bool
 	var taskFilter, isTask bool
-	if psFilters.Include("is-task") {
+	if psFilters.Contains("is-task") {
 		if psFilters.ExactMatch("is-task", "true") {
 		if psFilters.ExactMatch("is-task", "true") {
 			taskFilter = true
 			taskFilter = true
 			isTask = true
 			isTask = true
@@ -319,7 +319,7 @@ func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerLis
 
 
 	imagesFilter := map[image.ID]bool{}
 	imagesFilter := map[image.ID]bool{}
 	var ancestorFilter bool
 	var ancestorFilter bool
-	if psFilters.Include("ancestor") {
+	if psFilters.Contains("ancestor") {
 		ancestorFilter = true
 		ancestorFilter = true
 		psFilters.WalkValues("ancestor", func(ancestor string) error {
 		psFilters.WalkValues("ancestor", func(ancestor string) error {
 			id, platform, err := daemon.GetImageIDAndPlatform(ancestor)
 			id, platform, err := daemon.GetImageIDAndPlatform(ancestor)
@@ -465,7 +465,7 @@ func includeContainerInList(container *container.Snapshot, ctx *listContext) ite
 		return excludeContainer
 		return excludeContainer
 	}
 	}
 
 
-	if ctx.filters.Include("volume") {
+	if ctx.filters.Contains("volume") {
 		volumesByName := make(map[string]types.MountPoint)
 		volumesByName := make(map[string]types.MountPoint)
 		for _, m := range container.Mounts {
 		for _, m := range container.Mounts {
 			if m.Name != "" {
 			if m.Name != "" {
@@ -509,7 +509,7 @@ func includeContainerInList(container *container.Snapshot, ctx *listContext) ite
 		networkExist = errors.New("container part of network")
 		networkExist = errors.New("container part of network")
 		noNetworks   = errors.New("container is not part of any networks")
 		noNetworks   = errors.New("container is not part of any networks")
 	)
 	)
-	if ctx.filters.Include("network") {
+	if ctx.filters.Contains("network") {
 		err := ctx.filters.WalkValues("network", func(value string) error {
 		err := ctx.filters.WalkValues("network", func(value string) error {
 			if container.NetworkSettings == nil {
 			if container.NetworkSettings == nil {
 				return noNetworks
 				return noNetworks
@@ -627,17 +627,17 @@ func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) (
 
 
 	var retVols []volume.Volume
 	var retVols []volume.Volume
 	for _, vol := range vols {
 	for _, vol := range vols {
-		if filter.Include("name") {
+		if filter.Contains("name") {
 			if !filter.Match("name", vol.Name()) {
 			if !filter.Match("name", vol.Name()) {
 				continue
 				continue
 			}
 			}
 		}
 		}
-		if filter.Include("driver") {
+		if filter.Contains("driver") {
 			if !filter.ExactMatch("driver", vol.DriverName()) {
 			if !filter.ExactMatch("driver", vol.DriverName()) {
 				continue
 				continue
 			}
 			}
 		}
 		}
-		if filter.Include("label") {
+		if filter.Contains("label") {
 			v, ok := vol.(volume.DetailedVolume)
 			v, ok := vol.(volume.DetailedVolume)
 			if !ok {
 			if !ok {
 				continue
 				continue
@@ -649,7 +649,7 @@ func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) (
 		retVols = append(retVols, vol)
 		retVols = append(retVols, vol)
 	}
 	}
 	danglingOnly := false
 	danglingOnly := false
-	if filter.Include("dangling") {
+	if filter.Contains("dangling") {
 		if filter.ExactMatch("dangling", "true") || filter.ExactMatch("dangling", "1") {
 		if filter.ExactMatch("dangling", "true") || filter.ExactMatch("dangling", "1") {
 			danglingOnly = true
 			danglingOnly = true
 		} else if !filter.ExactMatch("dangling", "false") && !filter.ExactMatch("dangling", "0") {
 		} else if !filter.ExactMatch("dangling", "false") && !filter.ExactMatch("dangling", "0") {

+ 4 - 4
daemon/prune.go

@@ -182,7 +182,7 @@ func (daemon *Daemon) ImagesPrune(ctx context.Context, pruneFilters filters.Args
 	rep := &types.ImagesPruneReport{}
 	rep := &types.ImagesPruneReport{}
 
 
 	danglingOnly := true
 	danglingOnly := true
-	if pruneFilters.Include("dangling") {
+	if pruneFilters.Contains("dangling") {
 		if pruneFilters.ExactMatch("dangling", "false") || pruneFilters.ExactMatch("dangling", "0") {
 		if pruneFilters.ExactMatch("dangling", "false") || pruneFilters.ExactMatch("dangling", "0") {
 			danglingOnly = false
 			danglingOnly = false
 		} else if !pruneFilters.ExactMatch("dangling", "true") && !pruneFilters.ExactMatch("dangling", "1") {
 		} else if !pruneFilters.ExactMatch("dangling", "true") && !pruneFilters.ExactMatch("dangling", "1") {
@@ -440,7 +440,7 @@ func (daemon *Daemon) NetworksPrune(ctx context.Context, pruneFilters filters.Ar
 
 
 func getUntilFromPruneFilters(pruneFilters filters.Args) (time.Time, error) {
 func getUntilFromPruneFilters(pruneFilters filters.Args) (time.Time, error) {
 	until := time.Time{}
 	until := time.Time{}
-	if !pruneFilters.Include("until") {
+	if !pruneFilters.Contains("until") {
 		return until, nil
 		return until, nil
 	}
 	}
 	untilFilters := pruneFilters.Get("until")
 	untilFilters := pruneFilters.Get("until")
@@ -464,8 +464,8 @@ func matchLabels(pruneFilters filters.Args, labels map[string]string) bool {
 		return false
 		return false
 	}
 	}
 	// By default MatchKVList will return true if field (like 'label!') does not exist
 	// By default MatchKVList will return true if field (like 'label!') does not exist
-	// So we have to add additional Include("label!") check
-	if pruneFilters.Include("label!") {
+	// So we have to add additional Contains("label!") check
+	if pruneFilters.Contains("label!") {
 		if pruneFilters.MatchKVList("label!", labels) {
 		if pruneFilters.MatchKVList("label!", labels) {
 			return false
 			return false
 		}
 		}

+ 6 - 6
daemon/search.go

@@ -33,21 +33,21 @@ func (daemon *Daemon) SearchRegistryForImages(ctx context.Context, filtersArgs s
 
 
 	var isAutomated, isOfficial bool
 	var isAutomated, isOfficial bool
 	var hasStarFilter = 0
 	var hasStarFilter = 0
-	if searchFilters.Include("is-automated") {
+	if searchFilters.Contains("is-automated") {
 		if searchFilters.UniqueExactMatch("is-automated", "true") {
 		if searchFilters.UniqueExactMatch("is-automated", "true") {
 			isAutomated = true
 			isAutomated = true
 		} else if !searchFilters.UniqueExactMatch("is-automated", "false") {
 		} else if !searchFilters.UniqueExactMatch("is-automated", "false") {
 			return nil, invalidFilter{"is-automated", searchFilters.Get("is-automated")}
 			return nil, invalidFilter{"is-automated", searchFilters.Get("is-automated")}
 		}
 		}
 	}
 	}
-	if searchFilters.Include("is-official") {
+	if searchFilters.Contains("is-official") {
 		if searchFilters.UniqueExactMatch("is-official", "true") {
 		if searchFilters.UniqueExactMatch("is-official", "true") {
 			isOfficial = true
 			isOfficial = true
 		} else if !searchFilters.UniqueExactMatch("is-official", "false") {
 		} else if !searchFilters.UniqueExactMatch("is-official", "false") {
 			return nil, invalidFilter{"is-official", searchFilters.Get("is-official")}
 			return nil, invalidFilter{"is-official", searchFilters.Get("is-official")}
 		}
 		}
 	}
 	}
-	if searchFilters.Include("stars") {
+	if searchFilters.Contains("stars") {
 		hasStars := searchFilters.Get("stars")
 		hasStars := searchFilters.Get("stars")
 		for _, hasStar := range hasStars {
 		for _, hasStar := range hasStars {
 			iHasStar, err := strconv.Atoi(hasStar)
 			iHasStar, err := strconv.Atoi(hasStar)
@@ -67,17 +67,17 @@ func (daemon *Daemon) SearchRegistryForImages(ctx context.Context, filtersArgs s
 
 
 	filteredResults := []registrytypes.SearchResult{}
 	filteredResults := []registrytypes.SearchResult{}
 	for _, result := range unfilteredResult.Results {
 	for _, result := range unfilteredResult.Results {
-		if searchFilters.Include("is-automated") {
+		if searchFilters.Contains("is-automated") {
 			if isAutomated != result.IsAutomated {
 			if isAutomated != result.IsAutomated {
 				continue
 				continue
 			}
 			}
 		}
 		}
-		if searchFilters.Include("is-official") {
+		if searchFilters.Contains("is-official") {
 			if isOfficial != result.IsOfficial {
 			if isOfficial != result.IsOfficial {
 				continue
 				continue
 			}
 			}
 		}
 		}
-		if searchFilters.Include("stars") {
+		if searchFilters.Contains("stars") {
 			if result.StarCount < hasStarFilter {
 			if result.StarCount < hasStarFilter {
 				continue
 				continue
 			}
 			}

+ 2 - 2
plugin/backend_linux.go

@@ -365,7 +365,7 @@ func (pm *Manager) List(pluginFilters filters.Args) ([]types.Plugin, error) {
 
 
 	enabledOnly := false
 	enabledOnly := false
 	disabledOnly := false
 	disabledOnly := false
-	if pluginFilters.Include("enabled") {
+	if pluginFilters.Contains("enabled") {
 		if pluginFilters.ExactMatch("enabled", "true") {
 		if pluginFilters.ExactMatch("enabled", "true") {
 			enabledOnly = true
 			enabledOnly = true
 		} else if pluginFilters.ExactMatch("enabled", "false") {
 		} else if pluginFilters.ExactMatch("enabled", "false") {
@@ -386,7 +386,7 @@ next:
 		if disabledOnly && p.PluginObj.Enabled {
 		if disabledOnly && p.PluginObj.Enabled {
 			continue
 			continue
 		}
 		}
-		if pluginFilters.Include("capability") {
+		if pluginFilters.Contains("capability") {
 			for _, f := range p.GetTypes() {
 			for _, f := range p.GetTypes() {
 				if !pluginFilters.Match("capability", f.Capability) {
 				if !pluginFilters.Match("capability", f.Capability) {
 					continue next
 					continue next