Commit d856f300 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

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`.
parent abb55c83
# frozen_string_literal: true
require 'shellwords' require 'shellwords'
require 'pathname' require 'pathname'
...@@ -9,12 +11,13 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -9,12 +11,13 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
class DisallowedCommandError < StandardError; end class DisallowedCommandError < StandardError; end
class InvalidRepositoryPathError < StandardError; end class InvalidRepositoryPathError < StandardError; end
GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-lfs-authenticate).freeze GITALY_COMMAND = {
GITALY_MIGRATED_COMMANDS = {
'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'), 'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'),
'git-upload-archive' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-archive'), 'git-upload-archive' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-archive'),
'git-receive-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-receive-pack') 'git-receive-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-receive-pack')
}.freeze }.freeze
GIT_COMMANDS = GITALY_COMMAND.keys + ['git-lfs-authenticate']
API_COMMANDS = %w(2fa_recovery_codes).freeze API_COMMANDS = %w(2fa_recovery_codes).freeze
GL_PROTOCOL = 'ssh'.freeze GL_PROTOCOL = 'ssh'.freeze
...@@ -136,28 +139,23 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -136,28 +139,23 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
return return
end end
executable = @command # TODO happens only in testing as of right now
args = [] return unless @gitaly
if GITALY_MIGRATED_COMMANDS.key?(executable) && @gitaly # The entire gitaly_request hash should be built in gitlab-ce and passed
executable = GITALY_MIGRATED_COMMANDS[executable] # on as-is. For now we build a fake one on the spot.
gitaly_request = {
gitaly_address = @gitaly['address'] 'repository' => @gitaly['repository'],
'gl_repository' => @gl_repository,
# The entire gitaly_request hash should be built in gitlab-ce and passed 'gl_id' => @gl_id,
# on as-is. For now we build a fake one on the spot. 'gl_username' => @username,
gitaly_request = { 'git_config_options' => @git_config_options,
'repository' => @gitaly['repository'], 'git_protocol' => @git_protocol
'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)] args = [@gitaly['address'], JSON.dump(gitaly_request)]
end
executable = GITALY_COMMAND[@command]
args_string = [File.basename(executable), *args].join(' ') args_string = [File.basename(executable), *args].join(' ')
$logger.info('executing git command', command: args_string, user: log_username) $logger.info('executing git command', command: args_string, user: log_username)
exec_cmd(executable, *args) exec_cmd(executable, *args)
...@@ -182,7 +180,9 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -182,7 +180,9 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
'GL_REPOSITORY' => @gl_repository, 'GL_REPOSITORY' => @gl_repository,
'GL_USERNAME' => @username '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'] env['GITALY_TOKEN'] = @gitaly['token']
end end
......
...@@ -201,14 +201,6 @@ describe GitlabShell do ...@@ -201,14 +201,6 @@ describe GitlabShell do
end end
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 context 'gitaly-upload-pack' do
let(:ssh_cmd) { "git-upload-pack gitlab-ci.git" } let(:ssh_cmd) { "git-upload-pack gitlab-ci.git" }
before do before do
...@@ -309,14 +301,6 @@ describe GitlabShell do ...@@ -309,14 +301,6 @@ describe GitlabShell do
end end
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 context 'gitaly-upload-archive' do
before do before do
allow(api).to receive(:check_access).and_return(gitaly_check_access) allow(api).to receive(:check_access).and_return(gitaly_check_access)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment