Commit 12331a55 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use update hook to add post event to redis. Use GL_ID instead of GL_USER

parent ba68af63
v1.0.4
- requires gitlab b698094
- dont use post-receive file any more. Make all updates in update
- fixed issue with invalid GL_USER
- use GL_ID instead of GL_USER
#!/usr/bin/env bash #!/usr/bin/env ruby
# This file was placed here by GitLab. It makes sure that your pushed commits # This file was placed here by GitLab.
# will be processed properly. # IT IS DEPRECATED NOW.
# All GitLab logic handled by update hook
while read oldrev newrev ref
do
# For every branch or tag that was pushed, create a Resque job in redis.
repo_path=`pwd`
env -i redis-cli rpush "resque:gitlab:queue:post_receive" "{\"class\":\"PostReceive\",\"args\":[\"$repo_path\",\"$oldrev\",\"$newrev\",\"$ref\",\"$GL_USER\"]}" > /dev/null 2>&1
done
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# will be processed properly. # will be processed properly.
refname = ARGV[0] refname = ARGV[0]
key_id = ENV['GL_USER'] key_id = ENV['GL_ID']
repo_path = `pwd` repo_path = `pwd`
require_relative '../lib/gitlab_update' require_relative '../lib/gitlab_update'
......
...@@ -16,7 +16,7 @@ class GitlabShell ...@@ -16,7 +16,7 @@ class GitlabShell
parse_cmd parse_cmd
if git_cmds.include?(@git_cmd) if git_cmds.include?(@git_cmd)
ENV['GL_USER'] = @key_id ENV['GL_ID'] = @key_id
if validate_access if validate_access
process_cmd process_cmd
......
...@@ -3,33 +3,38 @@ require_relative 'gitlab_net' ...@@ -3,33 +3,38 @@ require_relative 'gitlab_net'
class GitlabUpdate class GitlabUpdate
def initialize(repo_path, key_id, refname) def initialize(repo_path, key_id, refname)
@repo_path = repo_path.strip
@repo_name = repo_path @repo_name = repo_path
@repo_name.gsub!(GitlabConfig.new.repos_path.to_s, "") @repo_name.gsub!(GitlabConfig.new.repos_path.to_s, "")
@repo_name.gsub!(/.git$/, "") @repo_name.gsub!(/.git$/, "")
@repo_name.gsub!(/^\//, "") @repo_name.gsub!(/^\//, "")
@key_id = key_id @key_id = key_id
@refname = /refs\/heads\/([\w\.-]+)/.match(refname).to_a.last @refname = refname
@branch_name = /refs\/heads\/([\w\.-]+)/.match(refname).to_a.last
@oldrev = ARGV[1]
@newrev = ARGV[2]
end end
def exec def exec
# Skip update hook for local push when key_id is nil # reset GL_USER env since we already
# It required for gitlab instance to make local pushes # get value from it
# without validation of access ENV['GL_ID'] = nil
exit 0 if @key_id.nil?
# Also skip update hook for non-gitlab keys
# and reset GL_USER env
unless @key_id =~ /\Akey\-\d+\Z/
ENV['GL_USER'] = nil
exit 0
end
if api.allowed?('git-receive-pack', @repo_name, @key_id, @refname) # If its push over ssh
exit 0 # we need to check user persmission per branch first
if ssh?
if api.allowed?('git-receive-pack', @repo_name, @key_id, @branch_name)
update_redis
exit 0
else
puts "GitLab: You are not allowed to access #{@branch_name}! "
exit 1
end
else else
puts "GitLab: You are not allowed to access #{@refname}! " update_redis
exit 1 exit 0
end end
end end
...@@ -38,4 +43,13 @@ class GitlabUpdate ...@@ -38,4 +43,13 @@ class GitlabUpdate
def api def api
GitlabNet.new GitlabNet.new
end end
def ssh?
@key_id =~ /\Akey\-\d+\Z/
end
def update_redis
command = "env -i redis-cli rpush 'resque:gitlab:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1"
system(command)
end
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