summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-04-07 18:55:23 -0400
committerGitHub <noreply@github.com>2021-04-07 18:55:23 -0400
commit9ba2e78cdcc28c15d72a76f6200a74e7ad6562b1 (patch)
treeb75ec2d72a516d2469dec5de8634fa0e0c9ad442
parent8c0df1c44a496d30b6e122c4ebc1dae9b5059607 (diff)
parent84907324fa02b8ede502a47b522fc717e782a909 (diff)
downloadpodman-9ba2e78cdcc28c15d72a76f6200a74e7ad6562b1.tar.gz
podman-9ba2e78cdcc28c15d72a76f6200a74e7ad6562b1.tar.bz2
podman-9ba2e78cdcc28c15d72a76f6200a74e7ad6562b1.zip
Merge pull request #9958 from jmguzik/limit-prune-filters-for-volumes
Volumes prune endpoint should use only prune filters
-rw-r--r--pkg/api/handlers/compat/volumes.go2
-rw-r--r--pkg/api/handlers/libpod/volumes.go2
-rw-r--r--pkg/domain/filters/volumes.go20
-rw-r--r--test/apiv2/30-volumes.at16
4 files changed, 37 insertions, 3 deletions
diff --git a/pkg/api/handlers/compat/volumes.go b/pkg/api/handlers/compat/volumes.go
index 42ece643b..d86fc1e19 100644
--- a/pkg/api/handlers/compat/volumes.go
+++ b/pkg/api/handlers/compat/volumes.go
@@ -266,7 +266,7 @@ func PruneVolumes(w http.ResponseWriter, r *http.Request) {
}
f := (url.Values)(*filterMap)
- filterFuncs, err := filters.GenerateVolumeFilters(f)
+ filterFuncs, err := filters.GeneratePruneVolumeFilters(f)
if err != nil {
utils.Error(w, "Something when wrong.", http.StatusInternalServerError, errors.Wrapf(err, "failed to parse filters for %s", f.Encode()))
return
diff --git a/pkg/api/handlers/libpod/volumes.go b/pkg/api/handlers/libpod/volumes.go
index 442b53d1e..68aec30d5 100644
--- a/pkg/api/handlers/libpod/volumes.go
+++ b/pkg/api/handlers/libpod/volumes.go
@@ -150,7 +150,7 @@ func pruneVolumesHelper(r *http.Request) ([]*reports.PruneReport, error) {
}
f := (url.Values)(*filterMap)
- filterFuncs, err := filters.GenerateVolumeFilters(f)
+ filterFuncs, err := filters.GeneratePruneVolumeFilters(f)
if err != nil {
return nil, err
}
diff --git a/pkg/domain/filters/volumes.go b/pkg/domain/filters/volumes.go
index 9b2fc5280..9a08adf82 100644
--- a/pkg/domain/filters/volumes.go
+++ b/pkg/domain/filters/volumes.go
@@ -75,7 +75,25 @@ func GenerateVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) {
return dangling
})
default:
- return nil, errors.Errorf("%q is in an invalid volume filter", filter)
+ return nil, errors.Errorf("%q is an invalid volume filter", filter)
+ }
+ }
+ }
+ return vf, nil
+}
+
+func GeneratePruneVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) {
+ var vf []libpod.VolumeFilter
+ for filter, v := range filters {
+ for _, val := range v {
+ switch filter {
+ case "label":
+ filter := val
+ vf = append(vf, func(v *libpod.Volume) bool {
+ return util.MatchLabelFilters([]string{filter}, v.Labels())
+ })
+ default:
+ return nil, errors.Errorf("%q is an invalid volume filter", filter)
}
}
}
diff --git a/test/apiv2/30-volumes.at b/test/apiv2/30-volumes.at
index 18ff31100..623e691e3 100644
--- a/test/apiv2/30-volumes.at
+++ b/test/apiv2/30-volumes.at
@@ -123,4 +123,20 @@ t POST libpod/volumes/prune 200
#After prune volumes, there should be no volume existing
t GET libpod/volumes/json 200 length=0
+# libpod api: do not use list filters for prune
+t POST libpod/volumes/prune?filters='{"name":["anyname"]}' 500 \
+ .cause="\"name\" is an invalid volume filter"
+t POST libpod/volumes/prune?filters='{"driver":["anydriver"]}' 500 \
+ .cause="\"driver\" is an invalid volume filter"
+t POST libpod/volumes/prune?filters='{"scope":["anyscope"]}' 500 \
+ .cause="\"scope\" is an invalid volume filter"
+
+# compat api: do not use list filters for prune
+t POST volumes/prune?filters='{"name":["anyname"]}' 500 \
+ .cause="\"name\" is an invalid volume filter"
+t POST volumes/prune?filters='{"driver":["anydriver"]}' 500 \
+ .cause="\"driver\" is an invalid volume filter"
+t POST volumes/prune?filters='{"scope":["anyscope"]}' 500 \
+ .cause="\"scope\" is an invalid volume filter"
+
# vim: filetype=sh