[ARVADOS] created: 949e7250b7f575d81c2da1c74f15885b6cf1628e

git at public.curoverse.com git at public.curoverse.com
Wed Apr 1 16:11:53 EDT 2015


        at  949e7250b7f575d81c2da1c74f15885b6cf1628e (commit)


commit 949e7250b7f575d81c2da1c74f15885b6cf1628e
Author: Tom Clegg <tom at curoverse.com>
Date:   Wed Apr 1 16:12:35 2015 -0400

    5416: Prefer repos stored locally by uuid, fall back to name. Update tests to suit 4523 fixtures.

diff --git a/services/arv-git-httpd/auth_handler.go b/services/arv-git-httpd/auth_handler.go
index f91ed3f..b2e91de 100644
--- a/services/arv-git-httpd/auth_handler.go
+++ b/services/arv-git-httpd/auth_handler.go
@@ -75,32 +75,6 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 	repoName = pathParts[0]
 	repoName = strings.TrimRight(repoName, "/")
 
-	// Regardless of whether the client asked for "/foo.git" or
-	// "/foo/.git", we choose whichever variant exists in our repo
-	// root. If neither exists, we won't even bother checking
-	// authentication.
-	rewrittenPath := ""
-	tryDirs := []string{
-		"/" + repoName + ".git",
-		"/" + repoName + "/.git",
-	}
-	for _, dir := range tryDirs {
-		if fileInfo, err := os.Stat(theConfig.Root + dir); err != nil {
-			if !os.IsNotExist(err) {
-				statusCode, statusText = http.StatusInternalServerError, err.Error()
-				return
-			}
-		} else if fileInfo.IsDir() {
-			rewrittenPath = dir + "/" + pathParts[1]
-			break
-		}
-	}
-	if rewrittenPath == "" {
-		statusCode, statusText = http.StatusNotFound, "not found"
-		return
-	}
-	r.URL.Path = rewrittenPath
-
 	arv, ok := connectionPool.Get().(*arvadosclient.ArvadosClient)
 	if !ok || arv == nil {
 		statusCode, statusText = http.StatusInternalServerError, "connection pool failed"
@@ -108,7 +82,8 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 	}
 	defer connectionPool.Put(arv)
 
-	// Ask API server whether the repository is readable using this token (by trying to read it!)
+	// Ask API server whether the repository is readable using
+	// this token (by trying to read it!)
 	arv.ApiToken = password
 	reposFound := arvadosclient.Dict{}
 	if err := arv.List("repositories", arvadosclient.Dict{
@@ -127,12 +102,14 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		statusCode, statusText = http.StatusInternalServerError, "name collision"
 		return
 	}
+
+	repoUUID := reposFound["items"].([]interface{})[0].(map[string]interface{})["uuid"].(string)
+
 	isWrite := strings.HasSuffix(r.URL.Path, "/git-receive-pack")
 	if !isWrite {
 		statusText = "read"
 	} else {
-		uuid := reposFound["items"].([]interface{})[0].(map[string]interface{})["uuid"].(string)
-		err := arv.Update("repositories", uuid, arvadosclient.Dict{
+		err := arv.Update("repositories", repoUUID, arvadosclient.Dict{
 			"repository": arvadosclient.Dict{
 				"modified_at": time.Now().String(),
 			},
@@ -143,6 +120,40 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		}
 		statusText = "write"
 	}
+
+	// Regardless of whether the client asked for "/foo.git" or
+	// "/foo/.git", we choose whichever variant exists in our repo
+	// root, and we try {uuid}.git and {uuid}/.git first. If none
+	// of these exist, we 404 even though the API told us the repo
+	// _should_ exist (presumably this means the repo was just
+	// created, and gitolite sync hasn't run yet).
+	rewrittenPath := ""
+	tryDirs := []string{
+		"/" + repoUUID + ".git",
+		"/" + repoUUID + "/.git",
+		"/" + repoName + ".git",
+		"/" + repoName + "/.git",
+	}
+	for _, dir := range tryDirs {
+		log.Println("Trying", theConfig.Root + dir)
+		if fileInfo, err := os.Stat(theConfig.Root + dir); err != nil {
+			if !os.IsNotExist(err) {
+				statusCode, statusText = http.StatusInternalServerError, err.Error()
+				return
+			}
+		} else if fileInfo.IsDir() {
+			rewrittenPath = dir + "/" + pathParts[1]
+			break
+		}
+	}
+	if rewrittenPath == "" {
+		// We say "content not found" to disambiguate from the
+		// earlier "API says that repo does not exist" error.
+		statusCode, statusText = http.StatusNotFound, "content not found"
+		return
+	}
+	r.URL.Path = rewrittenPath
+
 	handlerCopy := *h.handler
 	handlerCopy.Env = append(handlerCopy.Env, "REMOTE_USER="+r.RemoteAddr) // Should be username
 	handlerCopy.ServeHTTP(&w, r)
diff --git a/services/arv-git-httpd/server_test.go b/services/arv-git-httpd/server_test.go
index 751e7e4..5796445 100644
--- a/services/arv-git-httpd/server_test.go
+++ b/services/arv-git-httpd/server_test.go
@@ -25,7 +25,7 @@ func (s *IntegrationSuite) TestPathVariants(c *check.C) {
 	s.makeArvadosRepo(c)
 	// Spectator token
 	os.Setenv("ARVADOS_API_TOKEN", "zw2f4gwx8hw8cjre7yp6v1zylhrhn3m5gvjq73rtpwhmknrybu")
-	for _, repo := range []string{"foo.git", "foo/.git", "arvados.git", "arvados/.git"} {
+	for _, repo := range []string{"active/foo.git", "active/foo/.git", "arvados.git", "arvados/.git"} {
 		err := s.runGit(c, "fetch", repo)
 		c.Assert(err, check.Equals, nil)
 	}
@@ -34,22 +34,22 @@ func (s *IntegrationSuite) TestPathVariants(c *check.C) {
 func (s *IntegrationSuite) TestReadonly(c *check.C) {
 	// Spectator token
 	os.Setenv("ARVADOS_API_TOKEN", "zw2f4gwx8hw8cjre7yp6v1zylhrhn3m5gvjq73rtpwhmknrybu")
-	err := s.runGit(c, "fetch", "foo.git")
+	err := s.runGit(c, "fetch", "active/foo.git")
 	c.Assert(err, check.Equals, nil)
-	err = s.runGit(c, "push", "foo.git", "master:newbranchfail")
+	err = s.runGit(c, "push", "active/foo.git", "master:newbranchfail")
 	c.Assert(err, check.ErrorMatches, `.*HTTP code = 403.*`)
-	_, err = os.Stat(s.tmpRepoRoot + "/.git/refs/heads/newbranchfail")
+	_, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666/.git/refs/heads/newbranchfail")
 	c.Assert(err, check.FitsTypeOf, &os.PathError{})
 }
 
 func (s *IntegrationSuite) TestReadwrite(c *check.C) {
 	// Active user token
 	os.Setenv("ARVADOS_API_TOKEN", "3kg6k6lzmp9kj5cpkcoxie963cmvjahbt2fod9zru30k1jqdmi")
-	err := s.runGit(c, "fetch", "foo.git")
+	err := s.runGit(c, "fetch", "active/foo.git")
 	c.Assert(err, check.Equals, nil)
-	err = s.runGit(c, "push", "foo.git", "master:newbranch")
+	err = s.runGit(c, "push", "active/foo.git", "master:newbranch")
 	c.Assert(err, check.Equals, nil)
-	_, err = os.Stat(s.tmpRepoRoot + "/foo/.git/refs/heads/newbranch")
+	_, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666/.git/refs/heads/newbranch")
 	c.Assert(err, check.Equals, nil)
 }
 
@@ -63,7 +63,7 @@ func (s *IntegrationSuite) TestNonexistent(c *check.C) {
 func (s *IntegrationSuite) TestNoPermission(c *check.C) {
 	// Anonymous token
 	os.Setenv("ARVADOS_API_TOKEN", "4kg6k6lzmp9kj4cpkcoxie964cmvjahbt4fod9zru44k4jqdmi")
-	for _, repo := range []string{"foo.git", "foo/.git"} {
+	for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
 		err := s.runGit(c, "fetch", repo)
 		c.Assert(err, check.ErrorMatches, `.* not found.*`)
 	}
@@ -81,9 +81,9 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
 	c.Assert(err, check.Equals, nil)
 	s.tmpWorkdir, err = ioutil.TempDir("", "arv-git-httpd")
 	c.Assert(err, check.Equals, nil)
-	_, err = exec.Command("git", "init", s.tmpRepoRoot+"/foo").Output()
+	_, err = exec.Command("git", "init", s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666").Output()
 	c.Assert(err, check.Equals, nil)
-	_, err = exec.Command("sh", "-c", "cd "+s.tmpRepoRoot+"/foo && echo test >test && git add test && git commit -am 'foo: test'").CombinedOutput()
+	_, err = exec.Command("sh", "-c", "cd "+s.tmpRepoRoot+"/zzzzz-s0uqq-382brsig8rp3666 && echo test >test && git add test && git commit -am 'foo: test'").CombinedOutput()
 	c.Assert(err, check.Equals, nil)
 	_, err = exec.Command("git", "init", s.tmpWorkdir).Output()
 	c.Assert(err, check.Equals, nil)
@@ -105,7 +105,7 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
 	_, err = exec.Command("git", "config",
 		"--file", s.tmpWorkdir+"/.git/config",
 		"credential.http://"+s.testServer.Addr+"/.helper",
-		"!foo(){ echo password=$ARVADOS_API_TOKEN; };foo").Output()
+		"!cred(){ echo password=$ARVADOS_API_TOKEN; };cred").Output()
 	c.Assert(err, check.Equals, nil)
 	_, err = exec.Command("git", "config",
 		"--file", s.tmpWorkdir+"/.git/config",
@@ -157,9 +157,9 @@ func (s *IntegrationSuite) runGit(c *check.C, gitCmd, repo string, args ...strin
 
 // Make a bare arvados repo at {tmpRepoRoot}/arvados.git
 func (s *IntegrationSuite) makeArvadosRepo(c *check.C) {
-	_, err := exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/arvados.git").Output()
+	_, err := exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git").Output()
 	c.Assert(err, check.Equals, nil)
-	_, err = exec.Command("git", "--git-dir", s.tmpRepoRoot+"/arvados.git", "fetch", "../../.git", "master:master").Output()
+	_, err = exec.Command("git", "--git-dir", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git", "fetch", "../../.git", "master:master").Output()
 	c.Assert(err, check.Equals, nil)
 }
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list