Merge pull request #5427 from ywk253100/180730_redirect

Remove the URL rewrite for docker registry request
This commit is contained in:
Daniel Jiang 2018-07-31 13:34:15 +08:00 committed by GitHub
commit bda0a92ea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 12 deletions

View File

@ -47,7 +47,7 @@ http {
}
location /v2/ {
proxy_pass http://ui/registryproxy/v2/;
proxy_pass http://ui/v2/;
proxy_set_header Host $$http_host;
proxy_set_header X-Real-IP $$remote_addr;
proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;

View File

@ -67,7 +67,7 @@ http {
}
location /v2/ {
proxy_pass http://ui/registryproxy/v2/;
proxy_pass http://ui/v2/;
proxy_set_header Host $$http_host;
proxy_set_header X-Real-IP $$remote_addr;
proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;

View File

@ -63,7 +63,7 @@ func init() {
beego.Router("/reset", &CommonController{}, "post:ResetPassword")
beego.Router("/userExists", &CommonController{}, "post:UserExists")
beego.Router("/sendEmail", &CommonController{}, "get:SendResetEmail")
beego.Router("/registryproxy/*", &RegistryProxy{}, "*:Handle")
beego.Router("/v2/*", &RegistryProxy{}, "*:Handle")
}
func TestMain(m *testing.M) {
@ -175,17 +175,17 @@ func TestAll(t *testing.T) {
beego.BeeApp.Handlers.ServeHTTP(w, r)
assert.Equal(int(400), w.Code, "'/sendEmail' httpStatusCode should be 400")
r, _ = http.NewRequest("GET", "/registryproxy/v2/", nil)
r, _ = http.NewRequest("GET", "/v2/", nil)
w = httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
assert.Equal(int(200), w.Code, "ping v2 should get a 200 response")
r, _ = http.NewRequest("GET", "/registryproxy/v2/noproject/manifests/1.0", nil)
r, _ = http.NewRequest("GET", "/v2/noproject/manifests/1.0", nil)
w = httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
assert.Equal(int(400), w.Code, "GET v2/noproject/manifests/1.0 should get a 400 response")
r, _ = http.NewRequest("GET", "/registryproxy/v2/project/notexist/manifests/1.0", nil)
r, _ = http.NewRequest("GET", "/v2/project/notexist/manifests/1.0", nil)
w = httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
assert.Equal(int(404), w.Code, "GET v2/noproject/manifests/1.0 should get a 404 response")

View File

@ -118,7 +118,6 @@ type urlHandler struct {
func (uh urlHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
log.Debugf("in url handler, path: %s", req.URL.Path)
req.URL.Path = strings.TrimPrefix(req.URL.Path, RegistryProxyPrefix)
flag, repository, reference := MatchPullManifest(req)
if flag {
components := strings.SplitN(repository, "/", 2)
@ -161,7 +160,7 @@ type readonlyHandler struct {
func (rh readonlyHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if config.ReadOnly() {
if req.Method == http.MethodDelete || req.Method == http.MethodPost || req.Method == http.MethodPatch || req.Method == http.MethodPut {
log.Warningf("The request is prohibited in readonly mode, url is: %s", req.URL.Path)
log.Warningf("The request is prohibited in readonly mode, url is: %s", req.URL.Path)
http.Error(rw, marshalError("DENIED", "The system is in read only mode. Any modification is prohibited."), http.StatusForbidden)
return
}

View File

@ -14,9 +14,6 @@ var Proxy *httputil.ReverseProxy
var handlers handlerChain
// RegistryProxyPrefix is the prefix of url on UI.
const RegistryProxyPrefix = "/registryproxy"
type handlerChain struct {
head http.Handler
}

View File

@ -128,7 +128,7 @@ func initRouters() {
beego.Router("/service/notifications/jobs/adminjob/:id([0-9]+)", &admin.Handler{}, "post:HandleAdminJob")
beego.Router("/service/token", &token.Handler{})
beego.Router("/registryproxy/*", &controllers.RegistryProxy{}, "*:Handle")
beego.Router("/v2/*", &controllers.RegistryProxy{}, "*:Handle")
//APIs for chart repository
if config.WithChartMuseum() {