Commit 8f0f6762 authored by Douwe Maan's avatar Douwe Maan

Write GitlabAccess error to stderr.

parent 63efd092
...@@ -14,5 +14,8 @@ if GitlabAccess.new(repo_path, key_id, refs).exec && ...@@ -14,5 +14,8 @@ if GitlabAccess.new(repo_path, key_id, refs).exec &&
GitlabCustomHook.new.pre_receive(refs, repo_path) GitlabCustomHook.new.pre_receive(refs, repo_path)
exit 0 exit 0
else else
# reset GL_ID env since we stop git push here
ENV['GL_ID'] = nil
exit 1 exit 1
end end
...@@ -5,6 +5,8 @@ require_relative 'names_helper' ...@@ -5,6 +5,8 @@ require_relative 'names_helper'
require 'json' require 'json'
class GitlabAccess class GitlabAccess
class AccessDeniedError < StandardError; end
include NamesHelper include NamesHelper
attr_reader :config, :repo_path, :repo_name, :changes attr_reader :config, :repo_path, :repo_name, :changes
...@@ -18,19 +20,16 @@ class GitlabAccess ...@@ -18,19 +20,16 @@ class GitlabAccess
end end
def exec def exec
begin
status = api.check_access('git-receive-pack', @repo_name, @actor, @changes) status = api.check_access('git-receive-pack', @repo_name, @actor, @changes)
return true if status.allowed? raise AccessDeniedError, status.message unless status.allowed?
message = status.message true
rescue GitlabNet::ApiUnreachableError rescue GitlabNet::ApiUnreachableError
message = "Failed to authorize your Git request: internal API unreachable" $stderr.puts "GitLab: Failed to authorize your Git request: internal API unreachable"
end false
rescue AccessDeniedError => ex
# reset GL_ID env since we stop git push here $stderr.puts "GitLab: #{ex.message}"
ENV['GL_ID'] = nil
puts "GitLab: #{message}"
false false
end end
......
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