Commit 7d4ae819 authored by Douwe Maan's avatar Douwe Maan

Refactor GitlabShell#exec a bit.

parent b5757b74
...@@ -7,6 +7,8 @@ class GitlabShell ...@@ -7,6 +7,8 @@ class GitlabShell
class DisallowedCommandError < StandardError; end class DisallowedCommandError < StandardError; end
class InvalidRepositoryPathError < StandardError; end class InvalidRepositoryPathError < StandardError; end
GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-annex-shell).freeze
attr_accessor :key_id, :repo_name, :git_cmd, :repos_path, :repo_name attr_accessor :key_id, :repo_name, :git_cmd, :repos_path, :repo_name
def initialize(key_id, origin_cmd) def initialize(key_id, origin_cmd)
...@@ -24,11 +26,7 @@ class GitlabShell ...@@ -24,11 +26,7 @@ class GitlabShell
parse_cmd parse_cmd
raise DisallowedCommandError unless git_cmds.include?(@git_cmd) verify_access
status = api.check_access(@git_cmd, @repo_name, @key_id, '_any')
raise AccessDeniedError, status.message unless status.allowed?
process_cmd process_cmd
...@@ -59,6 +57,8 @@ class GitlabShell ...@@ -59,6 +57,8 @@ class GitlabShell
args = Shellwords.shellwords(@origin_cmd) args = Shellwords.shellwords(@origin_cmd)
@git_cmd = args.first @git_cmd = args.first
raise DisallowedCommandError unless GIT_COMMANDS.include?(@git_cmd)
if @git_cmd == 'git-annex-shell' if @git_cmd == 'git-annex-shell'
raise DisallowedCommandError unless @config.git_annex_enabled? raise DisallowedCommandError unless @config.git_annex_enabled?
...@@ -72,8 +72,10 @@ class GitlabShell ...@@ -72,8 +72,10 @@ class GitlabShell
end end
end end
def git_cmds def verify_access
%w(git-upload-pack git-receive-pack git-upload-archive git-annex-shell) status = api.check_access(@git_cmd, @repo_name, @key_id, '_any')
raise AccessDeniedError, status.message unless status.allowed?
end end
def process_cmd def process_cmd
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment