...

Source file src/github.com/docker/distribution/reference/normalize_deprecated.go

Documentation: github.com/docker/distribution/reference

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

View as plain text