Commit 8b871c33 authored by George Koltsov's avatar George Koltsov Committed by Matthias Käppler

Allow Bulk Import to use relative GitLab URL

 - Instead of reconstructing a URL user provided
   for bulk import, use it as is in order to allow
   GitLab instances that live on relative URLs
   to work

Changelog: fixed
parent 236d14b6
...@@ -87,7 +87,7 @@ class Import::BulkImportsController < ApplicationController ...@@ -87,7 +87,7 @@ class Import::BulkImportsController < ApplicationController
def client def client
@client ||= BulkImports::Clients::HTTP.new( @client ||= BulkImports::Clients::HTTP.new(
uri: session[url_key], url: session[url_key],
token: session[access_token_key], token: session[access_token_key],
per_page: params[:per_page], per_page: params[:per_page],
page: params[:page] page: params[:page]
......
...@@ -9,7 +9,7 @@ module BulkImports ...@@ -9,7 +9,7 @@ module BulkImports
@relation = relation @relation = relation
@entity = @pipeline_tracker.entity @entity = @pipeline_tracker.entity
@configuration = @entity.bulk_import.configuration @configuration = @entity.bulk_import.configuration
@client = Clients::HTTP.new(uri: @configuration.url, token: @configuration.access_token) @client = Clients::HTTP.new(url: @configuration.url, token: @configuration.access_token)
end end
def started? def started?
......
...@@ -55,7 +55,7 @@ module BulkImports ...@@ -55,7 +55,7 @@ module BulkImports
def http_client def http_client
@http_client ||= BulkImports::Clients::HTTP.new( @http_client ||= BulkImports::Clients::HTTP.new(
uri: configuration.url, url: configuration.url,
token: configuration.access_token token: configuration.access_token
) )
end end
......
...@@ -25,7 +25,7 @@ module BulkImports ...@@ -25,7 +25,7 @@ module BulkImports
def http_client(configuration) def http_client(configuration)
@client ||= Clients::HTTP.new( @client ||= Clients::HTTP.new(
uri: configuration.url, url: configuration.url,
token: configuration.access_token token: configuration.access_token
) )
end end
......
...@@ -7,8 +7,8 @@ module BulkImports ...@@ -7,8 +7,8 @@ module BulkImports
DEFAULT_PAGE = 1 DEFAULT_PAGE = 1
DEFAULT_PER_PAGE = 30 DEFAULT_PER_PAGE = 30
def initialize(uri:, token:, page: DEFAULT_PAGE, per_page: DEFAULT_PER_PAGE, api_version: API_VERSION) def initialize(url:, token:, page: DEFAULT_PAGE, per_page: DEFAULT_PER_PAGE, api_version: API_VERSION)
@uri = URI.parse(uri) @url = url
@token = token&.strip @token = token&.strip
@page = page @page = page
@per_page = per_page @per_page = per_page
...@@ -120,12 +120,8 @@ module BulkImports ...@@ -120,12 +120,8 @@ module BulkImports
raise(::BulkImports::Error, e) raise(::BulkImports::Error, e)
end end
def base_uri
@base_uri ||= "#{@uri.scheme}://#{@uri.host}:#{@uri.port}"
end
def api_url def api_url
Gitlab::Utils.append_path(base_uri, "/api/#{@api_version}") Gitlab::Utils.append_path(@url, "/api/#{@api_version}")
end end
end end
end end
......
...@@ -25,7 +25,7 @@ module BulkImports ...@@ -25,7 +25,7 @@ module BulkImports
def http_client(configuration) def http_client(configuration)
@http_client ||= BulkImports::Clients::HTTP.new( @http_client ||= BulkImports::Clients::HTTP.new(
uri: configuration.url, url: configuration.url,
token: configuration.access_token, token: configuration.access_token,
per_page: 100 per_page: 100
) )
......
...@@ -18,7 +18,7 @@ module BulkImports ...@@ -18,7 +18,7 @@ module BulkImports
def http_client(configuration) def http_client(configuration)
@http_client ||= BulkImports::Clients::HTTP.new( @http_client ||= BulkImports::Clients::HTTP.new(
uri: configuration.url, url: configuration.url,
token: configuration.access_token, token: configuration.access_token,
per_page: 100 per_page: 100
) )
......
...@@ -51,7 +51,7 @@ RSpec.describe Import::BulkImportsController do ...@@ -51,7 +51,7 @@ RSpec.describe Import::BulkImportsController do
end end
describe 'GET status' do describe 'GET status' do
let(:client) { BulkImports::Clients::HTTP.new(uri: 'http://gitlab.example', token: 'token') } let(:client) { BulkImports::Clients::HTTP.new(url: 'http://gitlab.example', token: 'token') }
describe 'serialized group data' do describe 'serialized group data' do
let(:client_response) do let(:client_response) do
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe BulkImports::Clients::HTTP do RSpec.describe BulkImports::Clients::HTTP do
include ImportSpecHelper include ImportSpecHelper
let(:uri) { 'http://gitlab.example' } let(:url) { 'http://gitlab.example' }
let(:token) { 'token' } let(:token) { 'token' }
let(:resource) { 'resource' } let(:resource) { 'resource' }
let(:version) { "#{BulkImport::MINIMUM_GITLAB_MAJOR_VERSION}.0.0" } let(:version) { "#{BulkImport::MINIMUM_GITLAB_MAJOR_VERSION}.0.0" }
...@@ -14,11 +14,11 @@ RSpec.describe BulkImports::Clients::HTTP do ...@@ -14,11 +14,11 @@ RSpec.describe BulkImports::Clients::HTTP do
before do before do
allow(Gitlab::HTTP).to receive(:get) allow(Gitlab::HTTP).to receive(:get)
.with('http://gitlab.example:80/api/v4/version', anything) .with('http://gitlab.example/api/v4/version', anything)
.and_return(version_response) .and_return(version_response)
end end
subject { described_class.new(uri: uri, token: token) } subject { described_class.new(url: url, token: token) }
shared_examples 'performs network request' do shared_examples 'performs network request' do
it 'performs network request' do it 'performs network request' do
...@@ -54,7 +54,7 @@ RSpec.describe BulkImports::Clients::HTTP do ...@@ -54,7 +54,7 @@ RSpec.describe BulkImports::Clients::HTTP do
include_examples 'performs network request' do include_examples 'performs network request' do
let(:expected_args) do let(:expected_args) do
[ [
'http://gitlab.example:80/api/v4/resource', 'http://gitlab.example/api/v4/resource',
hash_including( hash_including(
follow_redirects: false, follow_redirects: false,
query: { query: {
...@@ -104,7 +104,7 @@ RSpec.describe BulkImports::Clients::HTTP do ...@@ -104,7 +104,7 @@ RSpec.describe BulkImports::Clients::HTTP do
private private
def stub_http_get(path, query, response) def stub_http_get(path, query, response)
uri = "http://gitlab.example:80/api/v4/#{path}" uri = "http://gitlab.example/api/v4/#{path}"
params = { params = {
follow_redirects: false, follow_redirects: false,
headers: { headers: {
...@@ -124,7 +124,7 @@ RSpec.describe BulkImports::Clients::HTTP do ...@@ -124,7 +124,7 @@ RSpec.describe BulkImports::Clients::HTTP do
include_examples 'performs network request' do include_examples 'performs network request' do
let(:expected_args) do let(:expected_args) do
[ [
'http://gitlab.example:80/api/v4/resource', 'http://gitlab.example/api/v4/resource',
hash_including( hash_including(
body: {}, body: {},
follow_redirects: false, follow_redirects: false,
...@@ -144,7 +144,7 @@ RSpec.describe BulkImports::Clients::HTTP do ...@@ -144,7 +144,7 @@ RSpec.describe BulkImports::Clients::HTTP do
include_examples 'performs network request' do include_examples 'performs network request' do
let(:expected_args) do let(:expected_args) do
[ [
'http://gitlab.example:80/api/v4/resource', 'http://gitlab.example/api/v4/resource',
hash_including( hash_including(
follow_redirects: false, follow_redirects: false,
headers: { headers: {
...@@ -160,7 +160,7 @@ RSpec.describe BulkImports::Clients::HTTP do ...@@ -160,7 +160,7 @@ RSpec.describe BulkImports::Clients::HTTP do
describe '#stream' do describe '#stream' do
it 'performs network request with stream_body option' do it 'performs network request with stream_body option' do
expected_args = [ expected_args = [
'http://gitlab.example:80/api/v4/resource', 'http://gitlab.example/api/v4/resource',
hash_including( hash_including(
stream_body: true, stream_body: true,
headers: { headers: {
...@@ -183,4 +183,20 @@ RSpec.describe BulkImports::Clients::HTTP do ...@@ -183,4 +183,20 @@ RSpec.describe BulkImports::Clients::HTTP do
expect { subject.get(resource) }.to raise_error(::BulkImports::Error, "Unsupported GitLab Version. Minimum Supported Gitlab Version #{BulkImport::MINIMUM_GITLAB_MAJOR_VERSION}.") expect { subject.get(resource) }.to raise_error(::BulkImports::Error, "Unsupported GitLab Version. Minimum Supported Gitlab Version #{BulkImport::MINIMUM_GITLAB_MAJOR_VERSION}.")
end end
end end
context 'when url is relative' do
let(:url) { 'http://website.example/gitlab' }
before do
allow(Gitlab::HTTP).to receive(:get)
.with('http://website.example/gitlab/api/v4/version', anything)
.and_return(version_response)
end
it 'performs network request to a relative gitlab url' do
expect(Gitlab::HTTP).to receive(:get).with('http://website.example/gitlab/api/v4/resource', anything).and_return(response_double)
subject.get(resource)
end
end
end end
...@@ -6,7 +6,7 @@ RSpec.describe BulkImports::ExportRequestWorker do ...@@ -6,7 +6,7 @@ RSpec.describe BulkImports::ExportRequestWorker do
let_it_be(:bulk_import) { create(:bulk_import) } let_it_be(:bulk_import) { create(:bulk_import) }
let_it_be(:config) { create(:bulk_import_configuration, bulk_import: bulk_import) } let_it_be(:config) { create(:bulk_import_configuration, bulk_import: bulk_import) }
let_it_be(:entity) { create(:bulk_import_entity, source_full_path: 'foo/bar', bulk_import: bulk_import) } let_it_be(:entity) { create(:bulk_import_entity, source_full_path: 'foo/bar', bulk_import: bulk_import) }
let_it_be(:version_url) { 'https://gitlab.example:443/api/v4/version' } let_it_be(:version_url) { 'https://gitlab.example/api/v4/version' }
let(:response_double) { double(code: 200, success?: true, parsed_response: {}) } let(:response_double) { double(code: 200, success?: true, parsed_response: {}) }
let(:job_args) { [entity.id] } let(:job_args) { [entity.id] }
......
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