Commit e865251e authored by Ash McKenzie's avatar Ash McKenzie

Rename HTTPHelper#host to #internal_api_endpoint

parent dd4bd1d7
...@@ -35,7 +35,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -35,7 +35,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
params[:user_id] = actor.gsub("user-", "") params[:user_id] = actor.gsub("user-", "")
end end
url = "#{host}/allowed" url = "#{internal_api_endpoint}/allowed"
resp = post(url, params) resp = post(url, params)
if resp.code == '200' if resp.code == '200'
...@@ -52,7 +52,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -52,7 +52,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def discover(key) def discover(key)
key_id = key.gsub("key-", "") key_id = key.gsub("key-", "")
resp = get("#{host}/discover?key_id=#{key_id}") resp = get("#{internal_api_endpoint}/discover?key_id=#{key_id}")
JSON.parse(resp.body) rescue nil JSON.parse(resp.body) rescue nil
end end
...@@ -62,7 +62,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -62,7 +62,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
key_id: key.gsub('key-', '') key_id: key.gsub('key-', '')
} }
resp = post("#{host}/lfs_authenticate", params) resp = post("#{internal_api_endpoint}/lfs_authenticate", params)
if resp.code == '200' if resp.code == '200'
GitlabLfsAuthentication.build_from_json(resp.body) GitlabLfsAuthentication.build_from_json(resp.body)
...@@ -70,14 +70,14 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -70,14 +70,14 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end end
def broadcast_message def broadcast_message
resp = get("#{host}/broadcast_message") resp = get("#{internal_api_endpoint}/broadcast_message")
JSON.parse(resp.body) rescue {} JSON.parse(resp.body) rescue {}
end end
def merge_request_urls(gl_repository, repo_path, changes) def merge_request_urls(gl_repository, repo_path, changes)
changes = changes.join("\n") unless changes.is_a?(String) changes = changes.join("\n") unless changes.is_a?(String)
changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '') changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '')
url = "#{host}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}" url = "#{internal_api_endpoint}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}"
url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository
resp = get(url) resp = get(url)
...@@ -91,11 +91,11 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -91,11 +91,11 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end end
def check def check
get("#{host}/check", read_timeout: CHECK_TIMEOUT) get("#{internal_api_endpoint}/check", read_timeout: CHECK_TIMEOUT)
end end
def authorized_key(key) def authorized_key(key)
resp = get("#{host}/authorized_keys?key=#{URI.escape(key, '+/=')}") resp = get("#{internal_api_endpoint}/authorized_keys?key=#{URI.escape(key, '+/=')}")
JSON.parse(resp.body) if resp.code == "200" JSON.parse(resp.body) if resp.code == "200"
rescue rescue
nil nil
...@@ -103,7 +103,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -103,7 +103,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def two_factor_recovery_codes(key) def two_factor_recovery_codes(key)
key_id = key.gsub('key-', '') key_id = key.gsub('key-', '')
resp = post("#{host}/two_factor_recovery_codes", key_id: key_id) resp = post("#{internal_api_endpoint}/two_factor_recovery_codes", key_id: key_id)
JSON.parse(resp.body) if resp.code == '200' JSON.parse(resp.body) if resp.code == '200'
rescue rescue
...@@ -112,7 +112,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -112,7 +112,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def notify_post_receive(gl_repository, repo_path) def notify_post_receive(gl_repository, repo_path)
params = { gl_repository: gl_repository, project: repo_path } params = { gl_repository: gl_repository, project: repo_path }
resp = post("#{host}/notify_post_receive", params) resp = post("#{internal_api_endpoint}/notify_post_receive", params)
resp.code == '200' resp.code == '200'
rescue rescue
...@@ -125,7 +125,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -125,7 +125,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
identifier: identifier, identifier: identifier,
changes: changes changes: changes
} }
resp = post("#{host}/post_receive", params) resp = post("#{internal_api_endpoint}/post_receive", params)
raise NotFound if resp.code == '404' raise NotFound if resp.code == '404'
...@@ -133,7 +133,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength ...@@ -133,7 +133,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end end
def pre_receive(gl_repository) def pre_receive(gl_repository)
resp = post("#{host}/pre_receive", gl_repository: gl_repository) resp = post("#{internal_api_endpoint}/pre_receive", gl_repository: gl_repository)
raise NotFound if resp.code == '404' raise NotFound if resp.code == '404'
......
...@@ -11,7 +11,7 @@ module HTTPHelper ...@@ -11,7 +11,7 @@ module HTTPHelper
"#{config.gitlab_url}/api/v4" "#{config.gitlab_url}/api/v4"
end end
def host def internal_api_endpoint
"#{base_api_endpoint}/internal" "#{base_api_endpoint}/internal"
end end
......
...@@ -5,14 +5,14 @@ require_relative '../lib/gitlab_access_status' ...@@ -5,14 +5,14 @@ require_relative '../lib/gitlab_access_status'
describe GitlabNet, vcr: true do describe GitlabNet, vcr: true do
let(:gitlab_net) { GitlabNet.new } let(:gitlab_net) { GitlabNet.new }
let(:changes) { ['0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'] } let(:changes) { ['0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'] }
let(:host) { 'http://localhost:3000/api/v4/internal' } let(:internal_api_endpoint) { 'http://localhost:3000/api/v4/internal' }
let(:project) { 'gitlab-org/gitlab-test.git' } let(:project) { 'gitlab-org/gitlab-test.git' }
let(:key) { 'key-1' } let(:key) { 'key-1' }
let(:key2) { 'key-2' } let(:key2) { 'key-2' }
let(:secret) { "0a3938d9d95d807e94d937af3a4fbbea\n" } let(:secret) { "0a3938d9d95d807e94d937af3a4fbbea\n" }
before do before do
gitlab_net.stub(:host).and_return(host) gitlab_net.stub(:internal_api_endpoint).and_return(internal_api_endpoint)
gitlab_net.stub(:secret_token).and_return(secret) gitlab_net.stub(:secret_token).and_return(secret)
end end
...@@ -68,7 +68,7 @@ describe GitlabNet, vcr: true do ...@@ -68,7 +68,7 @@ describe GitlabNet, vcr: true do
lfs_access = gitlab_net.lfs_authenticate(key, project) lfs_access = gitlab_net.lfs_authenticate(key, project)
lfs_access.username.should == 'root' lfs_access.username.should == 'root'
lfs_access.lfs_token.should == 'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ' lfs_access.lfs_token.should == 'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ'
lfs_access.repository_http_path.should == URI.join(host.sub('api/v4', ''), project).to_s lfs_access.repository_http_path.should == URI.join(internal_api_endpoint.sub('api/v4', ''), project).to_s
end end
end end
end end
...@@ -100,13 +100,13 @@ describe GitlabNet, vcr: true do ...@@ -100,13 +100,13 @@ describe GitlabNet, vcr: true do
let(:encoded_changes) { "123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag" } let(:encoded_changes) { "123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag" }
it "sends the given arguments as encoded URL parameters" do it "sends the given arguments as encoded URL parameters" do
gitlab_net.should_receive(:get).with("#{host}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}") gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
gitlab_net.merge_request_urls(gl_repository, project, changes) gitlab_net.merge_request_urls(gl_repository, project, changes)
end end
it "omits the gl_repository parameter if it's nil" do it "omits the gl_repository parameter if it's nil" do
gitlab_net.should_receive(:get).with("#{host}/merge_request_urls?project=#{project}&changes=#{encoded_changes}") gitlab_net.should_receive(:get).with("#{internal_api_endpoint}/merge_request_urls?project=#{project}&changes=#{encoded_changes}")
gitlab_net.merge_request_urls(nil, project, changes) gitlab_net.merge_request_urls(nil, project, changes)
end end
...@@ -361,12 +361,12 @@ describe GitlabNet, vcr: true do ...@@ -361,12 +361,12 @@ describe GitlabNet, vcr: true do
it("uses API version 4") { should end_with("api/v4") } it("uses API version 4") { should end_with("api/v4") }
end end
describe :host do describe :internal_api_endpoint do
let(:net) { GitlabNet.new } let(:net) { GitlabNet.new }
subject { net.send :host } subject { net.send :internal_api_endpoint }
it { should include(net.send(:config).gitlab_url) } it { should include(net.send(:config).gitlab_url) }
it("uses API version 4") { should include("api/v4") } it("uses API version 4") { should end_with("api/v4/internal") }
end end
describe :http_client_for do describe :http_client_for do
......
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