2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
class Projects::GitHttpController < Projects::GitHttpClientController
|
2017-08-17 22:00:37 +05:30
|
|
|
include WorkhorseRequest
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
before_action :access_check
|
|
|
|
|
|
|
|
rescue_from Gitlab::GitAccess::UnauthorizedError, with: :render_403
|
|
|
|
rescue_from Gitlab::GitAccess::NotFoundError, with: :render_404
|
2018-03-17 18:26:18 +05:30
|
|
|
rescue_from Gitlab::GitAccess::ProjectCreationError, with: :render_422
|
2018-12-13 13:39:08 +05:30
|
|
|
rescue_from Gitlab::GitAccess::TimeoutError, with: :render_503
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
# 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-09-10 17:25:29 +05:30
|
|
|
log_user_activity if upload_pack?
|
|
|
|
|
|
|
|
render_ok
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# POST /foo/bar.git/git-upload-pack (git pull)
|
|
|
|
def git_upload_pack
|
2017-09-10 17:25:29 +05:30
|
|
|
render_ok
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# POST /foo/bar.git/git-receive-pack" (git push)
|
|
|
|
def git_receive_pack
|
2017-09-10 17:25:29 +05:30
|
|
|
render_ok
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def download_request?
|
|
|
|
upload_pack?
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def upload_pack?
|
|
|
|
git_command == 'git-upload-pack'
|
|
|
|
end
|
|
|
|
|
|
|
|
def git_command
|
|
|
|
if action_name == 'info_refs'
|
|
|
|
params[:service]
|
|
|
|
else
|
|
|
|
action_name.dasherize
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_ok
|
2016-09-29 09:46:39 +05:30
|
|
|
set_workhorse_internal_api_content_type
|
2017-08-17 22:00:37 +05:30
|
|
|
render json: Gitlab::Workhorse.git_http_ok(repository, wiki?, user, action_name)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def render_403(exception)
|
|
|
|
render plain: exception.message, status: :forbidden
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def render_404(exception)
|
|
|
|
render plain: exception.message, status: :not_found
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def render_422(exception)
|
|
|
|
render plain: exception.message, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
def render_503(exception)
|
|
|
|
render plain: exception.message, status: :service_unavailable
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def access
|
2018-03-17 18:26:18 +05:30
|
|
|
@access ||= access_klass.new(access_actor, project,
|
|
|
|
'http', authentication_abilities: authentication_abilities,
|
|
|
|
namespace_path: params[:namespace_id], project_path: project_path,
|
2018-05-09 12:01:36 +05:30
|
|
|
redirected_path: redirected_path, auth_result_type: auth_result_type)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def access_actor
|
|
|
|
return user if user
|
|
|
|
return :ci if ci?
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def access_check
|
2019-02-13 22:33:31 +05:30
|
|
|
access.check(git_command, Gitlab::GitAccess::ANY)
|
2018-03-17 18:26:18 +05:30
|
|
|
@project ||= access.project
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
def access_klass
|
|
|
|
@access_klass ||= wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def project_path
|
|
|
|
@project_path ||= params[:project_id].sub(/\.git$/, '')
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def log_user_activity
|
|
|
|
Users::ActivityService.new(user, 'pull').execute
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|