diff options
author | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2017-08-07 15:52:36 +0300 |
---|---|---|
committer | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2017-08-07 15:52:36 +0300 |
commit | ca9c06ab33dc8af4fd32e62f7580956cf8e518a6 (patch) | |
tree | 35951f2e2aed9f96d6053d9f689eeeda13cfb4b4 | |
parent | 6e0e79dde06a494b09984499ed550f2031b03eef (diff) | |
parent | cebb3dba2c9231bd0b57c125226b3191d1a96c64 (diff) |
Merge branch '386-gitlab-shell-path' into 'master'
Make gitlab-shell a dependency of Gitaly
See merge request !267
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | config.toml.example | 4 | ||||
-rw-r--r-- | internal/config/config.go | 51 | ||||
-rw-r--r-- | internal/config/config_test.go | 56 |
4 files changed, 106 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 603925be4..083487970 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Gitaly changelog +UNRELEASED + +- Add GitLab-Shell Path to config + https://gitlab.com/gitlab-org/gitaly/merge_requests/267 + v0.28.0 - Increase gitaly-ruby connection timeout to 20s diff --git a/config.toml.example b/config.toml.example index 7547c61e8..5fe394217 100644 --- a/config.toml.example +++ b/config.toml.example @@ -38,3 +38,7 @@ path = "/home/git/repositories" [gitaly-ruby] # The directory where gitaly-ruby is installed dir = "/home/git/gitaly/ruby" + +[gitlab-shell] +# The directory where gitlab-shell is installed +dir = "/home/git/gitlab-shell" diff --git a/internal/config/config.go b/internal/config/config.go index a7f1ee421..58af344f9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -3,6 +3,7 @@ package config import ( "fmt" "io" + "os" "os/exec" log "github.com/Sirupsen/logrus" @@ -17,15 +18,21 @@ var ( ) type config struct { - SocketPath string `toml:"socket_path" split_words:"true"` - ListenAddr string `toml:"listen_addr" split_words:"true"` - PrometheusListenAddr string `toml:"prometheus_listen_addr" split_words:"true"` - Git Git `toml:"git" envconfig:"git"` - Storages []Storage `toml:"storage" envconfig:"storage"` - Logging Logging `toml:"logging" envconfig:"logging"` - Prometheus Prometheus `toml:"prometheus"` - Auth Auth `toml:"auth"` - Ruby Ruby `toml:"gitaly-ruby"` + SocketPath string `toml:"socket_path" split_words:"true"` + ListenAddr string `toml:"listen_addr" split_words:"true"` + PrometheusListenAddr string `toml:"prometheus_listen_addr" split_words:"true"` + Git Git `toml:"git" envconfig:"git"` + Storages []Storage `toml:"storage" envconfig:"storage"` + Logging Logging `toml:"logging" envconfig:"logging"` + Prometheus Prometheus `toml:"prometheus"` + Auth Auth `toml:"auth"` + Ruby Ruby `toml:"gitaly-ruby"` + GitlabShell GitlabShell `toml:"gitlab-shell"` +} + +// GitlabShell contains the settings required for executing `gitlab-shell` +type GitlabShell struct { + Dir string `toml:"dir"` } // Git contains the settings for the Git executable @@ -72,7 +79,7 @@ func Load(file io.Reader) error { // Validate checks the current Config for sanity. func Validate() error { - for _, err := range []error{validateStorages(), validateToken(), SetGitPath()} { + for _, err := range []error{validateStorages(), validateToken(), SetGitPath(), validateShell()} { if err != nil { return err } @@ -80,6 +87,30 @@ func Validate() error { return nil } +func validateShell() error { + if len(Config.GitlabShell.Dir) == 0 { + log.WithField("dir", Config.GitlabShell.Dir). + Warn("gitlab-shell.dir not set") + return nil + } + + if s, err := os.Stat(Config.GitlabShell.Dir); err != nil { + log.WithField("dir", Config.GitlabShell.Dir). + WithError(err). + Warn("gitlab-shell.dir set but not found") + return err + } else if !s.IsDir() { + log.WithField("dir", Config.GitlabShell.Dir). + Warn("gitlab-shell.dir set but not a directory") + return fmt.Errorf("not a directory: %q", Config.GitlabShell.Dir) + } + + log.WithField("dir", Config.GitlabShell.Dir). + Debug("gitlab-shell.dir set") + + return nil +} + func validateStorages() error { if len(Config.Storages) == 0 { return fmt.Errorf("config: no storage configurations found. Is your gitaly.config correctly configured? https://gitlab.com/gitlab-org/gitaly/issues/397") diff --git a/internal/config/config_test.go b/internal/config/config_test.go index d31fb3e97..4329602f4 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -3,11 +3,14 @@ package config import ( "bytes" "io" + "io/ioutil" "os" "os/exec" + "path" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func configFileReader(content string) io.Reader { @@ -286,3 +289,56 @@ func TestSetGitPath(t *testing.T) { assert.Equal(t, tc.expected, Config.Git.BinPath, tc.desc) } } + +func TestValidateShellPath(t *testing.T) { + defer func(oldShellSettings GitlabShell) { + Config.GitlabShell = oldShellSettings + }(Config.GitlabShell) + + tmpDir, err := ioutil.TempDir("", "gitaly-tests-") + require.NoError(t, err) + tmpFile := path.Join(tmpDir, "my-file") + defer os.RemoveAll(tmpDir) + fp, err := os.Create(tmpFile) + require.NoError(t, err) + require.NoError(t, fp.Close()) + + testCases := []struct { + desc string + path string + shouldErr bool + }{ + { + desc: "When no Shell Path set", + path: "", + shouldErr: false, + }, + { + desc: "When Shell Path set to non-existing path", + path: "/non/existing/path", + shouldErr: true, + }, + { + desc: "When Shell Path set to non-dir path", + path: tmpFile, + shouldErr: true, + }, + { + desc: "When Shell Path set to a valid directory", + path: tmpDir, + shouldErr: false, + }, + } + + for _, tc := range testCases { + t.Log(tc.desc) + Config.GitlabShell.Dir = tc.path + err = validateShell() + if tc.shouldErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + + } +} |