Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit ff0c0a3

Browse files
Tibor VassthaJeztah
authored andcommitted
daemon/config: add MarshalJSON for future proofing
If anything marshals the daemon config now or in the future this commit ensures the correct canonical form for the builder GC policies' filters. Signed-off-by: Tibor Vass <tibor@docker.com> (cherry picked from commit 85733620ebea3da75abe7d732043354aa0883f8a) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: dae4436d1c742c88bba1a4e50a46f38f87f7ae17 Component: engine
1 parent 52f4e9b commit ff0c0a3

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

components/engine/api/types/filters/parse.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ func NewArgs(initialArgs ...KeyValuePair) Args {
3636
return args
3737
}
3838

39+
func (args Args) Keys() []string {
40+
keys := make([]string, 0, len(args.fields))
41+
for k := range args.fields {
42+
keys = append(keys, k)
43+
}
44+
return keys
45+
}
46+
3947
// MarshalJSON returns a JSON byte representation of the Args
4048
func (args Args) MarshalJSON() ([]byte, error) {
4149
if len(args.fields) == 0 {

components/engine/daemon/config/builder.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package config
22

33
import (
44
"encoding/json"
5+
"fmt"
6+
"sort"
57
"strings"
68

79
"github.com/docker/docker/api/types/filters"
@@ -16,6 +18,20 @@ type BuilderGCRule struct {
1618

1719
type BuilderGCFilter filters.Args
1820

21+
func (x *BuilderGCFilter) MarshalJSON() ([]byte, error) {
22+
f := filters.Args(*x)
23+
keys := f.Keys()
24+
sort.Strings(keys)
25+
arr := make([]string, 0, len(keys))
26+
for _, k := range keys {
27+
values := f.Get(k)
28+
for _, v := range values {
29+
arr = append(arr, fmt.Sprintf("%s=%s", k, v))
30+
}
31+
}
32+
return json.Marshal(arr)
33+
}
34+
1935
func (x *BuilderGCFilter) UnmarshalJSON(data []byte) error {
2036
var arr []string
2137
f := filters.NewArgs()

0 commit comments

Comments
 (0)