gitlab-org--gitlab-foss/lib/api/helpers/internal_helpers.rb
Alejandro Rodríguez c45341c816 Generate and handle a gl_repository param to pass around components
This new param allows us to share project information between components
that don't share or don't have access to the same filesystem
mountpoints, for example between Gitaly and Rails or between Rails and
Gitlab-Shell hooks. The previous parameters are still supported, but if
found, gl_repository is prefered. The old parameters should be deprecated
once all components support the new format.
2017-05-03 17:37:30 -03:00

47 lines
997 B
Ruby

module API
module Helpers
module InternalHelpers
def wiki?
set_project unless defined?(@wiki)
@wiki
end
def project
set_project unless defined?(@project)
@project
end
def ssh_authentication_abilities
[
:read_project,
:download_code,
:push_code
]
end
def parse_env
return {} if params[:env].blank?
JSON.parse(params[:env])
rescue JSON::ParserError
{}
end
def log_user_activity(actor)
commands = Gitlab::GitAccess::DOWNLOAD_COMMANDS
::Users::ActivityService.new(actor, 'Git SSH').execute if commands.include?(params[:action])
end
private
def set_project
if params[:gl_repository]
@project, @wiki = Gitlab::GlRepository.parse(params[:gl_repository])
else
@project, @wiki = Gitlab::RepoPath.parse(params[:project])
end
end
end
end
end