"net"
"net/http"
"net/http/cgi"
+ "os"
)
// gitHandler is an http.Handler that invokes git-http-backend (or
}
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"},
},
}
"net/http"
"net/http/httptest"
"net/url"
- "os"
"regexp"
check "gopkg.in/check.v1"
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)
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)+`$.*`)
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)
// (*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) {
s.tmpWorkdir = ""
s.Config = nil
+
+ theConfig = defaultConfig()
}
func (s *IntegrationSuite) RunGit(c *check.C, token, gitCmd, repo string, args ...string) error {
// 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()
"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
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
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