2020-01-17 08:58:12 +01:00
package middleware
import (
2020-01-20 08:02:58 +01:00
"fmt"
2020-03-13 04:16:13 +01:00
"regexp"
2020-01-20 08:02:58 +01:00
"github.com/docker/distribution/reference"
"github.com/opencontainers/go-digest"
2020-01-17 08:58:12 +01:00
)
const (
2020-01-20 08:02:58 +01:00
// RepositorySubexp is the name for sub regex that maps to repository name in the url
RepositorySubexp = "repository"
// ReferenceSubexp is the name for sub regex that maps to reference (tag or digest) url
ReferenceSubexp = "reference"
// DigestSubexp is the name for sub regex that maps to digest in the url
DigestSubexp = "digest"
2020-01-17 08:58:12 +01:00
)
2020-01-20 08:02:58 +01:00
var (
// V2ManifestURLRe is the regular expression for matching request v2 handler to view/delete manifest
V2ManifestURLRe = regexp . MustCompile ( fmt . Sprintf ( ` ^/v2/(?P<%s>%s)/manifests/(?P<%s>%s|%s)$ ` , RepositorySubexp , reference . NameRegexp . String ( ) , ReferenceSubexp , reference . TagRegexp . String ( ) , digest . DigestRegexp . String ( ) ) )
// V2TagListURLRe is the regular expression for matching request to v2 handler to list tags
V2TagListURLRe = regexp . MustCompile ( fmt . Sprintf ( ` ^/v2/(?P<%s>%s)/tags/list ` , RepositorySubexp , reference . NameRegexp . String ( ) ) )
2020-06-02 06:25:24 +02:00
// V2BlobURLRe is the regular expression for matching request to v2 handler to retrieve head/delete a blob
2020-01-20 08:02:58 +01:00
V2BlobURLRe = regexp . MustCompile ( fmt . Sprintf ( ` ^/v2/(?P<%s>%s)/blobs/(?P<%s>%s)$ ` , RepositorySubexp , reference . NameRegexp . String ( ) , DigestSubexp , digest . DigestRegexp . String ( ) ) )
// V2BlobUploadURLRe is the regular expression for matching the request to v2 handler to upload a blob, the upload uuid currently is not put into a group
V2BlobUploadURLRe = regexp . MustCompile ( fmt . Sprintf ( ` ^/v2/(?P<%s>%s)/blobs/uploads[/a-zA-Z0-9\-_\.=]*$ ` , RepositorySubexp , reference . NameRegexp . String ( ) ) )
// V2CatalogURLRe is the regular expression for mathing the request to v2 handler to list catalog
V2CatalogURLRe = regexp . MustCompile ( ` ^/v2/_catalog$ ` )
2020-01-17 08:58:12 +01:00
)