summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab_keys.rb2
-rw-r--r--lib/gitlab_net.rb10
-rw-r--r--lib/gitlab_projects.rb4
-rw-r--r--lib/gitlab_shell.rb2
-rw-r--r--lib/gitlab_update.rb36
5 files changed, 43 insertions, 11 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb
index 9931e90..a7e5a40 100644
--- a/lib/gitlab_keys.rb
+++ b/lib/gitlab_keys.rb
@@ -28,7 +28,7 @@ class GitlabKeys
end
def rm_key
- cmd = "sed -i '/#{@key_id}/d' #{auth_file}"
+ cmd = "sed -i '/shell #{@key_id}/d' #{auth_file}"
system(cmd)
end
end
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index a7d32cd..cc2c5a6 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -6,7 +6,9 @@ require_relative 'gitlab_config'
class GitlabNet
def allowed?(cmd, repo, key, ref)
project_name = repo.gsub("'", "")
- project_name = project_name.gsub(/\.git$/, "")
+ project_name = project_name.gsub(/\.git\Z/, "")
+ project_name = project_name.gsub(/\A\//, "")
+
key_id = key.gsub("key-", "")
url = "#{host}/allowed?key_id=#{key_id}&action=#{cmd}&ref=#{ref}&project=#{project_name}"
@@ -33,6 +35,10 @@ class GitlabNet
end
def get(url)
- Net::HTTP.get_response(URI.parse(url))
+ url = URI.parse(url)
+ http = Net::HTTP.new(url.host, url.port)
+ http.use_ssl = (url.port == 443)
+ request = Net::HTTP::Get.new(url.request_uri)
+ http.start {|http| http.request(request) }
end
end
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index 4cd337a..b9eb36a 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -41,8 +41,8 @@ class GitlabProjects
end
def import_project
- dir = @project_name.match(/[a-zA-Z\.\_\-]+\.git$/).to_s
- cmd = "cd #{@repos_path} && git clone --bare #{@project_name} #{dir} && #{create_hooks_cmd}"
+ @source = ARGV.shift
+ cmd = "cd #{@repos_path} && git clone --bare #{@source} #{@project_name} && #{create_hooks_cmd}"
system(cmd)
end
end
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index d821299..842714e 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -16,7 +16,7 @@ class GitlabShell
parse_cmd
if git_cmds.include?(@git_cmd)
- ENV['GL_USER'] = @key_id
+ ENV['GL_ID'] = @key_id
if validate_access
process_cmd
diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb
index cf3953e..156e385 100644
--- a/lib/gitlab_update.rb
+++ b/lib/gitlab_update.rb
@@ -3,21 +3,38 @@ require_relative 'gitlab_net'
class GitlabUpdate
def initialize(repo_path, key_id, refname)
+ @repo_path = repo_path.strip
@repo_name = repo_path
@repo_name.gsub!(GitlabConfig.new.repos_path.to_s, "")
@repo_name.gsub!(/.git$/, "")
@repo_name.gsub!(/^\//, "")
@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
def exec
- if api.allowed?('git-receive-pack', @repo_name, @key_id, @refname)
- exit 0
+ # reset GL_ID env since we already
+ # get value from it
+ ENV['GL_ID'] = nil
+
+ # If its push over ssh
+ # 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
- puts "GitLab: You are not allowed to access #{@refname}! "
- exit 1
+ update_redis
+ exit 0
end
end
@@ -26,4 +43,13 @@ class GitlabUpdate
def api
GitlabNet.new
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