2018-09-23 19:44:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-15 16:31:14 +00:00
|
|
|
class Import::GiteaController < Import::GithubController
|
2018-11-07 16:44:21 +00:00
|
|
|
extend ::Gitlab::Utils::Override
|
|
|
|
|
2020-04-07 00:09:33 +00:00
|
|
|
before_action :verify_blocked_uri, only: :status
|
|
|
|
|
2016-12-15 16:31:14 +00:00
|
|
|
def new
|
2018-11-07 16:44:21 +00:00
|
|
|
if session[access_token_key].present? && provider_url.present?
|
2016-12-15 16:31:14 +00:00
|
|
|
redirect_to status_import_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def personal_access_token
|
2016-12-16 16:43:34 +00:00
|
|
|
session[host_key] = params[host_key]
|
2016-12-15 16:31:14 +00:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2018-11-07 16:44:21 +00:00
|
|
|
# Must be defined or it will 404
|
2016-12-15 16:31:14 +00:00
|
|
|
def status
|
2020-04-07 00:09:33 +00:00
|
|
|
super
|
2016-12-15 16:31:14 +00:00
|
|
|
end
|
|
|
|
|
2020-07-17 00:09:37 +00:00
|
|
|
protected
|
2016-12-15 16:31:14 +00:00
|
|
|
|
2020-07-17 00:09:37 +00:00
|
|
|
override :provider_name
|
|
|
|
def provider_name
|
|
|
|
:gitea
|
2016-12-16 16:43:34 +00:00
|
|
|
end
|
|
|
|
|
2020-07-17 00:09:37 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def host_key
|
|
|
|
:"#{provider_name}_host_url"
|
2016-12-15 16:31:14 +00:00
|
|
|
end
|
|
|
|
|
2018-11-07 16:44:21 +00:00
|
|
|
override :provider_url
|
|
|
|
def provider_url
|
|
|
|
session[host_key]
|
|
|
|
end
|
|
|
|
|
2016-12-15 16:31:14 +00:00
|
|
|
# Gitea is not yet an OAuth provider
|
|
|
|
# See https://github.com/go-gitea/gitea/issues/27
|
2018-11-07 16:44:21 +00:00
|
|
|
override :logged_in_with_provider?
|
2016-12-15 16:31:14 +00:00
|
|
|
def logged_in_with_provider?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-11-07 16:44:21 +00:00
|
|
|
override :provider_auth
|
2016-12-15 16:31:14 +00:00
|
|
|
def provider_auth
|
2018-11-07 16:44:21 +00:00
|
|
|
if session[access_token_key].blank? || provider_url.blank?
|
2016-12-15 16:31:14 +00:00
|
|
|
redirect_to new_import_gitea_url,
|
2019-03-27 16:52:52 +00:00
|
|
|
alert: _('You need to specify both an Access Token and a Host URL.')
|
2016-12-15 16:31:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-11 12:09:55 +00:00
|
|
|
override :client_repos
|
|
|
|
def client_repos
|
|
|
|
@client_repos ||= filtered(client.repos)
|
|
|
|
end
|
|
|
|
|
|
|
|
override :client
|
|
|
|
def client
|
|
|
|
@client ||= Gitlab::LegacyGithubImport::Client.new(session[access_token_key], client_options)
|
|
|
|
end
|
|
|
|
|
2018-11-07 16:44:21 +00:00
|
|
|
override :client_options
|
2016-12-15 16:31:14 +00:00
|
|
|
def client_options
|
2018-11-07 16:44:21 +00:00
|
|
|
{ host: provider_url, api_version: 'v1' }
|
2016-12-15 16:31:14 +00:00
|
|
|
end
|
2020-03-05 15:07:52 +00:00
|
|
|
|
2020-04-07 00:09:33 +00:00
|
|
|
def verify_blocked_uri
|
|
|
|
Gitlab::UrlBlocker.validate!(
|
2020-03-05 15:07:52 +00:00
|
|
|
provider_url,
|
2020-12-10 00:09:50 +00:00
|
|
|
allow_localhost: allow_local_requests?,
|
|
|
|
allow_local_network: allow_local_requests?,
|
|
|
|
schemes: %w(http https)
|
2020-03-05 15:07:52 +00:00
|
|
|
)
|
2020-04-07 00:09:33 +00:00
|
|
|
rescue Gitlab::UrlBlocker::BlockedUrlError => e
|
|
|
|
session[access_token_key] = nil
|
|
|
|
|
|
|
|
redirect_to new_import_url, alert: _('Specified URL cannot be used: "%{reason}"') % { reason: e.message }
|
2020-03-05 15:07:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def allow_local_requests?
|
|
|
|
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
|
|
|
|
end
|
2016-12-15 16:31:14 +00:00
|
|
|
end
|