Pass Gitaly resource path to gitlab-workhorse if Gitaly is enabled

This commit is contained in:
Ahmad Sherif 2016-12-26 19:15:40 +02:00
parent 4b43126d08
commit 0a1c8bb37c
4 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,4 @@
---
title: Pass Gitaly resource path to gitlab-workhorse if Gitaly is enabled
merge_request: 8440
author:

View File

@ -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
#

View File

@ -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)

View File

@ -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