Commit f65c6802 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Fail early on invalid input (raise ... unless ...)

This intention of this change is to make the normal flow of execution
easier to read, and to prevent mistakes in deeply nested if-else trees.
parent 43b985d9
...@@ -18,7 +18,8 @@ class GitlabShell ...@@ -18,7 +18,8 @@ class GitlabShell
if @origin_cmd if @origin_cmd
parse_cmd parse_cmd
if git_cmds.include?(@git_cmd) raise DisallowedCommandError unless git_cmds.include?(@git_cmd)
ENV['GL_ID'] = @key_id ENV['GL_ID'] = @key_id
access = api.check_access(@git_cmd, @repo_name, @key_id, '_any') access = api.check_access(@git_cmd, @repo_name, @key_id, '_any')
...@@ -30,9 +31,6 @@ class GitlabShell ...@@ -30,9 +31,6 @@ class GitlabShell
$logger.warn message $logger.warn message
puts access.message puts access.message
end end
else
raise DisallowedCommandError
end
else else
puts "Welcome to GitLab, #{username}!" puts "Welcome to GitLab, #{username}!"
end end
...@@ -51,14 +49,12 @@ class GitlabShell ...@@ -51,14 +49,12 @@ class GitlabShell
@git_cmd = args.first @git_cmd = args.first
if @git_cmd == 'git-annex-shell' if @git_cmd == 'git-annex-shell'
if @config.git_annex_enabled? raise DisallowedCommandError unless @config.git_annex_enabled?
@repo_name = escape_path(args[2].sub(/\A\/~\//, '')) @repo_name = escape_path(args[2].sub(/\A\/~\//, ''))
# Make sure repository has git-annex enabled # Make sure repository has git-annex enabled
init_git_annex(@repo_name) init_git_annex(@repo_name)
else
raise DisallowedCommandError
end
else else
raise DisallowedCommandError unless args.count == 2 raise DisallowedCommandError unless args.count == 2
@repo_name = escape_path(args.last) @repo_name = escape_path(args.last)
...@@ -73,7 +69,8 @@ class GitlabShell ...@@ -73,7 +69,8 @@ class GitlabShell
repo_full_path = File.join(repos_path, repo_name) repo_full_path = File.join(repos_path, repo_name)
if @git_cmd == 'git-annex-shell' if @git_cmd == 'git-annex-shell'
if @config.git_annex_enabled? raise DisallowedCommandError unless @config.git_annex_enabled?
args = Shellwords.shellwords(@origin_cmd) args = Shellwords.shellwords(@origin_cmd)
parsed_args = parsed_args =
args.map do |arg| args.map do |arg|
...@@ -88,9 +85,6 @@ class GitlabShell ...@@ -88,9 +85,6 @@ class GitlabShell
$logger.info "gitlab-shell: executing git-annex command <#{parsed_args.join(' ')}> for #{log_username}." $logger.info "gitlab-shell: executing git-annex command <#{parsed_args.join(' ')}> for #{log_username}."
exec_cmd(*parsed_args) exec_cmd(*parsed_args)
else
raise DisallowedCommandError
end
else else
$logger.info "gitlab-shell: executing git command <#{@git_cmd} #{repo_full_path}> for #{log_username}." $logger.info "gitlab-shell: executing git command <#{@git_cmd} #{repo_full_path}> for #{log_username}."
exec_cmd(@git_cmd, repo_full_path) exec_cmd(@git_cmd, repo_full_path)
......
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