diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2020-05-20 16:33:57 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2020-05-20 16:33:57 +0300 |
commit | f906388f3c6ed4ac1bdb5a10649be55883d477c3 (patch) | |
tree | 6b05a76921d1126ae47fd8262003b6c17f001e8e | |
parent | 5a24d9619e2472d70a9ca4fc8d6d5ec7a9fdbffa (diff) | |
parent | 51d96bd920b4f07e87e84fd79c72a9b3c2f9902e (diff) |
Merge branch 'smh-revert' into 'master'
Revert "Merge branch 'jc-change-to-hooks' into 'master'"
See merge request gitlab-org/gitaly!2196
-rw-r--r-- | cmd/gitaly-hooks/hooks_test.go | 18 | ||||
-rw-r--r-- | config.toml.example | 9 | ||||
-rw-r--r-- | internal/config/config.go | 24 | ||||
-rw-r--r-- | internal/gitlabshell/env.go | 8 | ||||
-rw-r--r-- | internal/gitlabshell/env_test.go | 27 | ||||
-rw-r--r-- | internal/service/hooks/update.go | 2 | ||||
-rw-r--r-- | internal/service/smarthttp/receive_pack_test.go | 4 | ||||
-rw-r--r-- | internal/service/ssh/receive_pack_test.go | 4 |
8 files changed, 43 insertions, 53 deletions
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go index 5df748688..bdca5d353 100644 --- a/cmd/gitaly-hooks/hooks_test.go +++ b/cmd/gitaly-hooks/hooks_test.go @@ -123,10 +123,10 @@ func TestHooksPrePostReceive(t *testing.T) { defer cleanup() if featureSet.IsEnabled("use_gitaly_gitlabshell_config") { - config.Config.Gitlab.URL = ts.URL - config.Config.Gitlab.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") - config.Config.Gitlab.HTTPSettings.User = gitlabUser - config.Config.Gitlab.HTTPSettings.Password = gitlabPassword + config.Config.GitlabShell.GitlabURL = ts.URL + config.Config.GitlabShell.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") + config.Config.GitlabShell.HTTPSettings.User = gitlabUser + config.Config.GitlabShell.HTTPSettings.Password = gitlabPassword } var stderr, stdout bytes.Buffer @@ -218,7 +218,7 @@ func TestHooksUpdate(t *testing.T) { for _, featureSet := range featureSets { t.Run(fmt.Sprintf("enabled features: %v", featureSet), func(t *testing.T) { if featureSet.IsEnabled("use_gitaly_gitlabshell_config") { - config.Config.Hooks.CustomHooksDir = customHooksDir + config.Config.GitlabShell.CustomHooksDir = customHooksDir } testHooksUpdate(t, tempGitlabShellDir, socket, token, testhelper.GlHookValues{ @@ -332,8 +332,8 @@ func TestHooksPostReceiveFailed(t *testing.T) { testhelper.WriteShellSecretFile(t, tempGitlabShellDir, secretToken) config.Config.GitlabShell.Dir = tempGitlabShellDir - config.Config.Gitlab.URL = ts.URL - config.Config.Gitlab.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") + config.Config.GitlabShell.GitlabURL = ts.URL + config.Config.GitlabShell.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") featureSets, err := testhelper.NewFeatureSets([]string{featureflag.HooksRPC}) require.NoError(t, err) @@ -416,7 +416,9 @@ func TestHooksNotAllowed(t *testing.T) { testhelper.WriteShellSecretFile(t, tempGitlabShellDir, "the wrong token") config.Config.GitlabShell.Dir = tempGitlabShellDir - config.Config.Gitlab.URL = ts.URL + + config.Config.GitlabShell.Dir = tempGitlabShellDir + config.Config.GitlabShell.GitlabURL = ts.URL customHookOutputPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, "post-receive") defer cleanup() diff --git a/config.toml.example b/config.toml.example index d89f2da8a..aaab83c21 100644 --- a/config.toml.example +++ b/config.toml.example @@ -86,14 +86,11 @@ dir = "/home/git/gitaly/ruby" [gitlab-shell] # The directory where gitlab-shell is installed dir = "/home/git/gitlab-shell" - -[hooks] -custom_hooks_dir = "/home/git/custom_hooks" - -[gitlab] secret_file = "/home/git/gitlab-shell/.gitlab_shell_secret" +custom_hooks_dir = "/home/git/custom_hooks" gitlab_url = "http://localhost:8080" -[gitlab.http-settings] + +[gitlab-shell.http-settings] # read_timeout = 300 # user = someone # password = somepass diff --git a/internal/config/config.go b/internal/config/config.go index 94005beda..0b31aaf00 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -43,9 +43,7 @@ type Cfg struct { Auth auth.Config `toml:"auth"` TLS TLS `toml:"tls"` Ruby Ruby `toml:"gitaly-ruby"` - Gitlab Gitlab `toml:"gitlab"` GitlabShell GitlabShell `toml:"gitlab-shell"` - Hooks Hooks `toml:"hooks"` Concurrency []Concurrency `toml:"concurrency"` GracefulRestartTimeout time.Duration GracefulRestartTimeoutToml duration `toml:"graceful_restart_timeout"` @@ -60,19 +58,11 @@ type TLS struct { // GitlabShell contains the settings required for executing `gitlab-shell` type GitlabShell struct { - Dir string `toml:"dir" json:"dir"` -} - -// Gitlab contains settings required to connect to the Gitlab api -type Gitlab struct { - URL string `toml:"url" json:"url"` - HTTPSettings HTTPSettings `toml:"http-settings" json:"http_settings"` - SecretFile string `toml:"secret_file" json:"secret_file"` -} - -// Hooks contains the settings required for hooks -type Hooks struct { - CustomHooksDir string `toml:"custom_hooks_dir" json:"custom_hooks_dir"` + CustomHooksDir string `toml:"custom_hooks_dir" json:"custom_hooks_dir"` + Dir string `toml:"dir" json:"dir"` + GitlabURL string `toml:"gitlab_url" json:"gitlab_url"` + HTTPSettings HTTPSettings `toml:"http-settings" json:"http_settings"` + SecretFile string `toml:"secret_file" json:"secret_file"` } type HTTPSettings struct { @@ -174,8 +164,8 @@ func (c *Cfg) setDefaults() { c.GracefulRestartTimeout = 1 * time.Minute } - if c.Gitlab.SecretFile == "" { - c.Gitlab.SecretFile = filepath.Join(c.GitlabShell.Dir, ".gitlab_shell_secret") + if c.GitlabShell.SecretFile == "" { + c.GitlabShell.SecretFile = filepath.Join(c.GitlabShell.Dir, ".gitlab_shell_secret") } if c.GitlabShell.CustomHooksDir == "" { diff --git a/internal/gitlabshell/env.go b/internal/gitlabshell/env.go index 9165932ab..24a1f6296 100644 --- a/internal/gitlabshell/env.go +++ b/internal/gitlabshell/env.go @@ -27,14 +27,14 @@ type Config struct { // EnvFromConfig returns a set of environment variables from a config struct relevant to gitlab shell func EnvFromConfig(cfg config.Cfg) ([]string, error) { gitlabShellConfig := Config{ - CustomHooksDir: cfg.Hooks.CustomHooksDir, - GitlabURL: cfg.Gitlab.URL, - HTTPSettings: cfg.Gitlab.HTTPSettings, + CustomHooksDir: cfg.GitlabShell.CustomHooksDir, + GitlabURL: cfg.GitlabShell.GitlabURL, + HTTPSettings: cfg.GitlabShell.HTTPSettings, LogFormat: cfg.Logging.Format, LogLevel: cfg.Logging.Level, LogPath: cfg.Logging.Dir, RootPath: cfg.GitlabShell.Dir, //GITLAB_SHELL_DIR has been deprecated - SecretFile: cfg.Gitlab.SecretFile, + SecretFile: cfg.GitlabShell.SecretFile, } gitlabShellConfigString, err := json.Marshal(&gitlabShellConfig) diff --git a/internal/gitlabshell/env_test.go b/internal/gitlabshell/env_test.go index 9eac8f076..a5b9249c6 100644 --- a/internal/gitlabshell/env_test.go +++ b/internal/gitlabshell/env_test.go @@ -29,10 +29,11 @@ func TestGitHooksConfig(t *testing.T) { config.Config.Logging.Dir = loggingDir config.Config.Logging.Level = "fatal" config.Config.Logging.Format = "my-custom-format" - config.Config.GitlabShell.Dir = "../../ruby/gitlab-shell" - config.Config.Hooks.CustomHooksDir = "/path/to/custom_hooks" - config.Config.Gitlab = config.Gitlab{ - URL: "http://gitlaburl.com", + + config.Config.GitlabShell = config.GitlabShell{ + CustomHooksDir: "/path/to/custom_hooks", + Dir: "../../ruby/gitlab-shell", + GitlabURL: "http://gitlaburl.com", HTTPSettings: config.HTTPSettings{ ReadTimeout: 100, User: "user_name", @@ -62,19 +63,19 @@ func TestGitHooksConfig(t *testing.T) { require.NoError(t, json.NewDecoder(&stdout).Decode(&rubyConfigMap)) require.Equal(t, config.Config.Logging.Level, rubyConfigMap["log_level"]) require.Equal(t, config.Config.Logging.Format, rubyConfigMap["log_format"]) - require.Equal(t, config.Config.Gitlab.SecretFile, rubyConfigMap["secret_file"]) - require.Equal(t, config.Config.Hooks.CustomHooksDir, rubyConfigMap["custom_hooks_dir"]) - require.Equal(t, config.Config.Gitlab.URL, rubyConfigMap["gitlab_url"]) + require.Equal(t, config.Config.GitlabShell.SecretFile, rubyConfigMap["secret_file"]) + require.Equal(t, config.Config.GitlabShell.CustomHooksDir, rubyConfigMap["custom_hooks_dir"]) + require.Equal(t, config.Config.GitlabShell.GitlabURL, rubyConfigMap["gitlab_url"]) // HTTP Settings httpSettings, ok := rubyConfigMap["http_settings"].(map[string]interface{}) require.True(t, ok) - require.Equal(t, float64(config.Config.Gitlab.HTTPSettings.ReadTimeout), httpSettings["read_timeout"]) - require.Equal(t, config.Config.Gitlab.HTTPSettings.User, httpSettings["user"]) - require.Equal(t, config.Config.Gitlab.HTTPSettings.Password, httpSettings["password"]) - require.Equal(t, config.Config.Gitlab.HTTPSettings.CAFile, httpSettings["ca_file"]) - require.Equal(t, config.Config.Gitlab.HTTPSettings.CAPath, httpSettings["ca_path"]) - require.Equal(t, config.Config.Gitlab.HTTPSettings.SelfSigned, httpSettings["self_signed_cert"]) + require.Equal(t, float64(config.Config.GitlabShell.HTTPSettings.ReadTimeout), httpSettings["read_timeout"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.User, httpSettings["user"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.Password, httpSettings["password"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.CAFile, httpSettings["ca_file"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.CAPath, httpSettings["ca_path"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.SelfSigned, httpSettings["self_signed_cert"]) dir := filepath.Dir(rubyConfigMap["log_file"].(string)) require.Equal(t, config.Config.Logging.Dir, dir) diff --git a/internal/service/hooks/update.go b/internal/service/hooks/update.go index 5741da00c..9d0e2091b 100644 --- a/internal/service/hooks/update.go +++ b/internal/service/hooks/update.go @@ -83,7 +83,7 @@ func (s *server) UpdateHook(in *gitalypb.UpdateHookRequest, stream gitalypb.Hook if err != nil { return err } - executor, err := newCustomHooksExecutor(repoPath, config.Config.Hooks.CustomHooksDir, "update") + executor, err := newCustomHooksExecutor(repoPath, config.Config.GitlabShell.CustomHooksDir, "update") if err != nil { return helper.ErrInternal(err) } diff --git a/internal/service/smarthttp/receive_pack_test.go b/internal/service/smarthttp/receive_pack_test.go index 4abe9b93c..d60672ade 100644 --- a/internal/service/smarthttp/receive_pack_test.go +++ b/internal/service/smarthttp/receive_pack_test.go @@ -403,8 +403,8 @@ func testPostReceivePackToHooks(t *testing.T, callRPC bool) { testhelper.WriteCustomHook(testRepoPath, "pre-receive", []byte(testhelper.CheckNewObjectExists)) - config.Config.Gitlab.URL = ts.URL - config.Config.Gitlab.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") + config.Config.GitlabShell.GitlabURL = ts.URL + config.Config.GitlabShell.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") defer func(override string) { hooks.Override = override diff --git a/internal/service/ssh/receive_pack_test.go b/internal/service/ssh/receive_pack_test.go index cbe2fd2be..07a0016c7 100644 --- a/internal/service/ssh/receive_pack_test.go +++ b/internal/service/ssh/receive_pack_test.go @@ -243,8 +243,8 @@ func TestSSHReceivePackToHooks(t *testing.T) { testhelper.WriteTemporaryGitlabShellConfigFile(t, tempGitlabShellDir, testhelper.GitlabShellConfig{GitlabURL: ts.URL}) testhelper.WriteShellSecretFile(t, tempGitlabShellDir, secretToken) - config.Config.Gitlab.URL = ts.URL - config.Config.Gitlab.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") + config.Config.GitlabShell.GitlabURL = ts.URL + config.Config.GitlabShell.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") testhelper.WriteCustomHook(cloneDetails.RemoteRepoPath, "pre-receive", []byte(testhelper.CheckNewObjectExists)) |