소스 검색

filters: use json marshal, instead of beam/data

Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)
Vincent Batts 11 년 전
부모
커밋
89a15fa235
3개의 변경된 파일29개의 추가작업 그리고 7개의 파일을 삭제
  1. 12 2
      api/client/commands.go
  2. 13 4
      utils/filters/parse.go
  3. 4 1
      utils/filters/parse_test.go

+ 12 - 2
api/client/commands.go

@@ -1172,10 +1172,15 @@ func (cli *DockerCli) CmdImages(args ...string) error {
 	matchName := cmd.Arg(0)
 	matchName := cmd.Arg(0)
 	// FIXME: --viz and --tree are deprecated. Remove them in a future version.
 	// FIXME: --viz and --tree are deprecated. Remove them in a future version.
 	if *flViz || *flTree {
 	if *flViz || *flTree {
+		filterJson, err := filters.ToParam(imageFilterArgs)
+		if err != nil {
+			return err
+		}
 		v := url.Values{
 		v := url.Values{
 			"all":     []string{"1"},
 			"all":     []string{"1"},
-			"filters": []string{filters.ToParam(imageFilterArgs)},
+			"filters": []string{filterJson},
 		}
 		}
+
 		body, _, err := readBody(cli.call("GET", "/images/json?"+v.Encode(), nil, false))
 		body, _, err := readBody(cli.call("GET", "/images/json?"+v.Encode(), nil, false))
 		if err != nil {
 		if err != nil {
 			return err
 			return err
@@ -1237,9 +1242,14 @@ func (cli *DockerCli) CmdImages(args ...string) error {
 			fmt.Fprintf(cli.out, " base [style=invisible]\n}\n")
 			fmt.Fprintf(cli.out, " base [style=invisible]\n}\n")
 		}
 		}
 	} else {
 	} else {
+		filterJson, err := filters.ToParam(imageFilterArgs)
+		if err != nil {
+			return err
+		}
 		v := url.Values{
 		v := url.Values{
-			"filters": []string{filters.ToParam(imageFilterArgs)},
+			"filters": []string{filterJson},
 		}
 		}
+
 		if cmd.NArg() == 1 {
 		if cmd.NArg() == 1 {
 			// FIXME rename this parameter, to not be confused with the filters flag
 			// FIXME rename this parameter, to not be confused with the filters flag
 			v.Set("filter", matchName)
 			v.Set("filter", matchName)

+ 13 - 4
utils/filters/parse.go

@@ -1,8 +1,8 @@
 package filters
 package filters
 
 
 import (
 import (
+	"encoding/json"
 	"errors"
 	"errors"
-	"github.com/dotcloud/docker/pkg/beam/data"
 	"strings"
 	"strings"
 )
 )
 
 
@@ -40,13 +40,22 @@ var ErrorBadFormat = errors.New("bad format of filter (expected name=value)")
 /*
 /*
 packs the Args into an string for easy transport from client to server
 packs the Args into an string for easy transport from client to server
 */
 */
-func ToParam(a Args) string {
-	return data.Encode(a)
+func ToParam(a Args) (string, error) {
+	buf, err := json.Marshal(a)
+	if err != nil {
+		return "", err
+	}
+	return string(buf), nil
 }
 }
 
 
 /*
 /*
 unpacks the filter Args
 unpacks the filter Args
 */
 */
 func FromParam(p string) (Args, error) {
 func FromParam(p string) (Args, error) {
-	return data.Decode(p)
+	args := Args{}
+	err := json.Unmarshal([]byte(p), &args)
+	if err != nil {
+		return nil, err
+	}
+	return args, nil
 }
 }

+ 4 - 1
utils/filters/parse_test.go

@@ -36,7 +36,10 @@ func TestParam(t *testing.T) {
 		"image.name": []string{"ubuntu*", "*untu"},
 		"image.name": []string{"ubuntu*", "*untu"},
 	}
 	}
 
 
-	v := ToParam(a)
+	v, err := ToParam(a)
+	if err != nil {
+		t.Errorf("failed to marshal the filters: %s", err)
+	}
 	v1, err := FromParam(v)
 	v1, err := FromParam(v)
 	if err != nil {
 	if err != nil {
 		t.Errorf("%s", err)
 		t.Errorf("%s", err)