debian-mirror-gitlab/app/controllers/projects/git_http_controller.rb

116 lines
2.5 KiB
Ruby
Raw Normal View History

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
# 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
if upload_pack? && upload_pack_allowed?
2017-08-17 22:00:37 +05:30
log_user_activity
render_ok
elsif receive_pack? && receive_pack_allowed?
render_ok
2016-08-24 12:49:21 +05:30
elsif http_blocked?
2016-09-13 17:45:13 +05:30
render_http_not_allowed
else
2016-09-13 17:45:13 +05:30
render_denied
end
end
# POST /foo/bar.git/git-upload-pack (git pull)
def git_upload_pack
if upload_pack? && upload_pack_allowed?
render_ok
else
2016-09-13 17:45:13 +05:30
render_denied
end
end
# POST /foo/bar.git/git-receive-pack" (git push)
def git_receive_pack
if receive_pack? && receive_pack_allowed?
render_ok
else
2016-09-13 17:45:13 +05:30
render_denied
end
end
private
2016-09-13 17:45:13 +05:30
def download_request?
upload_pack?
end
def upload_pack?
git_command == 'git-upload-pack'
end
def receive_pack?
git_command == 'git-receive-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)
end
2016-09-13 17:45:13 +05:30
def render_http_not_allowed
render plain: access_check.message, status: :forbidden
2016-08-24 12:49:21 +05:30
end
2016-09-13 17:45:13 +05:30
def render_denied
2017-08-17 22:00:37 +05:30
if user && can?(user, :read_project, project)
render plain: access_denied_message, status: :forbidden
2016-09-13 17:45:13 +05:30
else
# Do not leak information about project existence
render_not_found
end
end
2017-08-17 22:00:37 +05:30
def access_denied_message
'Access denied'
end
def upload_pack_allowed?
return false unless Gitlab.config.gitlab_shell.upload_pack
2016-11-24 13:41:30 +05:30
access_check.allowed? || ci?
end
2016-08-24 12:49:21 +05:30
def access
2017-08-17 22:00:37 +05:30
@access ||= access_klass.new(user, project, 'http', authentication_abilities: authentication_abilities)
2016-08-24 12:49:21 +05:30
end
2016-09-13 17:45:13 +05:30
def access_check
# Use the magic string '_any' to indicate we do not know what the
# changes are. This is also what gitlab-shell does.
@access_check ||= access.check(git_command, '_any')
2016-08-24 12:49:21 +05:30
end
def http_blocked?
!access.protocol_allowed?
end
def receive_pack_allowed?
return false unless Gitlab.config.gitlab_shell.receive_pack
2016-09-13 17:45:13 +05:30
access_check.allowed?
end
2017-08-17 22:00:37 +05:30
def access_klass
@access_klass ||= wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess
end
def log_user_activity
Users::ActivityService.new(user, 'pull').execute
end
end