2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-20 16:41:26 +00:00
|
|
|
class Projects::GitHttpController < Projects::GitHttpClientController
|
2016-11-21 15:31:51 +00:00
|
|
|
include WorkhorseRequest
|
2016-08-19 17:10:41 +00:00
|
|
|
|
2017-05-19 19:58:45 +00:00
|
|
|
before_action :access_check
|
2019-03-19 17:02:17 +00:00
|
|
|
prepend_before_action :deny_head_requests, only: [:info_refs]
|
2017-05-19 19:58:45 +00:00
|
|
|
|
|
|
|
rescue_from Gitlab::GitAccess::UnauthorizedError, with: :render_403
|
|
|
|
rescue_from Gitlab::GitAccess::NotFoundError, with: :render_404
|
2018-01-25 12:26:52 +00:00
|
|
|
rescue_from Gitlab::GitAccess::ProjectCreationError, with: :render_422
|
2018-10-22 14:49:20 +00:00
|
|
|
rescue_from Gitlab::GitAccess::TimeoutError, with: :render_503
|
2017-05-19 19:58:45 +00:00
|
|
|
|
2016-04-22 11:24:53 +00:00
|
|
|
# GET /foo/bar.git/info/refs?service=git-upload-pack (git pull)
|
|
|
|
# GET /foo/bar.git/info/refs?service=git-receive-pack (git push)
|
|
|
|
def info_refs
|
2017-05-19 19:58:45 +00:00
|
|
|
log_user_activity if upload_pack?
|
2018-01-18 09:31:00 +00:00
|
|
|
|
2017-05-19 19:58:45 +00:00
|
|
|
render_ok
|
2016-03-23 17:34:16 +00:00
|
|
|
end
|
2016-04-15 10:40:43 +00:00
|
|
|
|
2016-04-22 11:24:53 +00:00
|
|
|
# POST /foo/bar.git/git-upload-pack (git pull)
|
|
|
|
def git_upload_pack
|
2018-12-13 19:26:56 +00:00
|
|
|
enqueue_fetch_statistics_update
|
|
|
|
|
2017-05-19 19:58:45 +00:00
|
|
|
render_ok
|
2016-04-22 11:24:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /foo/bar.git/git-receive-pack" (git push)
|
|
|
|
def git_receive_pack
|
2017-05-19 19:58:45 +00:00
|
|
|
render_ok
|
2016-03-23 17:34:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-03-19 17:02:17 +00:00
|
|
|
def deny_head_requests
|
|
|
|
head :forbidden if request.head?
|
|
|
|
end
|
|
|
|
|
2016-07-20 16:41:26 +00:00
|
|
|
def download_request?
|
|
|
|
upload_pack?
|
2016-03-23 17:34:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def upload_pack?
|
2016-04-22 11:24:53 +00:00
|
|
|
git_command == 'git-upload-pack'
|
2016-03-24 17:58:29 +00:00
|
|
|
end
|
|
|
|
|
2016-04-22 11:24:53 +00:00
|
|
|
def git_command
|
2016-03-23 17:34:16 +00:00
|
|
|
if action_name == 'info_refs'
|
2016-03-24 17:58:29 +00:00
|
|
|
params[:service]
|
2016-03-23 17:34:16 +00:00
|
|
|
else
|
2016-06-03 12:57:34 +00:00
|
|
|
action_name.dasherize
|
2016-03-23 17:34:16 +00:00
|
|
|
end
|
|
|
|
end
|
2016-04-15 10:40:43 +00:00
|
|
|
|
2016-03-23 17:34:16 +00:00
|
|
|
def render_ok
|
2016-08-19 17:10:41 +00:00
|
|
|
set_workhorse_internal_api_content_type
|
2019-03-18 16:51:11 +00:00
|
|
|
render json: Gitlab::Workhorse.git_http_ok(repository, repo_type, user, action_name)
|
2016-03-23 17:34:16 +00:00
|
|
|
end
|
2016-04-15 10:40:43 +00:00
|
|
|
|
2017-05-19 19:58:45 +00:00
|
|
|
def render_403(exception)
|
|
|
|
render plain: exception.message, status: :forbidden
|
2016-06-23 22:37:57 +00:00
|
|
|
end
|
|
|
|
|
2017-05-19 19:58:45 +00:00
|
|
|
def render_404(exception)
|
|
|
|
render plain: exception.message, status: :not_found
|
2016-03-23 17:34:16 +00:00
|
|
|
end
|
2016-03-24 17:58:29 +00:00
|
|
|
|
2018-01-25 12:26:52 +00:00
|
|
|
def render_422(exception)
|
|
|
|
render plain: exception.message, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
|
2018-10-22 14:49:20 +00:00
|
|
|
def render_503(exception)
|
|
|
|
render plain: exception.message, status: :service_unavailable
|
|
|
|
end
|
|
|
|
|
2018-12-13 19:26:56 +00:00
|
|
|
def enqueue_fetch_statistics_update
|
|
|
|
return if wiki?
|
|
|
|
return unless project.daily_statistics_enabled?
|
|
|
|
|
|
|
|
ProjectDailyStatisticsWorker.perform_async(project.id)
|
|
|
|
end
|
|
|
|
|
2016-06-27 16:14:44 +00:00
|
|
|
def access
|
2018-02-02 15:27:30 +00:00
|
|
|
@access ||= access_klass.new(access_actor, project,
|
|
|
|
'http', authentication_abilities: authentication_abilities,
|
|
|
|
namespace_path: params[:namespace_id], project_path: project_path,
|
2018-03-27 15:35:27 +00:00
|
|
|
redirected_path: redirected_path, auth_result_type: auth_result_type)
|
2018-01-18 09:31:00 +00:00
|
|
|
end
|
|
|
|
|
2017-05-16 19:58:46 +00:00
|
|
|
def access_actor
|
|
|
|
return user if user
|
|
|
|
return :ci if ci?
|
2016-06-27 16:14:44 +00:00
|
|
|
end
|
|
|
|
|
2016-08-03 12:54:12 +00:00
|
|
|
def access_check
|
2018-12-20 16:25:48 +00:00
|
|
|
access.check(git_command, Gitlab::GitAccess::ANY)
|
2018-02-02 15:27:30 +00:00
|
|
|
@project ||= access.project
|
2016-03-24 17:58:29 +00:00
|
|
|
end
|
2017-01-24 20:04:45 +00:00
|
|
|
|
|
|
|
def access_klass
|
2019-03-18 16:51:11 +00:00
|
|
|
@access_klass ||= repo_type.access_checker_class
|
2017-01-24 20:04:45 +00:00
|
|
|
end
|
2016-10-05 14:41:32 +00:00
|
|
|
|
2018-02-02 15:27:30 +00:00
|
|
|
def project_path
|
|
|
|
@project_path ||= params[:project_id].sub(/\.git$/, '')
|
2018-01-19 13:04:14 +00:00
|
|
|
end
|
|
|
|
|
2016-10-05 14:41:32 +00:00
|
|
|
def log_user_activity
|
|
|
|
Users::ActivityService.new(user, 'pull').execute
|
|
|
|
end
|
2016-03-23 17:34:16 +00:00
|
|
|
end
|