Commit 9eb019045a8c1bb9f1cb6e8d3dfb7338ab2f921a

Authored by Dmitriy Zaporozhets
2 parents 3a4aff69 1df1daa1

Merge pull request #1016 from SaitoWu/feature/https

Feature/https
@@ -15,6 +15,7 @@ gem "gitolite", :git => "https://github.com/gitlabhq/gitolite-client.git", @@ -15,6 +15,7 @@ gem "gitolite", :git => "https://github.com/gitlabhq/gitolite-client.git",
15 gem "pygments.rb", :git => "https://github.com/gitlabhq/pygments.rb.git", :ref => "2cada028da5054616634a1d9ca6941b65b3ce188" 15 gem "pygments.rb", :git => "https://github.com/gitlabhq/pygments.rb.git", :ref => "2cada028da5054616634a1d9ca6941b65b3ce188"
16 gem "omniauth-ldap", :git => "https://github.com/gitlabhq/omniauth-ldap.git", :ref => "7edf27d0281e09561838122982c16b7e62181f44" 16 gem "omniauth-ldap", :git => "https://github.com/gitlabhq/omniauth-ldap.git", :ref => "7edf27d0281e09561838122982c16b7e62181f44"
17 gem 'yaml_db', :git => "https://github.com/gitlabhq/yaml_db.git" 17 gem 'yaml_db', :git => "https://github.com/gitlabhq/yaml_db.git"
  18 +gem 'grack', :git => "https://github.com/gitlabhq/grack.git"
18 gem "linguist", "~> 1.0.0", :git => "https://github.com/gitlabhq/linguist.git" 19 gem "linguist", "~> 1.0.0", :git => "https://github.com/gitlabhq/linguist.git"
19 20
20 gem "stamp" 21 gem "stamp"
@@ -14,6 +14,13 @@ GIT @@ -14,6 +14,13 @@ GIT
14 hashery (~> 1.4.0) 14 hashery (~> 1.4.0)
15 15
16 GIT 16 GIT
  17 + remote: https://github.com/gitlabhq/grack.git
  18 + revision: ba46f3b0845c6a09d488ae6abdce6ede37e227e8
  19 + specs:
  20 + grack (1.0.0)
  21 + rack (~> 1.4.1)
  22 +
  23 +GIT
17 remote: https://github.com/gitlabhq/grit.git 24 remote: https://github.com/gitlabhq/grit.git
18 revision: 7f35cb98ff17d534a07e3ce6ec3d580f67402837 25 revision: 7f35cb98ff17d534a07e3ce6ec3d580f67402837
19 ref: 7f35cb98ff17d534a07e3ce6ec3d580f67402837 26 ref: 7f35cb98ff17d534a07e3ce6ec3d580f67402837
@@ -373,6 +380,7 @@ DEPENDENCIES @@ -373,6 +380,7 @@ DEPENDENCIES
373 foreman 380 foreman
374 git 381 git
375 gitolite! 382 gitolite!
  383 + grack!
376 grit! 384 grit!
377 haml-rails 385 haml-rails
378 httparty 386 httparty
config/gitlab.yml.example
@@ -17,11 +17,15 @@ git_host: @@ -17,11 +17,15 @@ git_host:
17 base_path: /home/git/repositories/ 17 base_path: /home/git/repositories/
18 host: localhost 18 host: localhost
19 git_user: git 19 git_user: git
  20 + upload_pack: true
  21 + receive_pack: true
20 # port: 22 22 # port: 22
21 23
  24 +
22 # Git settings 25 # Git settings
23 # Use default values unless you understand it 26 # Use default values unless you understand it
24 git: 27 git:
  28 + path: /usr/bin/git
25 # Max size of git object like commit, in bytes 29 # Max size of git object like commit, in bytes
26 # This value can be increased if you have a very large commits 30 # This value can be increased if you have a very large commits
27 git_max_size: 5242880 # 5.megabytes 31 git_max_size: 5242880 # 5.megabytes
config/initializers/grack_auth.rb 0 → 100644
@@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
  1 +module Grack
  2 + class Auth < Rack::Auth::Basic
  3 +
  4 + def valid?
  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-receive-pack')
  22 + if project.protected_branches.map(&:name).include?(current_ref)
  23 + project.master_access_for?(user)
  24 + else
  25 + project.dev_access_for?(user)
  26 + end
  27 + else
  28 + false
  29 + end
  30 + else
  31 + false
  32 + end
  33 + end# valid?
  34 +
  35 + def current_ref
  36 + if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/
  37 + input = Zlib::GzipReader.new(@request.body).string
  38 + else
  39 + input = @request.body.string
  40 + end
  41 +
  42 + oldrev, newrev, ref = input.split(' ')
  43 + /refs\/heads\/([\w-]+)/.match(ref).to_a.last
  44 + end
  45 + end# Auth
  46 +end# Grack
config/routes.rb
@@ -8,6 +8,14 @@ Gitlab::Application.routes.draw do @@ -8,6 +8,14 @@ Gitlab::Application.routes.draw do
8 require 'resque/server' 8 require 'resque/server'
9 mount Resque::Server.new, at: '/info/resque' 9 mount Resque::Server.new, at: '/info/resque'
10 10
  11 + # Enable Grack support
  12 + mount Grack::Bundle.new({
  13 + git_path: GIT_OPTS['path'],
  14 + project_root: GIT_HOST['base_path'],
  15 + upload_pack: GIT_HOST['upload_pack'],
  16 + receive_pack: GIT_HOST['receive_pack']
  17 + }), at: '/git'
  18 +
11 # 19 #
12 # Help 20 # Help
13 # 21 #
@@ -20,15 +28,15 @@ Gitlab::Application.routes.draw do @@ -20,15 +28,15 @@ Gitlab::Application.routes.draw do
20 # Admin Area 28 # Admin Area
21 # 29 #
22 namespace :admin do 30 namespace :admin do
23 - resources :users do  
24 - member do 31 + resources :users do
  32 + member do
25 put :team_update 33 put :team_update
26 put :block 34 put :block
27 put :unblock 35 put :unblock
28 end 36 end
29 end 37 end
30 - resources :projects, :constraints => { :id => /[^\/]+/ } do  
31 - member do 38 + resources :projects, :constraints => { :id => /[^\/]+/ } do
  39 + member do
32 get :team 40 get :team
33 put :team_update 41 put :team_update
34 end 42 end
@@ -79,12 +87,12 @@ Gitlab::Application.routes.draw do @@ -79,12 +87,12 @@ Gitlab::Application.routes.draw do
79 87
80 resources :wikis, :only => [:show, :edit, :destroy, :create] do 88 resources :wikis, :only => [:show, :edit, :destroy, :create] do
81 member do 89 member do
82 - get "history" 90 + get "history"
83 end 91 end
84 end 92 end
85 93
86 - resource :repository do  
87 - member do 94 + resource :repository do
  95 + member do
88 get "branches" 96 get "branches"
89 get "tags" 97 get "tags"
90 get "archive" 98 get "archive"
@@ -94,14 +102,14 @@ Gitlab::Application.routes.draw do @@ -94,14 +102,14 @@ Gitlab::Application.routes.draw do
94 resources :deploy_keys 102 resources :deploy_keys
95 resources :protected_branches, :only => [:index, :create, :destroy] 103 resources :protected_branches, :only => [:index, :create, :destroy]
96 104
97 - resources :refs, :only => [], :path => "/" do  
98 - collection do 105 + resources :refs, :only => [], :path => "/" do
  106 + collection do
99 get "switch" 107 get "switch"
100 end 108 end
101 109
102 - member do 110 + member do
103 get "tree", :constraints => { :id => /[a-zA-Z.\/0-9_\-]+/ } 111 get "tree", :constraints => { :id => /[a-zA-Z.\/0-9_\-]+/ }
104 - get "blob", 112 + get "blob",
105 :constraints => { 113 :constraints => {
106 :id => /[a-zA-Z.0-9\/_\-]+/, 114 :id => /[a-zA-Z.0-9\/_\-]+/,
107 :path => /.*/ 115 :path => /.*/
@@ -126,36 +134,36 @@ Gitlab::Application.routes.draw do @@ -126,36 +134,36 @@ Gitlab::Application.routes.draw do
126 end 134 end
127 end 135 end
128 136
129 - resources :merge_requests do  
130 - member do 137 + resources :merge_requests do
  138 + member do
131 get :diffs 139 get :diffs
132 get :automerge 140 get :automerge
133 get :automerge_check 141 get :automerge_check
134 end 142 end
135 143
136 - collection do 144 + collection do
137 get :branch_from 145 get :branch_from
138 get :branch_to 146 get :branch_to
139 end 147 end
140 end 148 end
141 -  
142 - resources :snippets do  
143 - member do 149 +
  150 + resources :snippets do
  151 + member do
144 get "raw" 152 get "raw"
145 end 153 end
146 end 154 end
147 155
148 - resources :hooks, :only => [:index, :create, :destroy] do  
149 - member do 156 + resources :hooks, :only => [:index, :create, :destroy] do
  157 + member do
150 get :test 158 get :test
151 end 159 end
152 end 160 end
153 - resources :commits do  
154 - collection do 161 + resources :commits do
  162 + collection do
155 get :compare 163 get :compare
156 end 164 end
157 165
158 - member do 166 + member do
159 get :patch 167 get :patch
160 end 168 end
161 end 169 end