Commit e5f9ccee authored by Ash McKenzie's avatar Ash McKenzie

Add GitPushSSHProxy.inform_client_message

b82f5aa5
parent 15976edf
......@@ -37,8 +37,9 @@ module EE
payload = {
'action' => 'geo_proxy_to_primary',
'data' => {
'api_endpoints' => [api_v4_geo_proxy_git_push_ssh_info_refs_path, api_v4_geo_proxy_git_push_ssh_push_path],
'primary_repo' => geo_primary_http_url_to_repo(project_or_wiki)
'info_message' => proxying_to_primary_message,
'api_endpoints' => custom_action_api_endpoints,
'primary_repo' => primary_http_repo_url
}
}
......@@ -63,6 +64,25 @@ module EE
geo_primary_http_url_to_repo(project_or_wiki)
end
end
def primary_http_repo_url
geo_primary_http_url_to_repo(project_or_wiki)
end
def primary_ssh_url_to_repo
geo_primary_ssh_url_to_repo(project_or_wiki)
end
def proxying_to_primary_message
::Gitlab::Geo::GitPushSSHProxy.inform_client_message(primary_ssh_url_to_repo)
end
def custom_action_api_endpoints
[
api_v4_geo_proxy_git_push_ssh_info_refs_path,
api_v4_geo_proxy_git_push_ssh_push_path
]
end
end
end
end
......@@ -11,10 +11,49 @@ module Gitlab
MustBeASecondaryNode = Class.new(StandardError)
class APIResponse
attr_reader :code, :body
def initialize(code, body)
@code = code
@body = body
end
def self.from_http_response(response, primary_repo)
success = response.is_a?(Net::HTTPSuccess)
body = response.body.to_s
if success
result = Base64.encode64(body)
else
message = failed_message(body, primary_repo)
end
new(response.code.to_i, status: success, message: message, result: result)
end
def self.failed_message(str, primary_repo)
"Failed to contact primary #{primary_repo}\nError: #{str}"
end
end
class FailedAPIResponse < APIResponse
def self.from_exception(ex_message, primary_repo, code: 500)
new(code.to_i,
status: false,
message: failed_message(ex_message, primary_repo),
result: nil)
end
end
def initialize(data)
@data = data
end
def self.inform_client_message(primary_repo_ssh)
"You're pushing to a Geo secondary.\nWe'll help you by proxying this request to the primary: #{primary_repo_ssh}"
end
def info_refs
ensure_secondary!
......
......@@ -27,6 +27,7 @@ describe Gitlab::Geo::GitPushSSHProxy, :geo do
end
let(:primary_repo_http) { geo_primary_http_url_to_repo(project) }
let(:primary_repo_ssh) { geo_primary_ssh_url_to_repo(project) }
let(:data) do
{
......@@ -35,6 +36,13 @@ describe Gitlab::Geo::GitPushSSHProxy, :geo do
}
end
describe '.inform_client_message' do
it 'returns a message, with the ssh address' do
expect(described_class.inform_client_message(primary_repo_ssh)).to eql("You're pushing to a Geo secondary.\nWe'll help you by proxying this request to the primary: #{primary_repo_ssh}")
end
end
context 'instance methods' do
subject { described_class.new(data) }
before do
......@@ -60,10 +68,7 @@ describe Gitlab::Geo::GitPushSSHProxy, :geo do
let(:full_info_refs_url) { "#{primary_repo_http}/info/refs?service=git-receive-pack" }
let(:info_refs_headers) { base_headers.merge('Content-Type' => 'application/x-git-upload-pack-request') }
let(:info_refs_http_body_full) do
"001f# service=git-receive-pack
0000#{info_refs_body_short}"
end
let(:info_refs_http_body_full) { "001f# service=git-receive-pack\n0000#{info_refs_body_short}" }
before do
stub_request(:get, full_info_refs_url).to_return(status: 200, body: info_refs_http_body_full, headers: info_refs_headers)
......@@ -110,4 +115,5 @@ describe Gitlab::Geo::GitPushSSHProxy, :geo do
end
end
end
end
end
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