Current registry reference use a subset of dns and IPv4 addresses to
represent a registry domain.
Since registries are mostly compatible with rfc3986, that defines the
URI generic syntax, this adds support for IPv6 enclosed in squared
brackets based on the mentioned rfc.
The regexp is only expanded to match on IPv6 addreses enclosed between
square brackets, considering only regular IPv6 addresses represented
as compressed or uncompressed, excluding special IPv6 address
representations.
Signed-off-by: Antonio Ojea <antonio.ojea.garcia@gmail.com>
Go 1.13 and up enforce import paths to be versioned if a project
contains a go.mod and has released v2 or up.
The current v2.x branches (and releases) do not yet have a go.mod,
and therefore are still allowed to be imported with a non-versioned
import path (go modules add a `+incompatible` annotation in that case).
However, now that this project has a `go.mod` file, incompatible
import paths will not be accepted by go modules, and attempting
to use code from this repository will fail.
This patch uses `v3` for the import-paths (not `v2`), because changing
import paths itself is a breaking change, which means that the
next release should increment the "major" version to comply with
SemVer (as go modules dictate).
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Allows having other parsers which are capable of unambiguously keeping domain and path separated in a Reference type.
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
When WithDigest is called on a reference that has a tag, it should
preserve the tag.
When WithTag is called on a reference that has digest, it should
preserve the digest.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Use the same error message as is used in
docker/reference/reference.go to provide
slightly more information about the error.
This change tests if the reference passes
after lowercasing its characters, to determine
if the reference was invalid due to
it containing uppercase characters.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
There is a constraint on the length of the name in a reference, so
WithName should be checking this instead of potentially creating a
reference that doesn't comply with the rules.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This was using a different regexp from the intended one. This meant that
tags with uppercase characters were not accepted.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Various improvements motivated by early real-world use in engine code
under development:
- Make `WithDigest` return `Canonical`, since the return value always
has a name and a digest.
- Introduce a `NamedTagged` type, which can be used for strongly typing
cases where something must have a name and a tag.
- Rename `ParseNamed` to `WithName`, and create a
`ParseNamed` that accepts tags and digests (returning a `Named` type).
The new `ParseNamed` makes code using the reference package much less
verbose, since typical use cases require a name, and this is an
additional type assertion and error case after every `Parse` call.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
These functions allow a Named type to be combined with a tag or a
digest. WithTag will replace the ImageReference function in
github.com/docker/docker/utils as the Docker Engine transitions to the
reference package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Since reference itself may be represented by multiple types which implement the reference inteface, serialization can lead to ambiguous type which cannot be deserialized.
Field wraps the reference object to ensure that the correct type is always deserialized, requiring an extra unwrap of the reference after deserialization.
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
There seems to be a need for a type that represents a way of pointing
to an image, irrespective of the implementation.
This patch defines a Reference interface and provides 3 implementations:
- TagReference: when only a tag is provided
- DigestReference: when a digest (according to the digest package) is
provided, can include optional tag as well
Validation of references are purely syntactic.
There is also a strong type for tags, analogous to digests, as well
as a strong type for Repository from which clients can access the
hostname alone, or the repository name without the hostname, or both
together via the String() method.
For Repository, the files names.go and names_test.go were moved from
the v2 package.
Signed-off-by: Tibor Vass <tibor@docker.com>