normalize_deprecated.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package reference
  2. import (
  3. "regexp"
  4. "github.com/distribution/reference"
  5. "github.com/opencontainers/go-digest"
  6. "github.com/opencontainers/go-digest/digestset"
  7. )
  8. // ParseNormalizedNamed parses a string into a named reference
  9. // transforming a familiar name from Docker UI to a fully
  10. // qualified reference. If the value may be an identifier
  11. // use ParseAnyReference.
  12. //
  13. // Deprecated: use [reference.ParseNormalizedNamed].
  14. func ParseNormalizedNamed(s string) (reference.Named, error) {
  15. return reference.ParseNormalizedNamed(s)
  16. }
  17. // ParseDockerRef normalizes the image reference following the docker convention,
  18. // which allows for references to contain both a tag and a digest.
  19. //
  20. // Deprecated: use [reference.ParseDockerRef].
  21. func ParseDockerRef(ref string) (reference.Named, error) {
  22. return reference.ParseDockerRef(ref)
  23. }
  24. // TagNameOnly adds the default tag "latest" to a reference if it only has
  25. // a repo name.
  26. //
  27. // Deprecated: use [reference.TagNameOnly].
  28. func TagNameOnly(ref reference.Named) reference.Named {
  29. return reference.TagNameOnly(ref)
  30. }
  31. // ParseAnyReference parses a reference string as a possible identifier,
  32. // full digest, or familiar name.
  33. //
  34. // Deprecated: use [reference.ParseAnyReference].
  35. func ParseAnyReference(ref string) (reference.Reference, error) {
  36. return reference.ParseAnyReference(ref)
  37. }
  38. // Functions and types below have been removed in distribution v3 and
  39. // have not been ported to github.com/distribution/reference. See
  40. // https://github.com/distribution/distribution/pull/3774
  41. var (
  42. // ShortIdentifierRegexp is the format used to represent a prefix
  43. // of an identifier. A prefix may be used to match a sha256 identifier
  44. // within a list of trusted identifiers.
  45. //
  46. // Deprecated: support for short-identifiers is deprecated, and will be removed in v3.
  47. ShortIdentifierRegexp = regexp.MustCompile(shortIdentifier)
  48. shortIdentifier = `([a-f0-9]{6,64})`
  49. // anchoredShortIdentifierRegexp is used to check if a value
  50. // is a possible identifier prefix, anchored at start and end
  51. // of string.
  52. anchoredShortIdentifierRegexp = regexp.MustCompile(`^` + shortIdentifier + `$`)
  53. )
  54. type digestReference digest.Digest
  55. func (d digestReference) String() string {
  56. return digest.Digest(d).String()
  57. }
  58. func (d digestReference) Digest() digest.Digest {
  59. return digest.Digest(d)
  60. }
  61. // ParseAnyReferenceWithSet parses a reference string as a possible short
  62. // identifier to be matched in a digest set, a full digest, or familiar name.
  63. //
  64. // Deprecated: support for short-identifiers is deprecated, and will be removed in v3.
  65. func ParseAnyReferenceWithSet(ref string, ds *digestset.Set) (Reference, error) {
  66. if ok := anchoredShortIdentifierRegexp.MatchString(ref); ok {
  67. dgst, err := ds.Lookup(ref)
  68. if err == nil {
  69. return digestReference(dgst), nil
  70. }
  71. } else {
  72. if dgst, err := digest.Parse(ref); err == nil {
  73. return digestReference(dgst), nil
  74. }
  75. }
  76. return reference.ParseNormalizedNamed(ref)
  77. }