From da19114d1a54d65b04e422353155640162d9b728 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 11 Dec 2014 21:08:23 -0800 Subject: [PATCH] Prepare urls package for exports The route definition files have been prepared for export with documentation. Consts have been updated and tests are now passing for the urls package. --- api/urls/routes.go | 45 ++++++++++++++++++++++------------------- api/urls/routes_test.go | 28 ++++++++++++------------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/api/urls/routes.go b/api/urls/routes.go index b291ee4b..79138a4a 100644 --- a/api/urls/routes.go +++ b/api/urls/routes.go @@ -1,66 +1,69 @@ -package registry +package urls import ( "github.com/docker/docker-registry/common" "github.com/gorilla/mux" ) +// 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. const ( - routeNameBase = "base" - routeNameImageManifest = "image-manifest" - routeNameTags = "tags" - routeNameBlob = "blob" - routeNameBlobUpload = "blob-upload" - routeNameBlobUploadResume = "blob-upload-resume" + RouteNameBase = "base" + RouteNameManifest = "manifest" + RouteNameTags = "tags" + RouteNameBlob = "blob" + RouteNameBlobUpload = "blob-upload" + RouteNameBlobUploadChunk = "blob-upload-chunk" ) var allEndpoints = []string{ - routeNameImageManifest, - routeNameTags, - routeNameBlob, - routeNameBlobUpload, - routeNameBlobUploadResume, + RouteNameManifest, + RouteNameTags, + RouteNameBlob, + RouteNameBlobUpload, + RouteNameBlobUploadChunk, } -// v2APIRouter builds a gorilla router with named routes for the various API -// methods. We may export this for use by the client. -func v2APIRouter() *mux.Router { +// Router builds a gorilla router with named routes for the various API +// methods. This can be used directly by both server implementations and +// clients. +func Router() *mux.Router { router := mux.NewRouter(). StrictSlash(true) // GET /v2/ Check Check that the registry implements API version 2(.1) router. Path("/v2/"). - Name(routeNameBase) + Name(RouteNameBase) // GET /v2//manifest/ Image Manifest Fetch the image manifest identified by name and tag. // PUT /v2//manifest/ Image Manifest Upload the image manifest identified by name and tag. // DELETE /v2//manifest/ Image Manifest Delete the image identified by name and tag. router. Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/manifests/{tag:" + common.TagNameRegexp.String() + "}"). - Name(routeNameImageManifest) + Name(RouteNameManifest) // GET /v2//tags/list Tags Fetch the tags under the repository identified by name. router. Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/tags/list"). - Name(routeNameTags) + Name(RouteNameTags) // GET /v2//blob/ Layer Fetch the blob identified by digest. router. Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/blobs/{digest:[a-zA-Z0-9-_+.]+:[a-zA-Z0-9-_+.=]+}"). - Name(routeNameBlob) + Name(RouteNameBlob) // POST /v2//blob/upload/ Layer Upload Initiate an upload of the layer identified by tarsum. router. Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/blobs/uploads/"). - Name(routeNameBlobUpload) + Name(RouteNameBlobUpload) // GET /v2//blob/upload/ Layer Upload Get the status of the upload identified by tarsum and uuid. // PUT /v2//blob/upload/ Layer Upload Upload all or a chunk of the upload identified by tarsum and uuid. // DELETE /v2//blob/upload/ Layer Upload Cancel the upload identified by layer and uuid router. Path("/v2/{name:" + common.RepositoryNameRegexp.String() + "}/blobs/uploads/{uuid}"). - Name(routeNameBlobUploadResume) + Name(RouteNameBlobUploadChunk) return router } diff --git a/api/urls/routes_test.go b/api/urls/routes_test.go index 6d684a61..f2e95270 100644 --- a/api/urls/routes_test.go +++ b/api/urls/routes_test.go @@ -1,4 +1,4 @@ -package registry +package urls import ( "encoding/json" @@ -25,7 +25,7 @@ type routeTestCase struct { // This may go away as the application structure comes together. func TestRouter(t *testing.T) { - router := v2APIRouter() + router := Router() testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { testCase := routeTestCase{ @@ -47,12 +47,12 @@ func TestRouter(t *testing.T) { for _, testcase := range []routeTestCase{ { - RouteName: routeNameBase, + RouteName: RouteNameBase, RequestURI: "/v2/", Vars: map[string]string{}, }, { - RouteName: routeNameImageManifest, + RouteName: RouteNameManifest, RequestURI: "/v2/foo/bar/manifests/tag", Vars: map[string]string{ "name": "foo/bar", @@ -60,14 +60,14 @@ func TestRouter(t *testing.T) { }, }, { - RouteName: routeNameTags, + RouteName: RouteNameTags, RequestURI: "/v2/foo/bar/tags/list", Vars: map[string]string{ "name": "foo/bar", }, }, { - RouteName: routeNameBlob, + RouteName: RouteNameBlob, RequestURI: "/v2/foo/bar/blobs/tarsum.dev+foo:abcdef0919234", Vars: map[string]string{ "name": "foo/bar", @@ -75,7 +75,7 @@ func TestRouter(t *testing.T) { }, }, { - RouteName: routeNameBlob, + RouteName: RouteNameBlob, RequestURI: "/v2/foo/bar/blobs/sha256:abcdef0919234", Vars: map[string]string{ "name": "foo/bar", @@ -83,14 +83,14 @@ func TestRouter(t *testing.T) { }, }, { - RouteName: routeNameBlobUpload, + RouteName: RouteNameBlobUpload, RequestURI: "/v2/foo/bar/blobs/uploads/", Vars: map[string]string{ "name": "foo/bar", }, }, { - RouteName: routeNameBlobUploadResume, + RouteName: RouteNameBlobUploadChunk, RequestURI: "/v2/foo/bar/blobs/uploads/uuid", Vars: map[string]string{ "name": "foo/bar", @@ -98,7 +98,7 @@ func TestRouter(t *testing.T) { }, }, { - RouteName: routeNameBlobUploadResume, + RouteName: RouteNameBlobUploadChunk, RequestURI: "/v2/foo/bar/blobs/uploads/D95306FA-FAD3-4E36-8D41-CF1C93EF8286", Vars: map[string]string{ "name": "foo/bar", @@ -106,7 +106,7 @@ func TestRouter(t *testing.T) { }, }, { - RouteName: routeNameBlobUploadResume, + RouteName: RouteNameBlobUploadChunk, RequestURI: "/v2/foo/bar/blobs/uploads/RDk1MzA2RkEtRkFEMy00RTM2LThENDEtQ0YxQzkzRUY4Mjg2IA==", Vars: map[string]string{ "name": "foo/bar", @@ -117,7 +117,7 @@ func TestRouter(t *testing.T) { // Check ambiguity: ensure we can distinguish between tags for // "foo/bar/image/image" and image for "foo/bar/image" with tag // "tags" - RouteName: routeNameImageManifest, + RouteName: RouteNameManifest, RequestURI: "/v2/foo/bar/manifests/manifests/tags", Vars: map[string]string{ "name": "foo/bar/manifests", @@ -127,14 +127,14 @@ func TestRouter(t *testing.T) { { // This case presents an ambiguity between foo/bar with tag="tags" // and list tags for "foo/bar/manifest" - RouteName: routeNameTags, + RouteName: RouteNameTags, RequestURI: "/v2/foo/bar/manifests/tags/list", Vars: map[string]string{ "name": "foo/bar/manifests", }, }, { - RouteName: routeNameBlobUploadResume, + RouteName: RouteNameBlobUploadChunk, RequestURI: "/v2/foo/../../blob/uploads/D95306FA-FAD3-4E36-8D41-CF1C93EF8286", StatusCode: http.StatusNotFound, },