Porting registry to use urls package
This simply moves the registry app to be using the urls package and its exported route names. This supports locking down exported route definitions for use in client packages.
This commit is contained in:
parent
da19114d1a
commit
5b13e95511
15
app.go
15
app.go
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/docker/docker-registry/api/urls"
|
||||||
"github.com/docker/docker-registry/storagedriver"
|
"github.com/docker/docker-registry/storagedriver"
|
||||||
"github.com/docker/docker-registry/storagedriver/factory"
|
"github.com/docker/docker-registry/storagedriver/factory"
|
||||||
|
|
||||||
@ -35,18 +36,18 @@ type App struct {
|
|||||||
func NewApp(configuration configuration.Configuration) *App {
|
func NewApp(configuration configuration.Configuration) *App {
|
||||||
app := &App{
|
app := &App{
|
||||||
Config: configuration,
|
Config: configuration,
|
||||||
router: v2APIRouter(),
|
router: urls.Router(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the handler dispatchers.
|
// Register the handler dispatchers.
|
||||||
app.register(routeNameBase, func(ctx *Context, r *http.Request) http.Handler {
|
app.register(urls.RouteNameBase, func(ctx *Context, r *http.Request) http.Handler {
|
||||||
return http.HandlerFunc(apiBase)
|
return http.HandlerFunc(apiBase)
|
||||||
})
|
})
|
||||||
app.register(routeNameImageManifest, imageManifestDispatcher)
|
app.register(urls.RouteNameManifest, imageManifestDispatcher)
|
||||||
app.register(routeNameTags, tagsDispatcher)
|
app.register(urls.RouteNameTags, tagsDispatcher)
|
||||||
app.register(routeNameBlob, layerDispatcher)
|
app.register(urls.RouteNameBlob, layerDispatcher)
|
||||||
app.register(routeNameBlobUpload, layerUploadDispatcher)
|
app.register(urls.RouteNameBlobUpload, layerUploadDispatcher)
|
||||||
app.register(routeNameBlobUploadResume, layerUploadDispatcher)
|
app.register(urls.RouteNameBlobUploadChunk, layerUploadDispatcher)
|
||||||
|
|
||||||
driver, err := factory.Create(configuration.Storage.Type(), configuration.Storage.Parameters())
|
driver, err := factory.Create(configuration.Storage.Type(), configuration.Storage.Parameters())
|
||||||
|
|
||||||
|
15
app_test.go
15
app_test.go
@ -6,6 +6,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker-registry/api/urls"
|
||||||
"github.com/docker/docker-registry/configuration"
|
"github.com/docker/docker-registry/configuration"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,10 +17,10 @@ import (
|
|||||||
func TestAppDispatcher(t *testing.T) {
|
func TestAppDispatcher(t *testing.T) {
|
||||||
app := &App{
|
app := &App{
|
||||||
Config: configuration.Configuration{},
|
Config: configuration.Configuration{},
|
||||||
router: v2APIRouter(),
|
router: urls.Router(),
|
||||||
}
|
}
|
||||||
server := httptest.NewServer(app)
|
server := httptest.NewServer(app)
|
||||||
router := v2APIRouter()
|
router := urls.Router()
|
||||||
|
|
||||||
serverURL, err := url.Parse(server.URL)
|
serverURL, err := url.Parse(server.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -71,33 +72,33 @@ func TestAppDispatcher(t *testing.T) {
|
|||||||
vars []string
|
vars []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
endpoint: routeNameImageManifest,
|
endpoint: urls.RouteNameManifest,
|
||||||
vars: []string{
|
vars: []string{
|
||||||
"name", "foo/bar",
|
"name", "foo/bar",
|
||||||
"tag", "sometag",
|
"tag", "sometag",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
endpoint: routeNameTags,
|
endpoint: urls.RouteNameTags,
|
||||||
vars: []string{
|
vars: []string{
|
||||||
"name", "foo/bar",
|
"name", "foo/bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
endpoint: routeNameBlob,
|
endpoint: urls.RouteNameBlob,
|
||||||
vars: []string{
|
vars: []string{
|
||||||
"name", "foo/bar",
|
"name", "foo/bar",
|
||||||
"digest", "tarsum.v1+bogus:abcdef0123456789",
|
"digest", "tarsum.v1+bogus:abcdef0123456789",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
endpoint: routeNameBlobUpload,
|
endpoint: urls.RouteNameBlobUpload,
|
||||||
vars: []string{
|
vars: []string{
|
||||||
"name", "foo/bar",
|
"name", "foo/bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
endpoint: routeNameBlobUploadResume,
|
endpoint: urls.RouteNameBlobUploadChunk,
|
||||||
vars: []string{
|
vars: []string{
|
||||||
"name", "foo/bar",
|
"name", "foo/bar",
|
||||||
"uuid", "theuuid",
|
"uuid", "theuuid",
|
||||||
|
15
urls.go
15
urls.go
@ -4,6 +4,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/docker/docker-registry/api/urls"
|
||||||
"github.com/docker/docker-registry/digest"
|
"github.com/docker/docker-registry/digest"
|
||||||
"github.com/docker/docker-registry/storage"
|
"github.com/docker/docker-registry/storage"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@ -17,7 +18,7 @@ type urlBuilder struct {
|
|||||||
func newURLBuilder(root *url.URL) *urlBuilder {
|
func newURLBuilder(root *url.URL) *urlBuilder {
|
||||||
return &urlBuilder{
|
return &urlBuilder{
|
||||||
url: root,
|
url: root,
|
||||||
router: v2APIRouter(),
|
router: urls.Router(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ func newURLBuilderFromString(root string) (*urlBuilder, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ub *urlBuilder) buildBaseURL() (string, error) {
|
func (ub *urlBuilder) buildBaseURL() (string, error) {
|
||||||
route := clonedRoute(ub.router, routeNameBase)
|
route := clonedRoute(ub.router, urls.RouteNameBase)
|
||||||
|
|
||||||
baseURL, err := route.
|
baseURL, err := route.
|
||||||
Schemes(ub.url.Scheme).
|
Schemes(ub.url.Scheme).
|
||||||
@ -54,7 +55,7 @@ func (ub *urlBuilder) buildBaseURL() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ub *urlBuilder) buildTagsURL(name string) (string, error) {
|
func (ub *urlBuilder) buildTagsURL(name string) (string, error) {
|
||||||
route := clonedRoute(ub.router, routeNameTags)
|
route := clonedRoute(ub.router, urls.RouteNameTags)
|
||||||
|
|
||||||
tagsURL, err := route.
|
tagsURL, err := route.
|
||||||
Schemes(ub.url.Scheme).
|
Schemes(ub.url.Scheme).
|
||||||
@ -72,7 +73,7 @@ func (ub *urlBuilder) forManifest(m *storage.Manifest) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ub *urlBuilder) buildManifestURL(name, tag string) (string, error) {
|
func (ub *urlBuilder) buildManifestURL(name, tag string) (string, error) {
|
||||||
route := clonedRoute(ub.router, routeNameImageManifest)
|
route := clonedRoute(ub.router, urls.RouteNameManifest)
|
||||||
|
|
||||||
manifestURL, err := route.
|
manifestURL, err := route.
|
||||||
Schemes(ub.url.Scheme).
|
Schemes(ub.url.Scheme).
|
||||||
@ -90,7 +91,7 @@ func (ub *urlBuilder) forLayer(l storage.Layer) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ub *urlBuilder) buildLayerURL(name string, dgst digest.Digest) (string, error) {
|
func (ub *urlBuilder) buildLayerURL(name string, dgst digest.Digest) (string, error) {
|
||||||
route := clonedRoute(ub.router, routeNameBlob)
|
route := clonedRoute(ub.router, urls.RouteNameBlob)
|
||||||
|
|
||||||
layerURL, err := route.
|
layerURL, err := route.
|
||||||
Schemes(ub.url.Scheme).
|
Schemes(ub.url.Scheme).
|
||||||
@ -104,7 +105,7 @@ func (ub *urlBuilder) buildLayerURL(name string, dgst digest.Digest) (string, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ub *urlBuilder) buildLayerUploadURL(name string) (string, error) {
|
func (ub *urlBuilder) buildLayerUploadURL(name string) (string, error) {
|
||||||
route := clonedRoute(ub.router, routeNameBlobUpload)
|
route := clonedRoute(ub.router, urls.RouteNameBlobUpload)
|
||||||
|
|
||||||
uploadURL, err := route.
|
uploadURL, err := route.
|
||||||
Schemes(ub.url.Scheme).
|
Schemes(ub.url.Scheme).
|
||||||
@ -122,7 +123,7 @@ func (ub *urlBuilder) forLayerUpload(layerUpload storage.LayerUpload) (string, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ub *urlBuilder) buildLayerUploadResumeURL(name, uuid string, values ...url.Values) (string, error) {
|
func (ub *urlBuilder) buildLayerUploadResumeURL(name, uuid string, values ...url.Values) (string, error) {
|
||||||
route := clonedRoute(ub.router, routeNameBlobUploadResume)
|
route := clonedRoute(ub.router, urls.RouteNameBlobUploadChunk)
|
||||||
|
|
||||||
uploadURL, err := route.
|
uploadURL, err := route.
|
||||||
Schemes(ub.url.Scheme).
|
Schemes(ub.url.Scheme).
|
||||||
|
Loading…
Reference in New Issue
Block a user