10234: 10263: Use a GitoliteHome configuration entry instead of passing through gitol...
authorTom Clegg <tom@curoverse.com>
Thu, 13 Oct 2016 15:02:18 +0000 (11:02 -0400)
committerTom Clegg <tom@curoverse.com>
Thu, 13 Oct 2016 17:36:54 +0000 (13:36 -0400)
services/arv-git-httpd/git_handler.go
services/arv-git-httpd/git_handler_test.go
services/arv-git-httpd/gitolite_test.go
services/arv-git-httpd/integration_test.go
services/arv-git-httpd/main.go
services/arv-git-httpd/usage.go
tools/arvbox/lib/arvbox/docker/service/arv-git-httpd/run-service

index f0b98fab72382dfa02c2b12a144e2a6b9f5190c4..f8e38e9516902c679b0ebd54327e011579ac3e76 100644 (file)
@@ -5,6 +5,7 @@ import (
        "net"
        "net/http"
        "net/http/cgi"
+       "os"
 )
 
 // gitHandler is an http.Handler that invokes git-http-backend (or
@@ -16,21 +17,24 @@ type gitHandler struct {
 }
 
 func newGitHandler() http.Handler {
+       var env []string
+       path := os.Getenv("PATH")
+       if theConfig.GitoliteHome != "" {
+               env = append(env,
+                       "GITOLITE_HTTP_HOME="+theConfig.GitoliteHome,
+                       "GL_BYPASS_ACCESS_CHECKS=1")
+               path = path + ":" + theConfig.GitoliteHome + "/bin"
+       }
+       env = append(env,
+               "GIT_PROJECT_ROOT="+theConfig.RepoRoot,
+               "GIT_HTTP_EXPORT_ALL=",
+               "SERVER_ADDR="+theConfig.Listen,
+               "PATH="+path)
        return &gitHandler{
                Handler: cgi.Handler{
                        Path: theConfig.GitCommand,
                        Dir:  theConfig.RepoRoot,
-                       Env: []string{
-                               "GIT_PROJECT_ROOT=" + theConfig.RepoRoot,
-                               "GIT_HTTP_EXPORT_ALL=",
-                               "SERVER_ADDR=" + theConfig.Listen,
-                       },
-                       InheritEnv: []string{
-                               "PATH",
-                               // Needed if GitCommand is gitolite-shell:
-                               "GITOLITE_HTTP_HOME",
-                               "GL_BYPASS_ACCESS_CHECKS",
-                       },
+                       Env:  env,
                        Args: []string{"http-backend"},
                },
        }
index 964810d63655ff84d34ab916abebfb1c95e12cac..6b08eeecdc303a246cba91873fd5c44a4ddddb4a 100644 (file)
@@ -4,7 +4,6 @@ import (
        "net/http"
        "net/http/httptest"
        "net/url"
-       "os"
        "regexp"
 
        check "gopkg.in/check.v1"
@@ -17,6 +16,7 @@ type GitHandlerSuite struct{}
 func (s *GitHandlerSuite) TestEnvVars(c *check.C) {
        theConfig = defaultConfig()
        theConfig.RepoRoot = "/"
+       theConfig.GitoliteHome = "/test/ghh"
 
        u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
        c.Check(err, check.Equals, nil)
@@ -29,15 +29,14 @@ func (s *GitHandlerSuite) TestEnvVars(c *check.C) {
        h := newGitHandler()
        h.(*gitHandler).Path = "/bin/sh"
        h.(*gitHandler).Args = []string{"-c", "printf 'Content-Type: text/plain\r\n\r\n'; env"}
-       os.Setenv("GITOLITE_HTTP_HOME", "/test/ghh")
-       os.Setenv("GL_BYPASS_ACCESS_CHECKS", "yesplease")
 
        h.ServeHTTP(resp, req)
 
        c.Check(resp.Code, check.Equals, http.StatusOK)
        body := resp.Body.String()
+       c.Check(body, check.Matches, `(?ms).*^PATH=.*:/test/ghh/bin$.*`)
        c.Check(body, check.Matches, `(?ms).*^GITOLITE_HTTP_HOME=/test/ghh$.*`)
-       c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=yesplease$.*`)
+       c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=1$.*`)
        c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`)
        c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`)
        c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta(theConfig.Listen)+`$.*`)
index 74c2b8cf4d91a8ac3da2835b12e90a35e6dd0380..38ff2309c1d2a3a57def17ac588276dab204e265 100644 (file)
@@ -48,9 +48,10 @@ func (s *GitoliteSuite) SetUpTest(c *check.C) {
                        APIHost:  arvadostest.APIHost(),
                        Insecure: true,
                },
-               Listen:     ":0",
-               GitCommand: "/usr/share/gitolite3/gitolite-shell",
-               RepoRoot:   s.tmpRepoRoot,
+               Listen:       ":0",
+               GitCommand:   "/usr/share/gitolite3/gitolite-shell",
+               GitoliteHome: s.gitoliteHome,
+               RepoRoot:     s.tmpRepoRoot,
        }
        s.IntegrationSuite.SetUpTest(c)
 
@@ -58,9 +59,6 @@ func (s *GitoliteSuite) SetUpTest(c *check.C) {
        // (*IntegrationTest)SetUpTest() -- see 2.2.4 at
        // http://gitolite.com/gitolite/gitolite.html
        runGitolite("gitolite", "setup")
-
-       os.Setenv("GITOLITE_HTTP_HOME", s.gitoliteHome)
-       os.Setenv("GL_BYPASS_ACCESS_CHECKS", "1")
 }
 
 func (s *GitoliteSuite) TearDownTest(c *check.C) {
index 5e55eca754838d97d2aaa8888482c686306a42cf..1d252599cdf3078b9924318980d91e031feb687d 100644 (file)
@@ -112,6 +112,8 @@ func (s *IntegrationSuite) TearDownTest(c *check.C) {
        s.tmpWorkdir = ""
 
        s.Config = nil
+
+       theConfig = defaultConfig()
 }
 
 func (s *IntegrationSuite) RunGit(c *check.C, token, gitCmd, repo string, args ...string) error {
index dacfec539e353084ca753677dafb6f4f80a923ca..3bd7b3a8aa93c5871ff18773188c1336033d2599 100644 (file)
@@ -14,10 +14,11 @@ import (
 
 // Server configuration
 type Config struct {
-       Client     arvados.Client
-       Listen     string
-       GitCommand string
-       RepoRoot   string
+       Client       arvados.Client
+       Listen       string
+       GitCommand   string
+       RepoRoot     string
+       GitoliteHome string
 }
 
 var theConfig = defaultConfig()
@@ -39,6 +40,8 @@ func main() {
                "Path to git or gitolite-shell executable. Each authenticated request will execute this program with a single argument, \"http-backend\"."+deprecated)
        flag.StringVar(&theConfig.RepoRoot, "repo-root", theConfig.RepoRoot,
                "Path to git repositories."+deprecated)
+       flag.StringVar(&theConfig.GitoliteHome, "gitolite-home", theConfig.GitoliteHome,
+               "Value for GITOLITE_HTTP_HOME environment variable. If not empty, GL_BYPASS_ACCESS_CHECKS=1 will also be set."+deprecated)
 
        cfgPath := flag.String("config", defaultCfgPath, "Configuration file `path`.")
        flag.Usage = usage
index e35593688fff8b705a3b3477eccedf42f205d69d..4eba36a908fb13fa6e307a5ff25a9a18b181f337 100644 (file)
@@ -51,6 +51,14 @@ GitCommand:
     request will execute this program with the single argument
     "http-backend".
 
+GitoliteHome:
+
+    Path to Gitolite's home directory. If a non-empty path is given,
+    the CGI environment will be set up to support the use of
+    gitolite-shell as a GitCommand: for example, if GitoliteHome is
+    "/gh", then the CGI environment will have GITOLITE_HTTP_HOME=/gh,
+    PATH=$PATH:/gh/bin, and GL_BYPASS_ACCESS_CHECKS=1.
+
 Listen:
 
     Local port to listen on. Can be "address:port" or ":port", where
index 518fe33d049a753cd9cece8b416c46dc4045e483..b6caa14ccce73f0026084427a30d579a1c363211 100755 (executable)
@@ -20,12 +20,11 @@ fi
 
 export ARVADOS_API_HOST=$localip:${services[api]}
 export ARVADOS_API_HOST_INSECURE=1
-export GITOLITE_HTTP_HOME=/var/lib/arvados/git
-export GL_BYPASS_ACCESS_CHECKS=1
 export PATH="$PATH:/var/lib/arvados/git/bin"
 cd ~git
 
 exec /usr/local/bin/arv-git-httpd \
-     -address=:${services[arv-git-httpd]} \
-     -git-command=/usr/share/gitolite3/gitolite-shell \
-     -repo-root=/var/lib/arvados/git/repositories
+    -address=:${services[arv-git-httpd]} \
+    -git-command=/usr/share/gitolite3/gitolite-shell \
+    -gitolite-home=/var/lib/arvados/git \
+    -repo-root=/var/lib/arvados/git/repositories