Commit Graph

28 Commits

Author SHA1 Message Date
Miloslav Trmač 777b215177 API transition: Drop reference.XNamedTagged
Instead use distreference.NamedTagged directly.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 751e8a5a2e Implementation collapse: Drop taggedRef
Now that taggedRef merely wraps a distreference.NamedTagged, adding no
functionality, just use a distreference.NamedTagged directly.  This also
simplifies XWithTag to merely call distreference.WithTag.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 0268d9077d API transition: Drop XNamedTagged.XTag
Instead, call NamedTagged.Tag in all users.

XNamedTagged is now equivalent to distreference.NamedTagged.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 09779a3d73 Implementation transition: Use the NamedTagged in XTag instead of namedRef
Rely on the recently added member instead of the previous
implementation.

Does not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač c2360fcb87 Duplication: Have both a namedRef and NamedTagged in taggedRef
Similar to the .our/.upstream dance in namedRef, add a second,
write-only implementation in taggedRef.  Except now we go a bit faster
and skip the .our/.upstream member names.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač dfe2fafaa2 API transition: Drop reference.XNamed
Instead use the distreference.Named interface directly.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 7abfa9812f API transition: Drop XNamed.XString
Instead call distreference.FamiliarString() for SOME uses, generally for
error messages and StringWithinTransport().

In signature/policy_reference_match.go and signature/docker.go, where we
care about equality but not exactly about the kind of normalization, call
XNamed.String() instead, with the same rationale as the earlier
Name/FamiliarName choice.

In copy.Image, when creating a singature, use .String() (i.e. the fully
explicit form), for that extra bit of safety.

In tests, generally use the simpler .String() and modify expected
results, instead of calling FamilarString().

XNamed is now equivalent to distreference.Named, all the extra methods
have went away.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 2b4f09f141 API transition: Drop XNamed.XName
Instead call distreference.FamiliarName() in SOME uses.

In signature/policy_reference_match.go, where we care about equality but
not exactly about the kind of normalization, call XNamed.Name()
instead.  That compares the fully-explicit instaed of the
fully-minimized name forms.  If both canonicalizations are consistent,
this should not matter—and if they weren’t, using the fully explicit
form should be safer.  (Also, .Name() is likely to be a bit faster, but
that really doesn’t matter all that much.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 8cde5543dd API transition: Drop XNamed.XRemoteName
Instead call distreference.Path() in all users.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 2f8c595199 API transition: Drop XNamed.XHostname
Instead call distreference.Domain() in all users.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač df65181c70 API transition: Drop XNamed.XFullName
Instead call distreference.Named.Name() in all users.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 5240b7c4bb Simplification: Make namedRef implement distreference.Named
Instead of embedding a distreference.Named as a private field, embed it
as an anonymous field, making namedRef a valid distreference.Named
implementation.

This is EXTREMELY ugly.  In theory, docker/distribution/reference
should be able to work with any valid input implementing
distreference.Named() equally, based on only what the public method
implementations return.  In practice, the code expects specific
implementations of internal interfaces, and merely embeding a
distreference.Named into our struct makes our struct _not_ implement
these internal interfaces.  We are forced to explicitly define
forwarding methods, using an undocumented knowledge that the returned
distreference.Named implements them.

Soon enough we will completely eiliminate namedRef and use a
distreference.Named directly, and then distreference can keep playing
these ugly games without us having to care.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 5edbd7f016 Simplification: drop namedRef.our
Now that namedRef.our values are only used for computing other
namedRef.our values, drop the struct member and all code computing it,
including the entirety of our normalization code.

We still keep .upstream as a private member instead of using
distreference.Named directly, or making namedRef an implementation of
distreference.Named.

BEHAVIOR CHANGE: We used to minimize the input and then check whether it
is a 64-char hex string, now distreference.ParseNormalizedNamed first
checks for a 64-char hext string and then normalized (and by expanding,
not minimizing).  Hence, things like docker.io/$64hexchars are now
accepted, which is a behavior change (noticed by the tests).  Though,
there is really no risk of confusing such a value with a digest reference,
so this behavior change seems quite acceptable.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač e8533be03a Transition to .upstream: Use distreference.Familiar* instead of our normalization
Call the newly provided distreference.FamilarName and
distreference.FamiliarString instead of using our minimal canonical
version.

This removes the last “externally-visible” uses of .our.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 465998c6fa Transition to .upstream: Use instead of splitHostname
In the “new” methods introduced in docker/reference.[X]Named,
to return the fully expanded host/path/both, instead of using .our and
expanding it in splitHostname, rely on the fully-expanded .upstream and
its fully-expanded .Name(), and the newly introduced
distreference.Domain() and distreference.Path() helpers.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 2c1ea37d0f Transition to .upstream: Use in taggedRef and canonicalRef
Start transitioning from .our uses to .upstream.  First in the simplest
cases: taggedRef.Tag() and canonicalRef.Digest() are values in principle
unaffected by the name canonicalization, so this should be an obviously
correct change which does not change behavior.

Starting with this one to demostrate the principle of moving step by
step.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač 2db870f598 Duplication: Have TWO distreference.Named values in namedRef
To start a transition to the upstream distreference.Named
canonicalization semantics, first start computing the upstream value:

In namedRef (and its subtypes), carry BOTH an "our" field (with existing
semantics, canonical = minimal) and "upstream" field (with the upstream
semantics, canonical = fully explicit).

.upstream is currently essentially write-only: it is used _only_ to compute
further .upstream values.  Therefore, this does not change behavior
(perhaps apart from a bit more error checking which now happens on the
upstream value).

To make this reasonably possible, some of the public methods return a
*namedRef instead of a public type, which breaks golint.  This is
temporary.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač dda360d9ec API separation: Add an 'X' to all public names from c/i/docker/daemon/reference
This is an intermediate step which will eventually go away.

The goal of this PR is to get rid of c/i/docker/daemon/reference and to
replace uses of it by direct calls to docker/distribution/reference.

We can't do that safely and easily, because the two have different
semantics for reference.Named.Name() and reference.Named.String(): we
return a minimized version, e.g. "busybox", upstream returns an expanded
version, e.g. "docker.io/library/busybox".

BEFORE this commit the difference is hidden by using
docker/distribution/reference.WithName, which allows using the minimized
version, and works with it correctly; but because we want to use the
upstream canonicalization code, which will change semantics, we can't
just mix and match.

To make the distinction explicit, this commmit adds an X to ALL public
names from c/i/docker/daemon/reference.  E.g. a reference.XNamed type,
which has methods XName and XString.

This is pretty large, but does not change behavior at all.  By
inspection it is clear to see that reference.XNamed and subtypes does
not expose any of the non-X, conflicting, method names.

Using e.g.
> git diff --word-diff-regex=.|grep -F '{+'|grep -v '^\([^{]\|{+X+}\)*{\?$'
it is possible to see that most lines in this diff only add a single X
letter, and manually inspect the few lines which don't match the regexp.

The only REALLY new code is an explicit definition of namedRef.XName()
and namedRef.XString(), and two newly added casts to namedRef in cases
where we need to use the underlying distreference.Reference within
a reference.XNamed value.  Strictly speaking these changes change
behavior, in that third-party implementations of reference.XNamed are no
longer accepted; but we broke them by renaming at all.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:24:14 +01:00
Miloslav Trmač c035e748f7 Use docker/distribution/reference.ParseNormalizedNamed
docker/distribution/reference.ParseNamed now (as of
6170ac53daed40ebbebc9fe5f482495d01f09f12) refuses input in a
non-fully-explicit form; the new ParseNormalizedNamed accepts it and
normalizes it into the fully explicit form.  (One would expect it to be
the other way around…)

So, use ParseNormalizedNamed now.  This is a minimal fix for the failing
tests.

Because docker/distribution/reference now does all the normalization, we
can use it and drop our docker/docker/reference fork (which will go away
upstream), at least in the short term.  (Longer-term we may need to
reintroduce it again if projectatomic/docker decided to modify _that_.)
But that’s more than just fixing the tests, so that will be a separate
PR.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-01-19 22:35:15 +01:00
Antonio Murdaca f4c6ac26a2
*: move to opencontainers/go-digest
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-01-09 15:55:13 +01:00
Antonio Murdaca ded9fba96e
docker: reference: drop WithDigest to work with oci/go-digest
See https://github.com/docker/distribution/issues/2130

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-01-09 15:55:12 +01:00
Aleksa Sarai d0a45e907a
docker: reference: load sha256 explicitly
There has been a change in upstream (docker/distribution), where they
now require users of the digest library to load algorithms into the
binary (in other words they do .Available checks on crypto algorithms).

This fixes the unit test failures with "unsupported digest algorithm".

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2016-12-21 17:54:45 +11:00
George Lestaris bda6e4b37f Replace fmt.Errorf with pkg/errors.Wrap
Signed-off-by: George Lestaris <glestaris@pivotal.io>
2016-12-19 14:13:16 +00:00
Antonio Murdaca 6021224098
docker: fork docker/dockerreference pkg
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-10-11 16:53:40 +02:00
Antonio Murdaca 788d1c64cd docker: remove reference pkg
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-07-01 22:24:35 +02:00
Antonio Murdaca 0e45d01adc *: move reference pkg under docker
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-06-27 17:50:15 +02:00
Antonio Murdaca 7be01242a8 remove duplicate code
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-03-22 15:50:40 +01:00
Antonio Murdaca 6a00ce47d2 import cifetch code and add layers command
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-03-17 11:48:04 +01:00