summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/errors.rb1
-rw-r--r--lib/gitlab_shell.rb17
2 files changed, 9 insertions, 9 deletions
diff --git a/lib/errors.rb b/lib/errors.rb
index f504f56..9e4d27b 100644
--- a/lib/errors.rb
+++ b/lib/errors.rb
@@ -1 +1,2 @@
class AccessDeniedError < StandardError; end
+class InvalidRepositoryPathError < StandardError; end
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index 10a9256..0a73e04 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -14,7 +14,6 @@ class GitlabShell
include LogHelper
class DisallowedCommandError < StandardError; end
- class InvalidRepositoryPathError < StandardError; end
GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-lfs-authenticate).freeze
API_COMMANDS = %w(2fa_recovery_codes).freeze
@@ -28,7 +27,7 @@ class GitlabShell
# ssh git@gitlab.example.com 'evil command', then origin_cmd contains
# 'evil command'.
def exec(origin_cmd)
- unless origin_cmd
+ if !origin_cmd || origin_cmd.empty?
puts "Welcome to GitLab, #{username}!"
return true
end
@@ -49,10 +48,10 @@ class GitlabShell
false
rescue DisallowedCommandError
$logger.warn('Denied disallowed command', command: origin_cmd, user: log_username)
- $stderr.puts "GitLab: Disallowed command"
+ $stderr.puts 'GitLab: Disallowed command'
false
rescue InvalidRepositoryPathError
- $stderr.puts "GitLab: Invalid repository path"
+ $stderr.puts 'GitLab: Invalid repository path'
false
end
@@ -61,6 +60,10 @@ class GitlabShell
attr_accessor :repo_name, :command, :git_access
attr_reader :config, :key_id, :repo_path
+ def api
+ @api ||= GitlabNet.new
+ end
+
def parse_cmd(args)
# Handle Git for Windows 2.14 using "git upload-pack" instead of git-upload-pack
if args.length == 3 && args.first == 'git'
@@ -89,7 +92,7 @@ class GitlabShell
raise DisallowedCommandError
end
else
- raise DisallowedCommandError unless args.count == 2
+ raise DisallowedCommandError, 'Expected two arguments' unless args.count == 2
@repo_name = args.last
end
@@ -112,10 +115,6 @@ class GitlabShell
action.execute(command, args)
end
- def api
- GitlabNet.new
- end
-
def lfs_authenticate
lfs_access = api.lfs_authenticate(key_id, repo_name)
return unless lfs_access