Commit 7f44599ed0ddb1e01395f41e5f4bec869c2238e6
1 parent
86807b8e
Exists in
master
and in
4 other branches
integrate with gitlabhq authority
Showing
2 changed files
with
28 additions
and
5 deletions
Show diff stats
Gemfile.lock
config/initializers/grack_auth.rb
| ... | ... | @@ -2,7 +2,30 @@ module Grack |
| 2 | 2 | class Auth < Rack::Auth::Basic |
| 3 | 3 | |
| 4 | 4 | def valid? |
| 5 | - true | |
| 6 | - end | |
| 7 | - end | |
| 8 | -end | |
| 5 | + # Authentication with username and password | |
| 6 | + email, password = @auth.credentials | |
| 7 | + user = User.find_by_email(email) | |
| 8 | + return false unless user.valid_password?(password) | |
| 9 | + | |
| 10 | + # Find project by PATH_INFO from env | |
| 11 | + if m = /^\/([\w-]+).git/.match(@env['PATH_INFO']).to_a | |
| 12 | + return false unless project = Project.find_by_path(m.last) | |
| 13 | + end | |
| 14 | + | |
| 15 | + # Git upload and receive | |
| 16 | + if @env['REQUEST_METHOD'] == 'GET' | |
| 17 | + true | |
| 18 | + elsif @env['REQUEST_METHOD'] == 'POST' | |
| 19 | + if @env['REQUEST_URI'].end_with?('git-upload-pack') | |
| 20 | + return project.dev_access_for?(user) | |
| 21 | + elsif @env['REQUEST_URI'].end_with?('git-upload-pack') | |
| 22 | + #TODO master branch protection | |
| 23 | + return project.dev_access_for?(user) | |
| 24 | + else | |
| 25 | + false | |
| 26 | + end | |
| 27 | + end | |
| 28 | + | |
| 29 | + end# valid? | |
| 30 | + end# Auth | |
| 31 | +end# Grack | ... | ... |