diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-04-13 11:36:49 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-04-13 11:36:49 +0300 |
commit | 7354e1b89b8303620549254b86a46159a329b583 (patch) | |
tree | 016f2dd50afc689bff1d5b546aec61c26f4a0e41 /lib | |
parent | 46b92499f1778775e31a1c27cfd1013586cd9cdf (diff) | |
parent | bf34fa788255454430cd9d1b9f45c2755258aabf (diff) | |
download | gitlab-shell-7354e1b89b8303620549254b86a46159a329b583.tar.gz |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-shell
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab_custom_hook.rb | 13 | ||||
-rw-r--r-- | lib/gitlab_post_receive.rb | 4 | ||||
-rw-r--r-- | lib/gitlab_shell.rb | 25 |
3 files changed, 18 insertions, 24 deletions
diff --git a/lib/gitlab_custom_hook.rb b/lib/gitlab_custom_hook.rb index a099e79..ac6837d 100644 --- a/lib/gitlab_custom_hook.rb +++ b/lib/gitlab_custom_hook.rb @@ -4,24 +4,21 @@ class GitlabCustomHook def pre_receive(changes, repo_path) hook = hook_file('pre-receive', repo_path) return true if hook.nil? - if call_receive_hook(hook, changes) - return true - else - # reset GL_ID env since we stop git push here - ENV['GL_ID'] = nil - return false - end + + call_receive_hook(hook, changes) end def post_receive(changes, repo_path) hook = hook_file('post-receive', repo_path) return true if hook.nil? - call_receive_hook(hook, changes) ? true : false + + call_receive_hook(hook, changes) end def update(ref_name, old_value, new_value, repo_path) hook = hook_file('update', repo_path) return true if hook.nil? + system(hook, ref_name, old_value, new_value) end diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb index 3c601ee..ede64f2 100644 --- a/lib/gitlab_post_receive.rb +++ b/lib/gitlab_post_receive.rb @@ -13,10 +13,6 @@ class GitlabPostReceive end def exec - # reset GL_ID env since we already - # get value from it - ENV['GL_ID'] = nil - result = update_redis begin diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb index d075048..7249836 100644 --- a/lib/gitlab_shell.rb +++ b/lib/gitlab_shell.rb @@ -7,11 +7,13 @@ 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 = /key-[0-9]+/.match(ARGV.join).to_s - @origin_cmd = ENV['SSH_ORIGINAL_COMMAND'] + def initialize(key_id, origin_cmd) + @key_id = key_id + @origin_cmd = origin_cmd @config = GitlabConfig.new @repos_path = @config.repos_path end @@ -24,12 +26,7 @@ class GitlabShell parse_cmd - raise DisallowedCommandError unless git_cmds.include?(@git_cmd) - - ENV['GL_ID'] = @key_id - status = api.check_access(@git_cmd, @repo_name, @key_id, '_any') - - raise AccessDeniedError, status.message unless status.allowed? + verify_access process_cmd @@ -60,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? @@ -73,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 @@ -105,7 +106,7 @@ class GitlabShell # This method is not covered by Rspec because it ends the current Ruby process. def exec_cmd(*args) - Kernel::exec({ 'PATH' => ENV['PATH'], 'LD_LIBRARY_PATH' => ENV['LD_LIBRARY_PATH'], 'GL_ID' => ENV['GL_ID'] }, *args, unsetenv_others: true) + Kernel::exec({ 'PATH' => ENV['PATH'], 'LD_LIBRARY_PATH' => ENV['LD_LIBRARY_PATH'], 'GL_ID' => @key_id }, *args, unsetenv_others: true) end def api |