summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-06 12:42:25 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-06 13:10:10 +0200
commit7d4ae819130b7a1d1876bc33e585a52452fc4995 (patch)
treebf365b0029133e600b79226299cff68d0e558f23
parentb5757b7489672f61bb4ea770accaac1cb38e9ffd (diff)
downloadgitlab-shell-7d4ae819130b7a1d1876bc33e585a52452fc4995.tar.gz
Refactor GitlabShell#exec a bit.
-rw-r--r--lib/gitlab_shell.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index c26318a..7249836 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -7,6 +7,8 @@ class GitlabShell
class DisallowedCommandError < 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
def initialize(key_id, origin_cmd)
@@ -24,11 +26,7 @@ class GitlabShell
parse_cmd
- raise DisallowedCommandError unless git_cmds.include?(@git_cmd)
-
- status = api.check_access(@git_cmd, @repo_name, @key_id, '_any')
-
- raise AccessDeniedError, status.message unless status.allowed?
+ verify_access
process_cmd
@@ -59,6 +57,8 @@ class GitlabShell
args = Shellwords.shellwords(@origin_cmd)
@git_cmd = args.first
+ raise DisallowedCommandError unless GIT_COMMANDS.include?(@git_cmd)
+
if @git_cmd == 'git-annex-shell'
raise DisallowedCommandError unless @config.git_annex_enabled?
@@ -72,8 +72,10 @@ class GitlabShell
end
end
- def git_cmds
- %w(git-upload-pack git-receive-pack git-upload-archive git-annex-shell)
+ def verify_access
+ status = api.check_access(@git_cmd, @repo_name, @key_id, '_any')
+
+ raise AccessDeniedError, status.message unless status.allowed?
end
def process_cmd