Commit 252a96d6 authored by Ash McKenzie's avatar Ash McKenzie

Tidy up GitlabShell

* Use constants for git commands
* private instead of protected
parent c4d63ab0
...@@ -6,7 +6,6 @@ require_relative 'gitlab_metrics' ...@@ -6,7 +6,6 @@ require_relative 'gitlab_metrics'
class GitlabShell # rubocop:disable Metrics/ClassLength class GitlabShell # rubocop:disable Metrics/ClassLength
GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-lfs-authenticate).freeze
GITALY_MIGRATED_COMMANDS = { GITALY_MIGRATED_COMMANDS = {
'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'), 'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'),
'git-upload-archive' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-archive'), 'git-upload-archive' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-archive'),
...@@ -16,6 +15,13 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -16,6 +15,13 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access
attr_reader :repo_path attr_reader :repo_path
GIT_UPLOAD_PACK_COMMAND = 'git-upload-pack'.freeze
GIT_RECEIVE_PACK_COMMAND = 'git-receive-pack'.freeze
GIT_UPLOAD_ARCHIVE_COMMAND = 'git-upload-archive'.freeze
GIT_LFS_AUTHENTICATE_COMMAND = 'git-lfs-authenticate'.freeze
GIT_COMMANDS = [GIT_UPLOAD_PACK_COMMAND, GIT_RECEIVE_PACK_COMMAND,
GIT_UPLOAD_ARCHIVE_COMMAND, GIT_LFS_AUTHENTICATE_COMMAND].freeze
def initialize(key_id) def initialize(key_id)
@key_id = key_id @key_id = key_id
...@@ -26,7 +32,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -26,7 +32,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
# ssh git@gitlab.example.com 'evil command', then origin_cmd contains # ssh git@gitlab.example.com 'evil command', then origin_cmd contains
# 'evil command'. # 'evil command'.
def exec(origin_cmd) def exec(origin_cmd)
unless origin_cmd if !origin_cmd || origin_cmd.empty?
puts "Welcome to GitLab, #{username}!" puts "Welcome to GitLab, #{username}!"
return true return true
end end
...@@ -46,20 +52,19 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -46,20 +52,19 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
false false
rescue AccessDeniedError => ex rescue AccessDeniedError => ex
$logger.warn('Access denied', command: origin_cmd, user: log_username) $logger.warn('Access denied', command: origin_cmd, user: log_username)
$stderr.puts "GitLab: #{ex.message}" $stderr.puts "GitLab: #{ex.message}"
false false
rescue DisallowedCommandError rescue DisallowedCommandError
$logger.warn('Denied disallowed command', command: origin_cmd, user: log_username) $logger.warn('Denied disallowed command', command: origin_cmd, user: log_username)
$stderr.puts 'GitLab: Disallowed command'
$stderr.puts "GitLab: Disallowed command"
false false
rescue InvalidRepositoryPathError rescue InvalidRepositoryPathError
$stderr.puts "GitLab: Invalid repository path" $stderr.puts 'GitLab: Invalid repository path'
false false
end end
protected private
def parse_cmd(args) def parse_cmd(args)
# Handle Git for Windows 2.14 using "git upload-pack" instead of git-upload-pack # Handle Git for Windows 2.14 using "git upload-pack" instead of git-upload-pack
......
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