Remove dependencies on registry packages
Because docker core cannot vendor non-master Go dependencies, we need to remove dependencies on registry package. The definition of digest.Digest has been changed to a string and the regular expressions have been ported from docker-registry/common library. We'll likely change this be dependent on the registry in the future when the API stabilizies and use of the master branch becomes the norm. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
2fcad2a10f
commit
ee1e1abb15
4 changed files with 28 additions and 15 deletions
|
@ -4,8 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker-registry/digest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestErrorCodes ensures that error code format, mappings and
|
// TestErrorCodes ensures that error code format, mappings and
|
||||||
|
@ -61,7 +59,7 @@ func TestErrorsManagement(t *testing.T) {
|
||||||
|
|
||||||
errs.Push(ErrorCodeDigestInvalid)
|
errs.Push(ErrorCodeDigestInvalid)
|
||||||
errs.Push(ErrorCodeBlobUnknown,
|
errs.Push(ErrorCodeBlobUnknown,
|
||||||
map[string]digest.Digest{"digest": "sometestblobsumdoesntmatter"})
|
map[string]string{"digest": "sometestblobsumdoesntmatter"})
|
||||||
|
|
||||||
p, err := json.Marshal(errs)
|
p, err := json.Marshal(errs)
|
||||||
|
|
||||||
|
|
19
docs/v2/regexp.go
Normal file
19
docs/v2/regexp.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package v2
|
||||||
|
|
||||||
|
import "regexp"
|
||||||
|
|
||||||
|
// This file defines regular expressions for use in route definition. These
|
||||||
|
// are also defined in the registry code base. Until they are in a common,
|
||||||
|
// shared location, and exported, they must be repeated here.
|
||||||
|
|
||||||
|
// RepositoryNameComponentRegexp restricts registtry path components names to
|
||||||
|
// start with at least two letters or numbers, with following parts able to
|
||||||
|
// separated by one period, dash or underscore.
|
||||||
|
var RepositoryNameComponentRegexp = regexp.MustCompile(`[a-z0-9]+(?:[._-][a-z0-9]+)*`)
|
||||||
|
|
||||||
|
// RepositoryNameRegexp builds on RepositoryNameComponentRegexp to allow 2 to
|
||||||
|
// 5 path components, separated by a forward slash.
|
||||||
|
var RepositoryNameRegexp = regexp.MustCompile(`(?:` + RepositoryNameComponentRegexp.String() + `/){1,4}` + RepositoryNameComponentRegexp.String())
|
||||||
|
|
||||||
|
// TagNameRegexp matches valid tag names. From docker/docker:graph/tags.go.
|
||||||
|
var TagNameRegexp = regexp.MustCompile(`[\w][\w.-]{0,127}`)
|
|
@ -1,9 +1,6 @@
|
||||||
package v2
|
package v2
|
||||||
|
|
||||||
import (
|
import "github.com/gorilla/mux"
|
||||||
"github.com/docker/docker-registry/common"
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
)
|
|
||||||
|
|
||||||
// The following are definitions of the name under which all V2 routes are
|
// The following are definitions of the name under which all V2 routes are
|
||||||
// registered. These symbols can be used to look up a route based on the name.
|
// registered. These symbols can be used to look up a route based on the name.
|
||||||
|
@ -40,29 +37,29 @@ func Router() *mux.Router {
|
||||||
// PUT /v2/<name>/manifest/<tag> Image Manifest Upload the image manifest identified by name and tag.
|
// PUT /v2/<name>/manifest/<tag> Image Manifest Upload the image manifest identified by name and tag.
|
||||||
// DELETE /v2/<name>/manifest/<tag> Image Manifest Delete the image identified by name and tag.
|
// DELETE /v2/<name>/manifest/<tag> Image Manifest Delete the image identified by name and tag.
|
||||||
router.
|
router.
|
||||||
Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/manifests/{tag:" + common.TagNameRegexp.String() + "}").
|
Path("/v2/{name:" + RepositoryNameRegexp.String() + "}/manifests/{tag:" + TagNameRegexp.String() + "}").
|
||||||
Name(RouteNameManifest)
|
Name(RouteNameManifest)
|
||||||
|
|
||||||
// GET /v2/<name>/tags/list Tags Fetch the tags under the repository identified by name.
|
// GET /v2/<name>/tags/list Tags Fetch the tags under the repository identified by name.
|
||||||
router.
|
router.
|
||||||
Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/tags/list").
|
Path("/v2/{name:" + RepositoryNameRegexp.String() + "}/tags/list").
|
||||||
Name(RouteNameTags)
|
Name(RouteNameTags)
|
||||||
|
|
||||||
// GET /v2/<name>/blob/<digest> Layer Fetch the blob identified by digest.
|
// GET /v2/<name>/blob/<digest> Layer Fetch the blob identified by digest.
|
||||||
router.
|
router.
|
||||||
Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/blobs/{digest:[a-zA-Z0-9-_+.]+:[a-zA-Z0-9-_+.=]+}").
|
Path("/v2/{name:" + RepositoryNameRegexp.String() + "}/blobs/{digest:[a-zA-Z0-9-_+.]+:[a-zA-Z0-9-_+.=]+}").
|
||||||
Name(RouteNameBlob)
|
Name(RouteNameBlob)
|
||||||
|
|
||||||
// POST /v2/<name>/blob/upload/ Layer Upload Initiate an upload of the layer identified by tarsum.
|
// POST /v2/<name>/blob/upload/ Layer Upload Initiate an upload of the layer identified by tarsum.
|
||||||
router.
|
router.
|
||||||
Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/blobs/uploads/").
|
Path("/v2/{name:" + RepositoryNameRegexp.String() + "}/blobs/uploads/").
|
||||||
Name(RouteNameBlobUpload)
|
Name(RouteNameBlobUpload)
|
||||||
|
|
||||||
// GET /v2/<name>/blob/upload/<uuid> Layer Upload Get the status of the upload identified by tarsum and uuid.
|
// GET /v2/<name>/blob/upload/<uuid> Layer Upload Get the status of the upload identified by tarsum and uuid.
|
||||||
// PUT /v2/<name>/blob/upload/<uuid> Layer Upload Upload all or a chunk of the upload identified by tarsum and uuid.
|
// PUT /v2/<name>/blob/upload/<uuid> Layer Upload Upload all or a chunk of the upload identified by tarsum and uuid.
|
||||||
// DELETE /v2/<name>/blob/upload/<uuid> Layer Upload Cancel the upload identified by layer and uuid
|
// DELETE /v2/<name>/blob/upload/<uuid> Layer Upload Cancel the upload identified by layer and uuid
|
||||||
router.
|
router.
|
||||||
Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/blobs/uploads/{uuid}").
|
Path("/v2/{name:" + RepositoryNameRegexp.String() + "}/blobs/uploads/{uuid}").
|
||||||
Name(RouteNameBlobUploadChunk)
|
Name(RouteNameBlobUploadChunk)
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/docker/docker-registry/digest"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -88,10 +87,10 @@ func (ub *URLBuilder) BuildManifestURL(name, tag string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildBlobURL constructs the url for the blob identified by name and dgst.
|
// BuildBlobURL constructs the url for the blob identified by name and dgst.
|
||||||
func (ub *URLBuilder) BuildBlobURL(name string, dgst digest.Digest) (string, error) {
|
func (ub *URLBuilder) BuildBlobURL(name string, dgst string) (string, error) {
|
||||||
route := ub.cloneRoute(RouteNameBlob)
|
route := ub.cloneRoute(RouteNameBlob)
|
||||||
|
|
||||||
layerURL, err := route.URL("name", name, "digest", dgst.String())
|
layerURL, err := route.URL("name", name, "digest", dgst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue