diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab_access.rb | 8 | ||||
-rw-r--r-- | lib/object_dirs_helper.rb | 39 |
2 files changed, 41 insertions, 6 deletions
diff --git a/lib/gitlab_access.rb b/lib/gitlab_access.rb index 3cdeb3e..e1a5e35 100644 --- a/lib/gitlab_access.rb +++ b/lib/gitlab_access.rb @@ -3,6 +3,7 @@ require_relative 'gitlab_net' require_relative 'gitlab_access_status' require_relative 'names_helper' require_relative 'gitlab_metrics' +require_relative 'object_dirs_helper' require 'json' class GitlabAccess @@ -23,12 +24,7 @@ class GitlabAccess def exec status = GitlabMetrics.measure('check-access:git-receive-pack') do - env = { - "GIT_ALTERNATE_OBJECT_DIRECTORIES" => ENV["GIT_ALTERNATE_OBJECT_DIRECTORIES"], - "GIT_OBJECT_DIRECTORY" => ENV["GIT_OBJECT_DIRECTORY"] - } - - api.check_access('git-receive-pack', @gl_repository, @repo_path, @actor, @changes, @protocol, env: env.to_json) + api.check_access('git-receive-pack', @gl_repository, @repo_path, @actor, @changes, @protocol, env: ObjectDirsHelper.all_attributes.to_json) end raise AccessDeniedError, status.message unless status.allowed? diff --git a/lib/object_dirs_helper.rb b/lib/object_dirs_helper.rb new file mode 100644 index 0000000..e175a03 --- /dev/null +++ b/lib/object_dirs_helper.rb @@ -0,0 +1,39 @@ +require 'pathname' + +class ObjectDirsHelper + class << self + def all_attributes + { + "GIT_ALTERNATE_OBJECT_DIRECTORIES" => absolute_alt_object_dirs, + "GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE" => relative_alt_object_dirs, + "GIT_OBJECT_DIRECTORY" => absolute_object_dir, + "GIT_OBJECT_DIRECTORY_RELATIVE" => relative_object_dir + } + end + + def absolute_object_dir + ENV['GIT_OBJECT_DIRECTORY'] + end + + def relative_object_dir + relative_path(absolute_object_dir) + end + + def absolute_alt_object_dirs + ENV['GIT_ALTERNATE_OBJECT_DIRECTORIES'].to_s.split(File::PATH_SEPARATOR) + end + + def relative_alt_object_dirs + absolute_alt_object_dirs.map { |dir| relative_path(dir) }.compact + end + + private + + def relative_path(absolute_path) + return if absolute_path.nil? + + repo_dir = Dir.pwd + Pathname.new(absolute_path).relative_path_from(Pathname.new(repo_dir)).to_s + end + end +end |