Skip to content

Commit 3a12793

Browse files
committedFeb 7, 2017
Use distribution reference
Remove forked reference package. Use normalized named values everywhere and familiar functions to convert back to familiar strings for UX and storage compatibility. Enforce that the source repository in the distribution metadata is always a normalized string, ignore invalid values which are not. Update distribution tests to use normalized values. Signed-off-by: Derek McGowan <[email protected]> (github: dmcgowan)
1 parent 2bea873 commit 3a12793

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+538
-1117
lines changed
 

‎api/server/router/plugin/backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"io"
55
"net/http"
66

7+
"github.com/docker/distribution/reference"
78
enginetypes "github.com/docker/docker/api/types"
89
"github.com/docker/docker/api/types/filters"
9-
"github.com/docker/docker/reference"
1010
"golang.org/x/net/context"
1111
)
1212

‎api/server/router/plugin/plugin_routes.go

+17-30
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import (
77
"strconv"
88
"strings"
99

10-
distreference "github.com/docker/distribution/reference"
10+
"github.com/docker/distribution/reference"
1111
"github.com/docker/docker/api/server/httputils"
1212
"github.com/docker/docker/api/types"
1313
"github.com/docker/docker/api/types/filters"
1414
"github.com/docker/docker/pkg/ioutils"
1515
"github.com/docker/docker/pkg/streamformatter"
16-
"github.com/docker/docker/reference"
1716
"github.com/pkg/errors"
1817
"golang.org/x/net/context"
1918
)
@@ -47,39 +46,27 @@ func parseHeaders(headers http.Header) (map[string][]string, *types.AuthConfig)
4746
// be returned.
4847
func parseRemoteRef(remote string) (reference.Named, string, error) {
4948
// Parse remote reference, supporting remotes with name and tag
50-
// NOTE: Using distribution reference to handle references
51-
// containing both a name and digest
52-
remoteRef, err := distreference.ParseNamed(remote)
49+
remoteRef, err := reference.ParseNormalizedNamed(remote)
5350
if err != nil {
5451
return nil, "", err
5552
}
5653

57-
var tag string
58-
if t, ok := remoteRef.(distreference.Tagged); ok {
59-
tag = t.Tag()
54+
type canonicalWithTag interface {
55+
reference.Canonical
56+
Tag() string
6057
}
6158

62-
// Convert distribution reference to docker reference
63-
// TODO: remove when docker reference changes reconciled upstream
64-
ref, err := reference.WithName(remoteRef.Name())
65-
if err != nil {
66-
return nil, "", err
67-
}
68-
if d, ok := remoteRef.(distreference.Digested); ok {
69-
ref, err = reference.WithDigest(ref, d.Digest())
70-
if err != nil {
71-
return nil, "", err
72-
}
73-
} else if tag != "" {
74-
ref, err = reference.WithTag(ref, tag)
59+
if canonical, ok := remoteRef.(canonicalWithTag); ok {
60+
remoteRef, err = reference.WithDigest(reference.TrimNamed(remoteRef), canonical.Digest())
7561
if err != nil {
7662
return nil, "", err
7763
}
78-
} else {
79-
ref = reference.WithDefaultTag(ref)
64+
return remoteRef, canonical.Tag(), nil
8065
}
8166

82-
return ref, tag, nil
67+
remoteRef = reference.TagNameOnly(remoteRef)
68+
69+
return remoteRef, "", nil
8370
}
8471

8572
func (pr *pluginRouter) getPrivileges(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
@@ -188,24 +175,24 @@ func getName(ref reference.Named, tag, name string) (string, error) {
188175
if err != nil {
189176
return "", err
190177
}
191-
name = nt.String()
178+
name = reference.FamiliarString(nt)
192179
} else {
193-
name = reference.WithDefaultTag(trimmed).String()
180+
name = reference.FamiliarString(reference.TagNameOnly(trimmed))
194181
}
195182
} else {
196-
name = ref.String()
183+
name = reference.FamiliarString(ref)
197184
}
198185
} else {
199-
localRef, err := reference.ParseNamed(name)
186+
localRef, err := reference.ParseNormalizedNamed(name)
200187
if err != nil {
201188
return "", err
202189
}
203190
if _, ok := localRef.(reference.Canonical); ok {
204191
return "", errors.New("cannot use digest in plugin tag")
205192
}
206-
if distreference.IsNameOnly(localRef) {
193+
if reference.IsNameOnly(localRef) {
207194
// TODO: log change in name to out stream
208-
name = reference.WithDefaultTag(localRef).String()
195+
name = reference.FamiliarString(reference.TagNameOnly(localRef))
209196
}
210197
}
211198
return name, nil

0 commit comments

Comments
 (0)
Please sign in to comment.