summaryrefslogtreecommitdiff
path: root/lib/gitlab_shell.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-04-09 10:25:18 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-04-09 10:25:18 +0000
commit2956630ab17fdaa2f29b98c5b5114809adfe1b37 (patch)
tree436f8840ecdd060f20d282bd7165fa4765c277fa /lib/gitlab_shell.rb
parent63efd0927224a7b3a6df7b83d452baab443d3d90 (diff)
parentf64e5d4a075479846f2e18bb34b84eb26d180f57 (diff)
downloadgitlab-shell-2956630ab17fdaa2f29b98c5b5114809adfe1b37.tar.gz
Merge branch 'nice-error-message' into 'master'
Write errors to stderr to get git to abort and show them as such. Addresses private issues https://dev.gitlab.org/gitlab/gitlab-shell/issues/33 and https://dev.gitlab.org/gitlab/gitlabhq/issues/2195. ![Screen_Shot_2015-04-06_at_13.05.43](https://gitlab.com/gitlab-org/gitlab-shell/uploads/56a4b9f4cc983da93afeb2b85252ec7e/Screen_Shot_2015-04-06_at_13.05.43.png) See merge request !8
Diffstat (limited to 'lib/gitlab_shell.rb')
-rw-r--r--lib/gitlab_shell.rb48
1 files changed, 30 insertions, 18 deletions
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index 806e016..d075048 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -3,7 +3,9 @@ require 'shellwords'
require_relative 'gitlab_net'
class GitlabShell
+ class AccessDeniedError < StandardError; end
class DisallowedCommandError < StandardError; end
+ class InvalidRepositoryPathError < StandardError; end
attr_accessor :key_id, :repo_name, :git_cmd, :repos_path, :repo_name
@@ -15,31 +17,41 @@ class GitlabShell
end
def exec
- if @origin_cmd
- parse_cmd
+ unless @origin_cmd
+ puts "Welcome to GitLab, #{username}!"
+ return true
+ end
- raise DisallowedCommandError unless git_cmds.include?(@git_cmd)
+ parse_cmd
- ENV['GL_ID'] = @key_id
+ raise DisallowedCommandError unless git_cmds.include?(@git_cmd)
- access = api.check_access(@git_cmd, @repo_name, @key_id, '_any')
+ ENV['GL_ID'] = @key_id
+ status = api.check_access(@git_cmd, @repo_name, @key_id, '_any')
- if access.allowed?
- process_cmd
- else
- message = "gitlab-shell: Access denied for git command <#{@origin_cmd}> by #{log_username}."
- $logger.warn message
- puts access.message
- end
- else
- puts "Welcome to GitLab, #{username}!"
- end
+ raise AccessDeniedError, status.message unless status.allowed?
+
+ process_cmd
+
+ true
rescue GitlabNet::ApiUnreachableError => ex
- puts "Failed to authorize your Git request: internal API unreachable"
+ $stderr.puts "GitLab: Failed to authorize your Git request: internal API unreachable"
+ false
+ rescue AccessDeniedError => ex
+ message = "gitlab-shell: Access denied for git command <#{@origin_cmd}> by #{log_username}."
+ $logger.warn message
+
+ $stderr.puts "GitLab: #{ex.message}"
+ false
rescue DisallowedCommandError => ex
message = "gitlab-shell: Attempt to execute disallowed command <#{@origin_cmd}> by #{log_username}."
$logger.warn message
- puts 'Disallowed command'
+
+ $stderr.puts "GitLab: Disallowed command"
+ false
+ rescue InvalidRepositoryPathError => ex
+ $stderr.puts "GitLab: Invalid repository path"
+ false
end
protected
@@ -125,7 +137,7 @@ class GitlabShell
if File.absolute_path(full_repo_path) == full_repo_path
path
else
- abort "Wrong repository path"
+ raise InvalidRepositoryPathError
end
end