debian-mirror-gitlab/app/controllers/import/gitea_controller.rb

81 lines
1.7 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class Import::GiteaController < Import::GithubController
2019-07-07 11:18:12 +05:30
extend ::Gitlab::Utils::Override
2020-04-22 19:07:51 +05:30
before_action :verify_blocked_uri, only: :status
2017-08-17 22:00:37 +05:30
def new
2019-07-07 11:18:12 +05:30
if session[access_token_key].present? && provider_url.present?
2017-08-17 22:00:37 +05:30
redirect_to status_import_url
end
end
def personal_access_token
session[host_key] = params[host_key]
super
end
2019-07-07 11:18:12 +05:30
# Must be defined or it will 404
2017-08-17 22:00:37 +05:30
def status
2020-04-22 19:07:51 +05:30
super
2017-08-17 22:00:37 +05:30
end
2020-07-28 23:09:34 +05:30
protected
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
override :provider_name
def provider_name
:gitea
2017-08-17 22:00:37 +05:30
end
2020-07-28 23:09:34 +05:30
private
def host_key
:"#{provider_name}_host_url"
2017-08-17 22:00:37 +05:30
end
2019-07-07 11:18:12 +05:30
override :provider_url
def provider_url
session[host_key]
end
2017-08-17 22:00:37 +05:30
# Gitea is not yet an OAuth provider
# See https://github.com/go-gitea/gitea/issues/27
2019-07-07 11:18:12 +05:30
override :logged_in_with_provider?
2017-08-17 22:00:37 +05:30
def logged_in_with_provider?
false
end
2019-07-07 11:18:12 +05:30
override :provider_auth
2017-08-17 22:00:37 +05:30
def provider_auth
2019-07-07 11:18:12 +05:30
if session[access_token_key].blank? || provider_url.blank?
2017-08-17 22:00:37 +05:30
redirect_to new_import_gitea_url,
2019-07-07 11:18:12 +05:30
alert: _('You need to specify both an Access Token and a Host URL.')
2017-08-17 22:00:37 +05:30
end
end
2019-07-07 11:18:12 +05:30
override :client_options
2017-08-17 22:00:37 +05:30
def client_options
2019-07-07 11:18:12 +05:30
{ host: provider_url, api_version: 'v1' }
2017-08-17 22:00:37 +05:30
end
2020-04-08 14:13:33 +05:30
2020-04-22 19:07:51 +05:30
def verify_blocked_uri
Gitlab::UrlBlocker.validate!(
2020-04-08 14:13:33 +05:30
provider_url,
{
allow_localhost: allow_local_requests?,
allow_local_network: allow_local_requests?,
schemes: %w(http https)
}
)
2020-04-22 19:07:51 +05:30
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-04-08 14:13:33 +05:30
end
def allow_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end
2017-08-17 22:00:37 +05:30
end