Commit graph

21 commits

Author SHA1 Message Date
Sebastiaan van Stijn
a4cec8ca82
reference: introduce const for "localhost"
Localhost is treated special when parsing references, and always considered
to be a domain, despite not having a "." nor a ":port". Adding a const for
this, to allow documenting this special case (making it more visible).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-22 23:45:26 +01:00
Sebastiaan van Stijn
bbd41f40bb
reference: introduce remoteName variable
This pattern was used in two places, so adding an intermediate variable allows
documenting its purpose. The "remote-name" grammer (which is interchangably
used with "path") also seemed to be missing from the grammar, so adding it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-22 23:45:23 +01:00
Sebastiaan van Stijn
10eace9a53
reference: document consts for normalizing and legacy domain
These const could use some documentation, as it won't be clear why
they exist.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-20 15:07:24 +01:00
Sebastiaan van Stijn
53757ea337
reference: ParseDockerRef: slight refactor, and update docs
- improve documentation
- remove redundant error-check
- simplify interface matching, which slightly improves readability
- touch-up some docs

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-20 15:07:24 +01:00
Sebastiaan van Stijn
8163e20c6f
reference: splitDockerDomain: remove incorrect "TODO"
My mistake; I added this TODO in 552b1526c6, but it
only applies to familiarizeName.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-20 15:07:21 +01:00
Sebastiaan van Stijn
552b1526c6
reference: check for prefix instead of splitting, and use consts
- use strings.HasPrefix() to check for the prefix we're interested in instead
  of doing a strings.Split() without limits. This makes the code both easier
  to read, and prevents potential situations where we end up with a long slice.
- use consts for defaults; these should never be modified, so better to use
  consts for them to indicate they're fixed values.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-09 15:21:47 +01:00
Sebastiaan van Stijn
6d4f62d7fd
reference: remove support for deprecated "shortid" refs
The "shortid" syntax was added in d26a3b37a6,
and allowed for matching an image on its ID prefix (this is before images were
content-addressable). With the introduction of content-addressable references,
this syntax became problematic, and Docker deprecated this syntax in 2016
(Docker v1.13.0) through commit; 5fc71599a0

> The `repository:shortid` syntax for referencing images is very little used,
> collides with tag references, and can be confused with digest references.

Support for this syntax was removed in 2017 (Docker 17.12) through commit:
a942c92dd7

containerd uses a fork of the reference package with this syntax removed, and
does not support this syntax:
901bcb2231

This patch removes the deprecated syntax, the ParseAnyReferenceWithSet function,
and the ShortIdentifierRegexp regex.

As there are no external consumers for this function, nor the regexp, I'm
skipping a deprecation cycle for this;

- https://grep.app/search?q=.ShortIdentifierRegexp
- https://grep.app/search?q=.ParseAnyReferenceWithSet%28

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-06 20:23:30 +01:00
Derek McGowan
90e62ac24c
Merge pull request #2979 from avtakkar/avtakkar/fix-domain-split
Fix bug in parsing domain from repository reference
2021-03-01 09:35:14 -08:00
Sebastiaan van Stijn
1d33874951
go.mod: change imports to github.com/distribution/distribution/v3
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>
2021-02-08 18:30:46 +01:00
Chuanying Du
c26fa61ec9 Update repo normalize error message to include the name of the repo.
Signed-off-by: Chuanying Du <cydu@google.com>
2020-10-20 10:48:22 -07:00
Aviral Takkar
a19e1847a3
Fix bug in parsing domain from repository reference
Signed-off-by: Aviral Takkar <aviral26@users.noreply.github.com>
2020-09-17 00:07:19 -07:00
Sebastiaan van Stijn
0ac367fd6b
Add reference.ParseDockerRef utility function
ParseDockerRef normalizes the image reference following the docker
convention. This is added mainly for backward compatibility. The reference
returned can only be either tagged or digested. For reference contains both tag
and digest, the function returns digested reference, e.g.

    docker.io/library/busybox:latest@sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa

will be returned as

    docker.io/library/busybox@sha256:7cc4b5aefd1d0cadf8d97d4350462ba51c694ebca145b08d7d41b41acc8db5aa.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-01-04 21:26:06 +01:00
Aaron Lehmann
245ca4659e reference: Replace EnsureTagged with TagNameOnly
The common use case for this function is to add a default tag if the
reference only has a name. The current behavior only adds the default
tag if there is no *tag*, which requires most callers to check for a
digest. Change the behavior to only add default tags to name-only
references, and change the name to reflect this. The documentation
already described the new behavior, so it does not need to be changed.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-01-26 11:46:00 -08:00
Derek McGowan
7cb0c15480 Merge pull request #2137 from dmcgowan/reference-ambiguous-library-namespace
Remove ambiguity for unsupported official repository input
2017-01-13 16:22:41 -08:00
Derek McGowan
63cb8cf23b
Remove NormalizedNamed from public interface
The NormalizedNamed interface has shown to not be necessary for
integrating the change downstream. The FamiliarName and FamiliarString
helpers are the only used interface and allow hiding the normalized
completely.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
2017-01-11 12:58:47 -08:00
Derek McGowan
24cbdc41ba
Remove ambiguity for unsupported official repository input
Officials repositories always have 2 part names with the first part
being library and second part being the offical repository name. Names
with more than 2 parts should not hit the special case for official
repositories since they are not valid official repositories.
Add tests for this ambiguity and to ensure that 3 part names are
supports for the default repository, as used by the docker store.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
2017-01-11 10:46:48 -08:00
Derek McGowan
320f72d252
Unexport NamedRepository
NamedRepository only needs to be used internally. Additionally this
interface may go away in the future and be merged with Named.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
2017-01-09 15:44:59 -08:00
Derek McGowan
e0286a7de0
Use go-digest package
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
2017-01-09 15:44:13 -08:00
Derek McGowan
429c75faf0
Add NormalizedName interface
Add interface for for a normalized name and corresponding parser for that type.
New normalized versions of all interfaces are not added since all type information is preserved on calls to Familiar.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
2017-01-05 16:57:11 -08:00
Derek McGowan
042fe9bf46
Move docker reference functionality to reference package
Add normalization functions and Docker specific domain splitting to
reference package.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
2017-01-05 15:43:27 -08:00
Nishant Totla
2caeb6192a
Adding utility functions - IsNameOnly and WithDefaultTag
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
2016-11-11 15:17:16 -08:00