mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Replace uses of filters.Include() with filters.Contains()
The `filters.Include()` method was deprecated in favor of `filters.Contains()`
in 065118390a
, 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>
This commit is contained in:
parent
147443a426
commit
97c5ae25c4
9 changed files with 45 additions and 34 deletions
|
@ -45,27 +45,27 @@ func filterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.N
|
|||
|
||||
displayNet := []types.NetworkResource{}
|
||||
for _, nw := range nws {
|
||||
if filter.Include("driver") {
|
||||
if filter.Contains("driver") {
|
||||
if !filter.ExactMatch("driver", nw.Driver) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if filter.Include("name") {
|
||||
if filter.Contains("name") {
|
||||
if !filter.Match("name", nw.Name) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if filter.Include("id") {
|
||||
if filter.Contains("id") {
|
||||
if !filter.Match("id", nw.ID) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if filter.Include("label") {
|
||||
if filter.Contains("label") {
|
||||
if !filter.MatchKVList("label", nw.Labels) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if filter.Include("scope") {
|
||||
if filter.Contains("scope") {
|
||||
if !filter.ExactMatch("scope", nw.Scope) {
|
||||
continue
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func filterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.N
|
|||
displayNet = append(displayNet, nw)
|
||||
}
|
||||
|
||||
if filter.Include("type") {
|
||||
if filter.Contains("type") {
|
||||
typeNet := []types.NetworkResource{}
|
||||
errFilter := filter.WalkValues("type", func(fval string) error {
|
||||
passList, err := filterNetworkByType(displayNet, fval)
|
||||
|
|
|
@ -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) {
|
||||
f := NewArgs()
|
||||
if f.Include("status") {
|
||||
|
|
|
@ -74,7 +74,7 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
|
|||
services := make([]types.Service, 0, len(r.Services))
|
||||
|
||||
for _, service := range r.Services {
|
||||
if options.Filters.Include("mode") {
|
||||
if options.Filters.Contains("mode") {
|
||||
var mode string
|
||||
switch service.Spec.GetMode().(type) {
|
||||
case *swarmapi.ServiceSpec_Global:
|
||||
|
|
|
@ -49,14 +49,14 @@ func (ef *Filter) filterContains(field string, values map[string]struct{}) bool
|
|||
}
|
||||
|
||||
func (ef *Filter) matchScope(scope string) bool {
|
||||
if !ef.filter.Include("scope") {
|
||||
if !ef.filter.Contains("scope") {
|
||||
return true
|
||||
}
|
||||
return ef.filter.ExactMatch("scope", scope)
|
||||
}
|
||||
|
||||
func (ef *Filter) matchLabels(attributes map[string]string) bool {
|
||||
if !ef.filter.Include("label") {
|
||||
if !ef.filter.Contains("label") {
|
||||
return true
|
||||
}
|
||||
return ef.filter.MatchKVList("label", attributes)
|
||||
|
|
|
@ -67,7 +67,7 @@ func (daemon *Daemon) Images(imageFilters filters.Args, all bool, withExtraAttrs
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if imageFilters.Include("dangling") {
|
||||
if imageFilters.Contains("dangling") {
|
||||
if imageFilters.ExactMatch("dangling", "true") {
|
||||
danglingOnly = true
|
||||
} 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)
|
||||
if img.Config == nil {
|
||||
continue
|
||||
|
@ -150,7 +150,7 @@ func (daemon *Daemon) Images(imageFilters filters.Args, all bool, withExtraAttrs
|
|||
newImage := newImage(img, size)
|
||||
|
||||
for _, ref := range daemon.referenceStore.References(id.Digest()) {
|
||||
if imageFilters.Include("reference") {
|
||||
if imageFilters.Contains("reference") {
|
||||
var found bool
|
||||
var matchErr error
|
||||
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 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
|
||||
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
|
||||
}
|
||||
newImage.RepoDigests = []string{"<none>@<none>"}
|
||||
|
|
|
@ -276,7 +276,7 @@ func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerLis
|
|||
}
|
||||
|
||||
var taskFilter, isTask bool
|
||||
if psFilters.Include("is-task") {
|
||||
if psFilters.Contains("is-task") {
|
||||
if psFilters.ExactMatch("is-task", "true") {
|
||||
taskFilter = true
|
||||
isTask = true
|
||||
|
@ -319,7 +319,7 @@ func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerLis
|
|||
|
||||
imagesFilter := map[image.ID]bool{}
|
||||
var ancestorFilter bool
|
||||
if psFilters.Include("ancestor") {
|
||||
if psFilters.Contains("ancestor") {
|
||||
ancestorFilter = true
|
||||
psFilters.WalkValues("ancestor", func(ancestor string) error {
|
||||
id, platform, err := daemon.GetImageIDAndPlatform(ancestor)
|
||||
|
@ -465,7 +465,7 @@ func includeContainerInList(container *container.Snapshot, ctx *listContext) ite
|
|||
return excludeContainer
|
||||
}
|
||||
|
||||
if ctx.filters.Include("volume") {
|
||||
if ctx.filters.Contains("volume") {
|
||||
volumesByName := make(map[string]types.MountPoint)
|
||||
for _, m := range container.Mounts {
|
||||
if m.Name != "" {
|
||||
|
@ -509,7 +509,7 @@ func includeContainerInList(container *container.Snapshot, ctx *listContext) ite
|
|||
networkExist = errors.New("container part of network")
|
||||
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 {
|
||||
if container.NetworkSettings == nil {
|
||||
return noNetworks
|
||||
|
@ -627,17 +627,17 @@ func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) (
|
|||
|
||||
var retVols []volume.Volume
|
||||
for _, vol := range vols {
|
||||
if filter.Include("name") {
|
||||
if filter.Contains("name") {
|
||||
if !filter.Match("name", vol.Name()) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if filter.Include("driver") {
|
||||
if filter.Contains("driver") {
|
||||
if !filter.ExactMatch("driver", vol.DriverName()) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if filter.Include("label") {
|
||||
if filter.Contains("label") {
|
||||
v, ok := vol.(volume.DetailedVolume)
|
||||
if !ok {
|
||||
continue
|
||||
|
@ -649,7 +649,7 @@ func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) (
|
|||
retVols = append(retVols, vol)
|
||||
}
|
||||
danglingOnly := false
|
||||
if filter.Include("dangling") {
|
||||
if filter.Contains("dangling") {
|
||||
if filter.ExactMatch("dangling", "true") || filter.ExactMatch("dangling", "1") {
|
||||
danglingOnly = true
|
||||
} else if !filter.ExactMatch("dangling", "false") && !filter.ExactMatch("dangling", "0") {
|
||||
|
|
|
@ -182,7 +182,7 @@ func (daemon *Daemon) ImagesPrune(ctx context.Context, pruneFilters filters.Args
|
|||
rep := &types.ImagesPruneReport{}
|
||||
|
||||
danglingOnly := true
|
||||
if pruneFilters.Include("dangling") {
|
||||
if pruneFilters.Contains("dangling") {
|
||||
if pruneFilters.ExactMatch("dangling", "false") || pruneFilters.ExactMatch("dangling", "0") {
|
||||
danglingOnly = false
|
||||
} 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) {
|
||||
until := time.Time{}
|
||||
if !pruneFilters.Include("until") {
|
||||
if !pruneFilters.Contains("until") {
|
||||
return until, nil
|
||||
}
|
||||
untilFilters := pruneFilters.Get("until")
|
||||
|
@ -464,8 +464,8 @@ func matchLabels(pruneFilters filters.Args, labels map[string]string) bool {
|
|||
return false
|
||||
}
|
||||
// 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) {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -33,21 +33,21 @@ func (daemon *Daemon) SearchRegistryForImages(ctx context.Context, filtersArgs s
|
|||
|
||||
var isAutomated, isOfficial bool
|
||||
var hasStarFilter = 0
|
||||
if searchFilters.Include("is-automated") {
|
||||
if searchFilters.Contains("is-automated") {
|
||||
if searchFilters.UniqueExactMatch("is-automated", "true") {
|
||||
isAutomated = true
|
||||
} else if !searchFilters.UniqueExactMatch("is-automated", "false") {
|
||||
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") {
|
||||
isOfficial = true
|
||||
} else if !searchFilters.UniqueExactMatch("is-official", "false") {
|
||||
return nil, invalidFilter{"is-official", searchFilters.Get("is-official")}
|
||||
}
|
||||
}
|
||||
if searchFilters.Include("stars") {
|
||||
if searchFilters.Contains("stars") {
|
||||
hasStars := searchFilters.Get("stars")
|
||||
for _, hasStar := range hasStars {
|
||||
iHasStar, err := strconv.Atoi(hasStar)
|
||||
|
@ -67,17 +67,17 @@ func (daemon *Daemon) SearchRegistryForImages(ctx context.Context, filtersArgs s
|
|||
|
||||
filteredResults := []registrytypes.SearchResult{}
|
||||
for _, result := range unfilteredResult.Results {
|
||||
if searchFilters.Include("is-automated") {
|
||||
if searchFilters.Contains("is-automated") {
|
||||
if isAutomated != result.IsAutomated {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if searchFilters.Include("is-official") {
|
||||
if searchFilters.Contains("is-official") {
|
||||
if isOfficial != result.IsOfficial {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if searchFilters.Include("stars") {
|
||||
if searchFilters.Contains("stars") {
|
||||
if result.StarCount < hasStarFilter {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -365,7 +365,7 @@ func (pm *Manager) List(pluginFilters filters.Args) ([]types.Plugin, error) {
|
|||
|
||||
enabledOnly := false
|
||||
disabledOnly := false
|
||||
if pluginFilters.Include("enabled") {
|
||||
if pluginFilters.Contains("enabled") {
|
||||
if pluginFilters.ExactMatch("enabled", "true") {
|
||||
enabledOnly = true
|
||||
} else if pluginFilters.ExactMatch("enabled", "false") {
|
||||
|
@ -386,7 +386,7 @@ next:
|
|||
if disabledOnly && p.PluginObj.Enabled {
|
||||
continue
|
||||
}
|
||||
if pluginFilters.Include("capability") {
|
||||
if pluginFilters.Contains("capability") {
|
||||
for _, f := range p.GetTypes() {
|
||||
if !pluginFilters.Match("capability", f.Capability) {
|
||||
continue next
|
||||
|
|
Loading…
Add table
Reference in a new issue