From 0a1c8bb37cbfe550e7c29b8f30c607cf985466df Mon Sep 17 00:00:00 2001 From: Ahmad Sherif Date: Mon, 26 Dec 2016 19:15:40 +0200 Subject: [PATCH] Pass Gitaly resource path to gitlab-workhorse if Gitaly is enabled --- .../feature-gitaly-feature-flag.yml | 4 ++++ config/initializers/1_settings.rb | 6 +++++ lib/gitlab/workhorse.rb | 9 +++++++- spec/lib/gitlab/workhorse_spec.rb | 23 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/feature-gitaly-feature-flag.yml diff --git a/changelogs/unreleased/feature-gitaly-feature-flag.yml b/changelogs/unreleased/feature-gitaly-feature-flag.yml new file mode 100644 index 00000000000..1fa566aeb10 --- /dev/null +++ b/changelogs/unreleased/feature-gitaly-feature-flag.yml @@ -0,0 +1,4 @@ +--- +title: Pass Gitaly resource path to gitlab-workhorse if Gitaly is enabled +merge_request: 8440 +author: diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index ee97b4e42b9..906ec11f012 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -403,6 +403,12 @@ Settings.rack_attack.git_basic_auth['maxretry'] ||= 10 Settings.rack_attack.git_basic_auth['findtime'] ||= 1.minute Settings.rack_attack.git_basic_auth['bantime'] ||= 1.hour +# +# Gitaly +# +Settings['gitaly'] ||= Settingslogic.new({}) +Settings.gitaly['socket_path'] ||= ENV['GITALY_SOCKET_PATH'] + # # Testing settings # diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index d28bb583fe7..a3b502ffd6a 100644 --- a/lib/gitlab/workhorse.rb +++ b/lib/gitlab/workhorse.rb @@ -15,10 +15,17 @@ module Gitlab class << self def git_http_ok(repository, user) - { + params = { GL_ID: Gitlab::GlId.gl_id(user), RepoPath: repository.path_to_repo, } + + params.merge!( + GitalySocketPath: Gitlab.config.gitaly.socket_path, + GitalyResourcePath: "/projects/#{repository.project.id}/git-http/info-refs", + ) if Gitlab.config.gitaly.socket_path.present? + + params end def lfs_upload_ok(oid, size) diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb index 61da91dcbd3..4b1cd466677 100644 --- a/spec/lib/gitlab/workhorse_spec.rb +++ b/spec/lib/gitlab/workhorse_spec.rb @@ -174,4 +174,27 @@ describe Gitlab::Workhorse, lib: true do described_class.verify_api_request!(headers) end end + + describe '.git_http_ok' do + let(:user) { create(:user) } + + subject { described_class.git_http_ok(repository, user) } + + it { expect(subject).to eq({ GL_ID: "user-#{user.id}", RepoPath: repository.path_to_repo }) } + + context 'when Gitaly socket path is present' do + let(:gitaly_socket_path) { '/tmp/gitaly.sock' } + + before do + allow(Gitlab.config.gitaly).to receive(:socket_path).and_return(gitaly_socket_path) + end + + it 'includes Gitaly params in the returned value' do + expect(subject).to include({ + GitalyResourcePath: "/projects/#{repository.project.id}/git-http/info-refs", + GitalySocketPath: gitaly_socket_path, + }) + end + end + end end