integrate with gitlabhq authority
This commit is contained in:
parent
86807b8ecc
commit
7f44599ed0
2 changed files with 28 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
GIT
|
GIT
|
||||||
remote: https://github.com/SaitoWu/grack.git
|
remote: https://github.com/SaitoWu/grack.git
|
||||||
revision: dd990d231ac9189046b71a65d874638e55320e27
|
revision: ba46f3b0845c6a09d488ae6abdce6ede37e227e8
|
||||||
specs:
|
specs:
|
||||||
grack (1.0.0)
|
grack (1.0.0)
|
||||||
rack (~> 1.4.1)
|
rack (~> 1.4.1)
|
||||||
|
|
|
@ -2,7 +2,30 @@ module Grack
|
||||||
class Auth < Rack::Auth::Basic
|
class Auth < Rack::Auth::Basic
|
||||||
|
|
||||||
def valid?
|
def valid?
|
||||||
|
# Authentication with username and password
|
||||||
|
email, password = @auth.credentials
|
||||||
|
user = User.find_by_email(email)
|
||||||
|
return false unless user.valid_password?(password)
|
||||||
|
|
||||||
|
# Find project by PATH_INFO from env
|
||||||
|
if m = /^\/([\w-]+).git/.match(@env['PATH_INFO']).to_a
|
||||||
|
return false unless project = Project.find_by_path(m.last)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Git upload and receive
|
||||||
|
if @env['REQUEST_METHOD'] == 'GET'
|
||||||
true
|
true
|
||||||
|
elsif @env['REQUEST_METHOD'] == 'POST'
|
||||||
|
if @env['REQUEST_URI'].end_with?('git-upload-pack')
|
||||||
|
return project.dev_access_for?(user)
|
||||||
|
elsif @env['REQUEST_URI'].end_with?('git-upload-pack')
|
||||||
|
#TODO master branch protection
|
||||||
|
return project.dev_access_for?(user)
|
||||||
|
else
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
end# valid?
|
||||||
|
end# Auth
|
||||||
|
end# Grack
|
||||||
|
|
Loading…
Add table
Reference in a new issue