mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
api/types/filters: remove deprecated ToParamWithVersion
It's only used by the client to support API versions older than v1.22. Make it an internal utility that doesn't depend on internal fields of `filter.Args`. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -81,3 +81,41 @@ func encodePlatform(platform *ocispec.Platform) (string, error) {
|
||||
}
|
||||
return string(p), nil
|
||||
}
|
||||
|
||||
// encodeLegacyFilters encodes Args in the legacy format as used in API v1.21 and older.
|
||||
// where values are a list of strings, instead of a set.
|
||||
//
|
||||
// Don't use in any new code; use [filters.ToJSON]] instead.
|
||||
func encodeLegacyFilters(currentFormat string) (string, error) {
|
||||
// The Args.fields field is not exported, but used to marshal JSON,
|
||||
// so we'll marshal to the new format, then unmarshal to get the
|
||||
// fields, and marshal again.
|
||||
//
|
||||
// This is far from optimal, but this code is only used for deprecated
|
||||
// API versions, so should not be hit commonly.
|
||||
var argsFields map[string]map[string]bool
|
||||
err := json.Unmarshal([]byte(currentFormat), &argsFields)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
buf, err := json.Marshal(convertArgsToSlice(argsFields))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(buf), nil
|
||||
}
|
||||
|
||||
func convertArgsToSlice(f map[string]map[string]bool) map[string][]string {
|
||||
m := map[string][]string{}
|
||||
for k, v := range f {
|
||||
values := []string{}
|
||||
for kk := range v {
|
||||
if v[kk] {
|
||||
values = append(values, kk)
|
||||
}
|
||||
}
|
||||
m[k] = values
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user