summaryrefslogtreecommitdiff
path: root/lib/api/helpers/internal_helpers.rb
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-04-28 13:52:09 -0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-05-03 17:37:30 -0300
commitc45341c816d78d51aee84a6068d778b9cbc502c8 (patch)
tree769202931229d2e799bdd0f4a8d7c6e8f9ba8ff8 /lib/api/helpers/internal_helpers.rb
parentc1e2da9293bb036280c05ee6b99952b067bdc316 (diff)
downloadgitlab-ce-c45341c816d78d51aee84a6068d778b9cbc502c8.tar.gz
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.
Diffstat (limited to 'lib/api/helpers/internal_helpers.rb')
-rw-r--r--lib/api/helpers/internal_helpers.rb52
1 files changed, 14 insertions, 38 deletions
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index 718f936a1fc..264df7271a3 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -1,48 +1,14 @@
module API
module Helpers
module InternalHelpers
- # Project paths may be any of the following:
- # * /repository/storage/path/namespace/project
- # * /namespace/project
- # * namespace/project
- #
- # In addition, they may have a '.git' extension and multiple namespaces
- #
- # Transform all these cases to 'namespace/project'
- def clean_project_path(project_path, storages = Gitlab.config.repositories.storages.values)
- project_path = project_path.sub(/\.git\z/, '')
-
- storages.each do |storage|
- storage_path = File.expand_path(storage['path'])
-
- if project_path.start_with?(storage_path)
- project_path = project_path.sub(storage_path, '')
- break
- end
- end
-
- project_path.sub(/\A\//, '')
- end
-
- def project_path
- @project_path ||= clean_project_path(params[:project])
- end
-
def wiki?
- @wiki ||= project_path.end_with?('.wiki') &&
- !Project.find_by_full_path(project_path)
+ set_project unless defined?(@wiki)
+ @wiki
end
def project
- @project ||= begin
- # Check for *.wiki repositories.
- # Strip out the .wiki from the pathname before finding the
- # project. This applies the correct project permissions to
- # the wiki repository as well.
- project_path.chomp!('.wiki') if wiki?
-
- Project.find_by_full_path(project_path)
- end
+ set_project unless defined?(@project)
+ @project
end
def ssh_authentication_abilities
@@ -66,6 +32,16 @@ module API
::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