summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2018-08-16 14:23:54 +0200
committerZeger-Jan van de Weg <git@zjvandeweg.nl>2018-08-20 10:10:52 +0200
commitd856f300a99bc9786e717243378fd9c088d25db0 (patch)
tree6c5ac002190186e2dcd8a6f5efe4178e8963f465
parentabb55c839ceedeb8f32f9af4ad791d349ab03f8c (diff)
downloadgitlab-shell-d856f300a99bc9786e717243378fd9c088d25db0.tar.gz
Remove non Gitaly code paths
All shell access goes through Gitaly, so dead code paths exist to support the legacy way too. This change mostly removes the dead code from `#process_cmd`.
-rw-r--r--lib/gitlab_shell.rb46
-rw-r--r--spec/gitlab_shell_spec.rb16
2 files changed, 23 insertions, 39 deletions
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index 4cabd37..286a3d1 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'shellwords'
require 'pathname'
@@ -9,12 +11,13 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
class DisallowedCommandError < StandardError; end
class InvalidRepositoryPathError < StandardError; end
- GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-lfs-authenticate).freeze
- GITALY_MIGRATED_COMMANDS = {
+ GITALY_COMMAND = {
'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'),
'git-upload-archive' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-archive'),
'git-receive-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-receive-pack')
}.freeze
+
+ GIT_COMMANDS = GITALY_COMMAND.keys + ['git-lfs-authenticate']
API_COMMANDS = %w(2fa_recovery_codes).freeze
GL_PROTOCOL = 'ssh'.freeze
@@ -136,28 +139,23 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
return
end
- executable = @command
- args = []
-
- if GITALY_MIGRATED_COMMANDS.key?(executable) && @gitaly
- executable = GITALY_MIGRATED_COMMANDS[executable]
-
- gitaly_address = @gitaly['address']
-
- # The entire gitaly_request hash should be built in gitlab-ce and passed
- # on as-is. For now we build a fake one on the spot.
- gitaly_request = {
- 'repository' => @gitaly['repository'],
- 'gl_repository' => @gl_repository,
- 'gl_id' => @gl_id,
- 'gl_username' => @username,
- 'git_config_options' => @git_config_options,
- 'git_protocol' => @git_protocol
- }
+ # TODO happens only in testing as of right now
+ return unless @gitaly
+
+ # The entire gitaly_request hash should be built in gitlab-ce and passed
+ # on as-is. For now we build a fake one on the spot.
+ gitaly_request = {
+ 'repository' => @gitaly['repository'],
+ 'gl_repository' => @gl_repository,
+ 'gl_id' => @gl_id,
+ 'gl_username' => @username,
+ 'git_config_options' => @git_config_options,
+ 'git_protocol' => @git_protocol
+ }
- args = [gitaly_address, JSON.dump(gitaly_request)]
- end
+ args = [@gitaly['address'], JSON.dump(gitaly_request)]
+ executable = GITALY_COMMAND[@command]
args_string = [File.basename(executable), *args].join(' ')
$logger.info('executing git command', command: args_string, user: log_username)
exec_cmd(executable, *args)
@@ -182,7 +180,9 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
'GL_REPOSITORY' => @gl_repository,
'GL_USERNAME' => @username
}
- if @gitaly && @gitaly.include?('token')
+
+ # @gitaly is a thing, unless another code path exists that doesn't go through process_cmd
+ if @gitaly&.include?('token')
env['GITALY_TOKEN'] = @gitaly['token']
end
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index 96c4878..1841e1e 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -201,14 +201,6 @@ describe GitlabShell do
end
end
- context 'git-upload-pack' do
- it_behaves_like 'upload-pack', 'git-upload-pack'
- end
-
- context 'git upload-pack' do
- it_behaves_like 'upload-pack', 'git upload-pack'
- end
-
context 'gitaly-upload-pack' do
let(:ssh_cmd) { "git-upload-pack gitlab-ci.git" }
before do
@@ -309,14 +301,6 @@ describe GitlabShell do
end
end
- context 'git-upload-archive' do
- it_behaves_like 'upload-archive', 'git-upload-archive'
- end
-
- context 'git upload-archive' do
- it_behaves_like 'upload-archive', 'git upload-archive'
- end
-
context 'gitaly-upload-archive' do
before do
allow(api).to receive(:check_access).and_return(gitaly_check_access)