diff --git a/go.mod b/go.mod index 20c429b6e8..21002a88c1 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/containernetworking/cni v1.1.2 github.com/containernetworking/plugins v1.3.0 github.com/containers/buildah v1.32.0 - github.com/containers/common v0.56.1-0.20230922104122-56ed984ea383 + github.com/containers/common v0.56.1-0.20230925164139-e18cda8d7750 github.com/containers/conmon v2.0.20+incompatible github.com/containers/gvisor-tap-vsock v0.7.1-0.20230922151156-97028a6a6d6a github.com/containers/image/v5 v5.28.0 diff --git a/go.sum b/go.sum index a51e2ce64c..2bef480368 100644 --- a/go.sum +++ b/go.sum @@ -249,8 +249,8 @@ github.com/containernetworking/plugins v1.3.0 h1:QVNXMT6XloyMUoO2wUOqWTC1hWFV62Q github.com/containernetworking/plugins v1.3.0/go.mod h1:Pc2wcedTQQCVuROOOaLBPPxrEXqqXBFt3cZ+/yVg6l0= github.com/containers/buildah v1.32.0 h1:uz5Rcf7lGeStj7iPTBgO4UdhQYZqMMzyt9suDf16k1k= github.com/containers/buildah v1.32.0/go.mod h1:sN3rA3DbnqekNz3bNdkqWduuirYDuMs54LUCOZOomBE= -github.com/containers/common v0.56.1-0.20230922104122-56ed984ea383 h1:+SPOIY+DIO5nExB66n9aVWZi/yzcLpks6Ys4IwVxOLY= -github.com/containers/common v0.56.1-0.20230922104122-56ed984ea383/go.mod h1:ABFEglmyt48WWWQv80kGhitfbVfR1Br35wk3gBQdrIk= +github.com/containers/common v0.56.1-0.20230925164139-e18cda8d7750 h1:16M7tpn2zsrbJCYZ9ARjLerUQDg68pUGvWRFeTR0dhM= +github.com/containers/common v0.56.1-0.20230925164139-e18cda8d7750/go.mod h1:ABFEglmyt48WWWQv80kGhitfbVfR1Br35wk3gBQdrIk= github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg= github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I= github.com/containers/gvisor-tap-vsock v0.7.1-0.20230922151156-97028a6a6d6a h1:AytlbDLdlu6fZxulV3sHrXYQpQpkipNCZA6LGwcL37M= diff --git a/vendor/github.com/containers/common/pkg/filters/filters.go b/vendor/github.com/containers/common/pkg/filters/filters.go index 84fe368f31..3d442a5306 100644 --- a/vendor/github.com/containers/common/pkg/filters/filters.go +++ b/vendor/github.com/containers/common/pkg/filters/filters.go @@ -107,13 +107,7 @@ func PrepareFilters(r *http.Request) (map[string][]string, error) { func MatchLabelFilters(filterValues []string, labels map[string]string) bool { outer: for _, filterValue := range filterValues { - filterArray := strings.SplitN(filterValue, "=", 2) - filterKey := filterArray[0] - if len(filterArray) > 1 { - filterValue = filterArray[1] - } else { - filterValue = "" - } + filterKey, filterValue := splitFilterValue(filterValue) for labelKey, labelValue := range labels { if filterValue == "" || labelValue == filterValue { if labelKey == filterKey || matchPattern(filterKey, labelKey) { @@ -126,6 +120,32 @@ outer: return true } +// MatchNegatedLabelFilters matches negated labels and returns true if they are valid +func MatchNegatedLabelFilters(filterValues []string, labels map[string]string) bool { + for _, filterValue := range filterValues { + filterKey, filterValue := splitFilterValue(filterValue) + for labelKey, labelValue := range labels { + if filterValue == "" || labelValue == filterValue { + if labelKey == filterKey || matchPattern(filterKey, labelKey) { + return false + } + } + } + } + return true +} + +func splitFilterValue(filterValue string) (string, string) { + filterArray := strings.SplitN(filterValue, "=", 2) + filterKey := filterArray[0] + if len(filterArray) > 1 { + filterValue = filterArray[1] + } else { + filterValue = "" + } + return filterKey, filterValue +} + func matchPattern(pattern string, value string) bool { if strings.Contains(pattern, "*") { filter := fmt.Sprintf("*%s*", pattern) diff --git a/vendor/modules.txt b/vendor/modules.txt index 026354075d..547791aab3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -164,7 +164,7 @@ github.com/containers/buildah/pkg/sshagent github.com/containers/buildah/pkg/util github.com/containers/buildah/pkg/volumes github.com/containers/buildah/util -# github.com/containers/common v0.56.1-0.20230922104122-56ed984ea383 +# github.com/containers/common v0.56.1-0.20230925164139-e18cda8d7750 ## explicit; go 1.18 github.com/containers/common/libimage github.com/containers/common/libimage/define