Commit f5591f68 authored by Stan Hu's avatar Stan Hu

Support unhiding of all refs for Geo Nodes

By default, we hide certain refs (e.g. keep-around/XXX) to save user
download time. We need to preserve these references on secondary Geo
nodes to have a true copy.
parent 914f9685
require 'json' require 'json'
class GitAccessStatus class GitAccessStatus
attr_reader :message, :gl_repository, :repository_path, :gitaly attr_reader :message, :gl_repository, :repository_path, :gitaly, :geo_node
def initialize(status, message, gl_repository, repository_path, gitaly) def initialize(status, message, gl_repository, repository_path, gitaly, geo_node)
@status = status @status = status
@message = message @message = message
@gl_repository = gl_repository @gl_repository = gl_repository
@repository_path = repository_path @repository_path = repository_path
@gitaly = gitaly @gitaly = gitaly
@geo_node = geo_node
end end
def self.create_from_json(json) def self.create_from_json(json)
values = JSON.parse(json) values = JSON.parse(json)
self.new(values["status"], values["message"], values["gl_repository"], values["repository_path"], values["gitaly"]) self.new(values["status"],
values["message"],
values["gl_repository"],
values["repository_path"],
values["gitaly"],
values["geo_node"])
end end
def allowed? def allowed?
......
...@@ -39,7 +39,7 @@ class GitlabNet ...@@ -39,7 +39,7 @@ class GitlabNet
if resp.code == '200' if resp.code == '200'
GitAccessStatus.create_from_json(resp.body) GitAccessStatus.create_from_json(resp.body)
else else
GitAccessStatus.new(false, 'API is not accessible', nil, nil) GitAccessStatus.new(false, 'API is not accessible', nil, nil, nil, false)
end end
end end
......
...@@ -17,7 +17,7 @@ class GitlabShell ...@@ -17,7 +17,7 @@ class GitlabShell
API_COMMANDS = %w(2fa_recovery_codes) API_COMMANDS = %w(2fa_recovery_codes)
GL_PROTOCOL = 'ssh'.freeze GL_PROTOCOL = 'ssh'.freeze
attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access, :show_all_refs
attr_reader :repo_path attr_reader :repo_path
def initialize(key_id) def initialize(key_id)
...@@ -100,6 +100,7 @@ class GitlabShell ...@@ -100,6 +100,7 @@ class GitlabShell
self.repo_path = status.repository_path self.repo_path = status.repository_path
@gl_repository = status.gl_repository @gl_repository = status.gl_repository
@gitaly = status.gitaly @gitaly = status.gitaly
@show_all_refs = status.geo_node
end end
def process_cmd(args) def process_cmd(args)
...@@ -159,6 +160,10 @@ class GitlabShell ...@@ -159,6 +160,10 @@ class GitlabShell
env['GITALY_TOKEN'] = @gitaly['token'] env['GITALY_TOKEN'] = @gitaly['token']
end end
# We have to use a negative transfer.hideRefs since this is the only way
# to undo an already set parameter: https://www.spinics.net/lists/git/msg256772.html
env['GIT_CONFIG_PARAMETERS'] = "'transfer.hideRefs=!refs'" if @show_all_refs
if git_trace_available? if git_trace_available?
env.merge!({ env.merge!({
'GIT_TRACE' => @config.git_trace_log_file, 'GIT_TRACE' => @config.git_trace_log_file,
......
...@@ -7,7 +7,7 @@ describe GitlabAccess do ...@@ -7,7 +7,7 @@ describe GitlabAccess do
let(:repo_path) { File.join(repository_path, repo_name) + ".git" } let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
let(:api) do let(:api) do
double(GitlabNet).tap do |api| double(GitlabNet).tap do |api|
api.stub(check_access: GitAccessStatus.new(true, 'ok', 'project-1', '/home/git/repositories', nil)) api.stub(check_access: GitAccessStatus.new(true, 'ok', 'project-1', '/home/git/repositories', nil, false))
end end
end end
subject do subject do
...@@ -38,7 +38,7 @@ describe GitlabAccess do ...@@ -38,7 +38,7 @@ describe GitlabAccess do
context "access is denied" do context "access is denied" do
before do before do
api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil, nil)) api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil, nil, false))
end end
it "returns false" do it "returns false" do
......
...@@ -19,12 +19,12 @@ describe GitlabShell do ...@@ -19,12 +19,12 @@ describe GitlabShell do
end end
end end
let(:gitaly_check_access) { GitAccessStatus.new(true, 'ok', gl_repository, repo_path, { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' })} let(:gitaly_check_access) { GitAccessStatus.new(true, 'ok', gl_repository, repo_path, { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' }, false) }
let(:api) do let(:api) do
double(GitlabNet).tap do |api| double(GitlabNet).tap do |api|
api.stub(discover: { 'name' => 'John Doe' }) api.stub(discover: { 'name' => 'John Doe' })
api.stub(check_access: GitAccessStatus.new(true, 'ok', gl_repository, repo_path, nil)) api.stub(check_access: GitAccessStatus.new(true, 'ok', gl_repository, repo_path, nil, false))
api.stub(two_factor_recovery_codes: { api.stub(two_factor_recovery_codes: {
'success' => true, 'success' => true,
'recovery_codes' => ['f67c514de60c4953', '41278385fc00c1e0'] 'recovery_codes' => ['f67c514de60c4953', '41278385fc00c1e0']
...@@ -326,7 +326,7 @@ describe GitlabShell do ...@@ -326,7 +326,7 @@ describe GitlabShell do
end end
it "should disallow access and log the attempt if check_access returns false status" do it "should disallow access and log the attempt if check_access returns false status" do
api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil, nil)) api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil, nil, false))
message = "gitlab-shell: Access denied for git command <git-upload-pack gitlab-ci.git> " message = "gitlab-shell: Access denied for git command <git-upload-pack gitlab-ci.git> "
message << "by user with key #{key_id}." message << "by user with key #{key_id}."
$logger.should_receive(:warn).with(message) $logger.should_receive(:warn).with(message)
...@@ -386,6 +386,20 @@ describe GitlabShell do ...@@ -386,6 +386,20 @@ describe GitlabShell do
shell.send :exec_cmd, [1, 2] shell.send :exec_cmd, [1, 2]
end end
context "when show_all_refs is enabled" do
before { shell.show_all_refs = true }
it 'sets local git parameters' do
expected_hash = hash_including(
'GIT_CONFIG_PARAMETERS' => "'transfer.hideRefs=!refs'"
)
Kernel.should_receive(:exec).with(expected_hash, [1, 2], exec_options).once
shell.send :exec_cmd, [1, 2]
end
end
context "when specifying a git_tracing log file" do context "when specifying a git_tracing log file" do
let(:git_trace_log_file) { '/tmp/git_trace_performance.log' } let(:git_trace_log_file) { '/tmp/git_trace_performance.log' }
......
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