Skip to content

Commit 5f54a8f

Browse files
committed
refactor: make environment setting more generic
This sets the stage for letting other projects benefit from something Dokku-specific
1 parent cc9a4df commit 5f54a8f

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

git-http-backend.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ type Service struct {
2323
}
2424

2525
type Config struct {
26-
ProjectRoot string
27-
GitBinPath string
28-
UploadPack bool
29-
ReceivePack bool
26+
AuthPassEnvVar string
27+
AuthUserEnvVar string
28+
DefaultEnv string
29+
ProjectRoot string
30+
GitBinPath string
31+
UploadPack bool
32+
ReceivePack bool
3033
}
3134

3235
type HandlerReq struct {
@@ -38,10 +41,13 @@ type HandlerReq struct {
3841
}
3942

4043
var config Config = Config{
41-
ProjectRoot: "/tmp",
42-
GitBinPath: "/usr/bin/git",
43-
UploadPack: true,
44-
ReceivePack: true,
44+
AuthPassEnvVar: "",
45+
AuthUserEnvVar: "",
46+
DefaultEnv: "",
47+
ProjectRoot: "/tmp",
48+
GitBinPath: "/usr/bin/git",
49+
UploadPack: true,
50+
ReceivePack: true,
4551
}
4652

4753
var services = map[string]Service{
@@ -63,6 +69,9 @@ var (
6369
)
6470

6571
func init() {
72+
flag.StringVar(&config.AuthPassEnvVar, "auth_pass_env_var", config.AuthPassEnvVar, "set an env var to provide the basic auth pass as")
73+
flag.StringVar(&config.AuthUserEnvVar, "auth_user_env_var", config.AuthUserEnvVar, "set an env var to provide the basic auth user as")
74+
flag.StringVar(&config.DefaultEnv, "default_env", config.DefaultEnv, "set the default env")
6675
flag.StringVar(&config.ProjectRoot, "project_root", config.ProjectRoot, "set project root")
6776
flag.StringVar(&config.GitBinPath, "git_bin_path", config.GitBinPath, "set git bin path")
6877
flag.StringVar(&address, "server_address", address, "set server address")
@@ -119,14 +128,20 @@ func serviceRpc(hr HandlerReq) {
119128
w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-result", rpc))
120129
w.WriteHeader(http.StatusOK)
121130

122-
env := []string{
123-
"SSH_USER=git-http-backend",
131+
env := []string{}
132+
133+
if config.DefaultEnv != "" {
134+
env = append(env, config.DefaultEnv)
124135
}
125136

126-
user, _, authok := r.BasicAuth()
137+
user, password, authok := r.BasicAuth()
127138
if authok {
128-
env = append(env, fmt.Sprintf("NAME=%s", user))
129-
env = append(env, fmt.Sprintf("SSH_NAME=%s", user))
139+
if config.AuthUserEnvVar != "" {
140+
env = append(env, fmt.Sprintf("%s=%s", config.AuthUserEnvVar, user))
141+
}
142+
if config.AuthPassEnvVar != "" {
143+
env = append(env, fmt.Sprintf("%s=%s", config.AuthPassEnvVar, password))
144+
}
130145
}
131146

132147
args := []string{rpc, "--stateless-rpc", dir}

0 commit comments

Comments
 (0)