gitlab-grack 2.0.0.pre → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +22 -3
- data/Gemfile +2 -7
- data/Gemfile.lock +8 -17
- data/Makefile +153 -0
- data/Procfile.example +3 -0
- data/README.md +292 -95
- data/Vagrantfile +41 -0
- data/database.yml.example +13 -0
- data/gitlab-openldap/.gitignore +1 -0
- data/gitlab-openldap/Makefile +40 -0
- data/gitlab-openldap/README.md +60 -0
- data/gitlab-openldap/bootstrap.ldif +36 -0
- data/gitlab-openldap/frontend.alt.example.com.ldif +109 -0
- data/gitlab-openldap/frontend.example.com.ldif +109 -0
- data/gitlab-openldap/run-slapd +3 -0
- data/gitlab-openldap/run-slapd-alt +3 -0
- data/redis/redis.conf.example +2 -0
- data/redis/resque.yml.example +2 -0
- data/support/edit-gitlab.yml +11 -0
- metadata +29 -25
- data/.gitmodules +0 -3
- data/.travis.yml +0 -14
- data/CHANGELOG +0 -2
- data/Rakefile +0 -27
- data/examples/dispatch.fcgi +0 -9
- data/grack.gemspec +0 -20
- data/install.txt +0 -60
- data/lib/grack.rb +0 -5
- data/lib/grack/auth.rb +0 -37
- data/lib/grack/bundle.rb +0 -20
- data/lib/grack/server.rb +0 -324
- data/lib/grack/version.rb +0 -3
- data/tests/main_test.rb +0 -239
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-grack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chacon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.5.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.5.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mocha
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.11'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.11'
|
41
41
|
description: Ruby/Rack Git Smart-HTTP Server Handler
|
@@ -45,23 +45,28 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
49
|
-
- .
|
50
|
-
- .travis.yml
|
51
|
-
- CHANGELOG
|
48
|
+
- ".gitignore"
|
49
|
+
- ".ssh/.gitkeep"
|
52
50
|
- Gemfile
|
53
51
|
- Gemfile.lock
|
52
|
+
- Makefile
|
53
|
+
- Procfile.example
|
54
54
|
- README.md
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
55
|
+
- Vagrantfile
|
56
|
+
- database.yml.example
|
57
|
+
- gitlab-openldap/.gitignore
|
58
|
+
- gitlab-openldap/Makefile
|
59
|
+
- gitlab-openldap/README.md
|
60
|
+
- gitlab-openldap/bootstrap.ldif
|
61
|
+
- gitlab-openldap/frontend.alt.example.com.ldif
|
62
|
+
- gitlab-openldap/frontend.example.com.ldif
|
63
|
+
- gitlab-openldap/run-slapd
|
64
|
+
- gitlab-openldap/run-slapd-alt
|
65
|
+
- gitlab-satellites/.gitkeep
|
66
|
+
- redis/redis.conf.example
|
67
|
+
- redis/resque.yml.example
|
68
|
+
- repositories/.gitkeep
|
69
|
+
- support/edit-gitlab.yml
|
65
70
|
homepage: https://github.com/gitlabhq/grack
|
66
71
|
licenses: []
|
67
72
|
metadata: {}
|
@@ -71,19 +76,18 @@ require_paths:
|
|
71
76
|
- lib
|
72
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
78
|
requirements:
|
74
|
-
- -
|
79
|
+
- - ">="
|
75
80
|
- !ruby/object:Gem::Version
|
76
81
|
version: '0'
|
77
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
83
|
requirements:
|
79
|
-
- -
|
84
|
+
- - ">"
|
80
85
|
- !ruby/object:Gem::Version
|
81
86
|
version: 1.3.1
|
82
87
|
requirements: []
|
83
88
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.
|
89
|
+
rubygems_version: 2.4.3
|
85
90
|
signing_key:
|
86
91
|
specification_version: 4
|
87
92
|
summary: Ruby/Rack Git Smart-HTTP Server Handler
|
88
|
-
test_files:
|
89
|
-
- tests/main_test.rb
|
93
|
+
test_files: []
|
data/.gitmodules
DELETED
data/.travis.yml
DELETED
data/CHANGELOG
DELETED
data/Rakefile
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
require "bundler/gem_tasks"
|
3
|
-
|
4
|
-
task :default => :test
|
5
|
-
|
6
|
-
desc "Run the tests."
|
7
|
-
task :test do
|
8
|
-
Dir.glob("tests/*_test.rb").each do |f|
|
9
|
-
system "ruby #{f}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
desc "Run test coverage."
|
14
|
-
task :rcov do
|
15
|
-
system "rcov tests/*_test.rb -i lib/git_http.rb -x rack -x Library -x tests"
|
16
|
-
system "open coverage/index.html"
|
17
|
-
end
|
18
|
-
|
19
|
-
namespace :grack do
|
20
|
-
desc "Start Grack"
|
21
|
-
task :start do
|
22
|
-
system "rackup config.ru -p 8080"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
desc "Start everything."
|
27
|
-
multitask :start => [ 'grack:start' ]
|
data/examples/dispatch.fcgi
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
|
3
|
-
require 'lib/git_http'
|
4
|
-
config = {
|
5
|
-
:project_root => "/opt",
|
6
|
-
:upload_pack => true,
|
7
|
-
:receive_pack => false,
|
8
|
-
}
|
9
|
-
Rack::Handler::FastCGI.run(GitHttp::App.new(config))
|
data/grack.gemspec
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/grack/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Scott Chacon"]
|
6
|
-
gem.email = ["schacon@gmail.com"]
|
7
|
-
gem.description = %q{Ruby/Rack Git Smart-HTTP Server Handler}
|
8
|
-
gem.summary = %q{Ruby/Rack Git Smart-HTTP Server Handler}
|
9
|
-
gem.homepage = "https://github.com/gitlabhq/grack"
|
10
|
-
|
11
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
-
gem.files = `git ls-files`.split("\n")
|
13
|
-
gem.test_files = `git ls-files -- tests/*`.split("\n")
|
14
|
-
gem.name = "gitlab-grack"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = Grack::VERSION
|
17
|
-
|
18
|
-
gem.add_dependency("rack", "~> 1.5.1")
|
19
|
-
gem.add_development_dependency("mocha", "~> 0.11")
|
20
|
-
end
|
data/install.txt
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
Installation
|
2
|
-
========================
|
3
|
-
|
4
|
-
** This documentation is not finished yet. I haven't tested all of
|
5
|
-
these and it's obviously incomplete - these are currently just notes.
|
6
|
-
|
7
|
-
FastCGI
|
8
|
-
---------------------------------------
|
9
|
-
Here is an example config from lighttpd server:
|
10
|
-
----
|
11
|
-
# main fastcgi entry
|
12
|
-
$HTTP["url"] =~ "^/myapp/.+$" {
|
13
|
-
fastcgi.server = ( "/myapp" =>
|
14
|
-
( "localhost" =>
|
15
|
-
( "bin-path" => "/var/www/localhost/cgi-bin/dispatch.fcgi",
|
16
|
-
"docroot" => "/var/www/localhost/htdocs/myapp",
|
17
|
-
"host" => "127.0.0.1",
|
18
|
-
"port" => 1026,
|
19
|
-
"check-local" => "disable"
|
20
|
-
)
|
21
|
-
)
|
22
|
-
)
|
23
|
-
} # HTTP[url]
|
24
|
-
----
|
25
|
-
You can use the examples/dispatch.fcgi file as your dispatcher.
|
26
|
-
|
27
|
-
(Example Apache setup?)
|
28
|
-
|
29
|
-
Installing in a Java application server
|
30
|
-
---------------------------------------
|
31
|
-
# install Warbler
|
32
|
-
$ sudo gem install warbler
|
33
|
-
$ cd gitsmart
|
34
|
-
$ (edit config.ru)
|
35
|
-
$ warble
|
36
|
-
$ cp gitsmart.war /path/to/java/autodeploy/dir
|
37
|
-
|
38
|
-
Unicorn
|
39
|
-
---------------------------------------
|
40
|
-
With Unicorn (http://unicorn.bogomips.org/) you can just run 'unicorn'
|
41
|
-
in the directory with the config.ru file.
|
42
|
-
|
43
|
-
Thin
|
44
|
-
---------------------------------------
|
45
|
-
thin.yml
|
46
|
-
---
|
47
|
-
pid: /home/deploy/myapp/server/thin.pid
|
48
|
-
log: /home/deploy/myapp/logs/thin.log
|
49
|
-
timeout: 30
|
50
|
-
port: 7654
|
51
|
-
max_conns: 1024
|
52
|
-
chdir: /home/deploy/myapp/site_files
|
53
|
-
rackup: /home/deploy/myapp/server/config.ru
|
54
|
-
max_persistent_conns: 512
|
55
|
-
environment: production
|
56
|
-
address: 127.0.0.1
|
57
|
-
servers: 1
|
58
|
-
daemonize: true
|
59
|
-
|
60
|
-
|
data/lib/grack.rb
DELETED
data/lib/grack/auth.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'rack/auth/basic'
|
2
|
-
require 'rack/auth/abstract/handler'
|
3
|
-
require 'rack/auth/abstract/request'
|
4
|
-
|
5
|
-
module Grack
|
6
|
-
class Auth < Rack::Auth::Basic
|
7
|
-
def call(env)
|
8
|
-
@env = env
|
9
|
-
@request = Rack::Request.new(env)
|
10
|
-
@auth = Request.new(env)
|
11
|
-
|
12
|
-
if not @auth.provided?
|
13
|
-
unauthorized
|
14
|
-
elsif not @auth.basic?
|
15
|
-
bad_request
|
16
|
-
else
|
17
|
-
result = if (access = valid? and access == true)
|
18
|
-
@env['REMOTE_USER'] = @auth.username
|
19
|
-
@app.call(env)
|
20
|
-
else
|
21
|
-
if access == '404'
|
22
|
-
render_not_found
|
23
|
-
elsif access == '403'
|
24
|
-
render_no_access
|
25
|
-
else
|
26
|
-
unauthorized
|
27
|
-
end
|
28
|
-
end
|
29
|
-
result
|
30
|
-
end
|
31
|
-
end# method call
|
32
|
-
|
33
|
-
def valid?
|
34
|
-
false
|
35
|
-
end
|
36
|
-
end# class Auth
|
37
|
-
end# module Grack
|
data/lib/grack/bundle.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'rack/builder'
|
2
|
-
require 'grack/auth'
|
3
|
-
require 'grack/server'
|
4
|
-
|
5
|
-
module Grack
|
6
|
-
module Bundle
|
7
|
-
extend self
|
8
|
-
|
9
|
-
def new(config)
|
10
|
-
Rack::Builder.new do
|
11
|
-
use Grack::Auth do |username, password|
|
12
|
-
false
|
13
|
-
end
|
14
|
-
|
15
|
-
run Grack::Server.new(config)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
data/lib/grack/server.rb
DELETED
@@ -1,324 +0,0 @@
|
|
1
|
-
require 'zlib'
|
2
|
-
require 'rack/request'
|
3
|
-
require 'rack/response'
|
4
|
-
require 'rack/utils'
|
5
|
-
require 'time'
|
6
|
-
|
7
|
-
module Grack
|
8
|
-
class Server
|
9
|
-
|
10
|
-
SERVICES = [
|
11
|
-
["POST", 'service_rpc', "(.*?)/git-upload-pack$", 'upload-pack'],
|
12
|
-
["POST", 'service_rpc', "(.*?)/git-receive-pack$", 'receive-pack'],
|
13
|
-
|
14
|
-
["GET", 'get_info_refs', "(.*?)/info/refs$"],
|
15
|
-
["GET", 'get_text_file', "(.*?)/HEAD$"],
|
16
|
-
["GET", 'get_text_file', "(.*?)/objects/info/alternates$"],
|
17
|
-
["GET", 'get_text_file', "(.*?)/objects/info/http-alternates$"],
|
18
|
-
["GET", 'get_info_packs', "(.*?)/objects/info/packs$"],
|
19
|
-
["GET", 'get_text_file', "(.*?)/objects/info/[^/]*$"],
|
20
|
-
["GET", 'get_loose_object', "(.*?)/objects/[0-9a-f]{2}/[0-9a-f]{38}$"],
|
21
|
-
["GET", 'get_pack_file', "(.*?)/objects/pack/pack-[0-9a-f]{40}\\.pack$"],
|
22
|
-
["GET", 'get_idx_file', "(.*?)/objects/pack/pack-[0-9a-f]{40}\\.idx$"],
|
23
|
-
]
|
24
|
-
|
25
|
-
def initialize(config = false)
|
26
|
-
set_config(config)
|
27
|
-
end
|
28
|
-
|
29
|
-
def set_config(config)
|
30
|
-
@config = config || {}
|
31
|
-
end
|
32
|
-
|
33
|
-
def set_config_setting(key, value)
|
34
|
-
@config[key] = value
|
35
|
-
end
|
36
|
-
|
37
|
-
def call(env)
|
38
|
-
@env = env
|
39
|
-
@req = Rack::Request.new(env)
|
40
|
-
|
41
|
-
cmd, path, @reqfile, @rpc = match_routing
|
42
|
-
|
43
|
-
return render_method_not_allowed if cmd == 'not_allowed'
|
44
|
-
return render_not_found if !cmd
|
45
|
-
|
46
|
-
@dir = get_git_dir(path)
|
47
|
-
return render_not_found if !@dir
|
48
|
-
|
49
|
-
Dir.chdir(@dir) do
|
50
|
-
self.method(cmd).call()
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# ---------------------------------
|
55
|
-
# actual command handling functions
|
56
|
-
# ---------------------------------
|
57
|
-
|
58
|
-
# Uses chunked (streaming) transfer, otherwise response
|
59
|
-
# blocks to calculate Content-Length header
|
60
|
-
# http://en.wikipedia.org/wiki/Chunked_transfer_encoding
|
61
|
-
|
62
|
-
CRLF = "\r\n"
|
63
|
-
|
64
|
-
def service_rpc
|
65
|
-
return render_no_access if !has_access(@rpc, true)
|
66
|
-
input = read_body
|
67
|
-
|
68
|
-
@res = Rack::Response.new
|
69
|
-
@res.status = 200
|
70
|
-
@res["Content-Type"] = "application/x-git-%s-result" % @rpc
|
71
|
-
@res["Transfer-Encoding"] = "chunked"
|
72
|
-
@res["Cache-Control"] = "no-cache"
|
73
|
-
|
74
|
-
@res.finish do
|
75
|
-
command = git_command("#{@rpc} --stateless-rpc #{@dir}")
|
76
|
-
IO.popen(command, File::RDWR) do |pipe|
|
77
|
-
pipe.write(input)
|
78
|
-
pipe.close_write
|
79
|
-
while !pipe.eof?
|
80
|
-
block = pipe.read(8192) # 8KB at a time
|
81
|
-
@res.write encode_chunk(block) # stream it to the client
|
82
|
-
end
|
83
|
-
@res.write terminating_chunk
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def encode_chunk(chunk)
|
89
|
-
size_in_hex = chunk.size.to_s(16)
|
90
|
-
[ size_in_hex, CRLF, chunk, CRLF ].join
|
91
|
-
end
|
92
|
-
|
93
|
-
def terminating_chunk
|
94
|
-
[ 0, CRLF, CRLF ].join
|
95
|
-
end
|
96
|
-
|
97
|
-
def get_info_refs
|
98
|
-
service_name = get_service_type
|
99
|
-
|
100
|
-
if has_access(service_name)
|
101
|
-
cmd = git_command("#{service_name} --stateless-rpc --advertise-refs .")
|
102
|
-
refs = `#{cmd}`
|
103
|
-
|
104
|
-
@res = Rack::Response.new
|
105
|
-
@res.status = 200
|
106
|
-
@res["Content-Type"] = "application/x-git-%s-advertisement" % service_name
|
107
|
-
hdr_nocache
|
108
|
-
@res.write(pkt_write("# service=git-#{service_name}\n"))
|
109
|
-
@res.write(pkt_flush)
|
110
|
-
@res.write(refs)
|
111
|
-
@res.finish
|
112
|
-
else
|
113
|
-
dumb_info_refs
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def dumb_info_refs
|
118
|
-
update_server_info
|
119
|
-
send_file(@reqfile, "text/plain; charset=utf-8") do
|
120
|
-
hdr_nocache
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def get_info_packs
|
125
|
-
# objects/info/packs
|
126
|
-
send_file(@reqfile, "text/plain; charset=utf-8") do
|
127
|
-
hdr_nocache
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def get_loose_object
|
132
|
-
send_file(@reqfile, "application/x-git-loose-object") do
|
133
|
-
hdr_cache_forever
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def get_pack_file
|
138
|
-
send_file(@reqfile, "application/x-git-packed-objects") do
|
139
|
-
hdr_cache_forever
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def get_idx_file
|
144
|
-
send_file(@reqfile, "application/x-git-packed-objects-toc") do
|
145
|
-
hdr_cache_forever
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def get_text_file
|
150
|
-
send_file(@reqfile, "text/plain") do
|
151
|
-
hdr_nocache
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
# ------------------------
|
156
|
-
# logic helping functions
|
157
|
-
# ------------------------
|
158
|
-
|
159
|
-
F = ::File
|
160
|
-
|
161
|
-
# some of this borrowed from the Rack::File implementation
|
162
|
-
def send_file(reqfile, content_type)
|
163
|
-
reqfile = File.join(@dir, reqfile)
|
164
|
-
return render_not_found if !F.exists?(reqfile)
|
165
|
-
|
166
|
-
@res = Rack::Response.new
|
167
|
-
@res.status = 200
|
168
|
-
@res["Content-Type"] = content_type
|
169
|
-
@res["Last-Modified"] = F.mtime(reqfile).httpdate
|
170
|
-
|
171
|
-
yield
|
172
|
-
|
173
|
-
if size = F.size?(reqfile)
|
174
|
-
@res["Content-Length"] = size.to_s
|
175
|
-
@res.finish do
|
176
|
-
F.open(reqfile, "rb") do |file|
|
177
|
-
while part = file.read(8192)
|
178
|
-
@res.write part
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
else
|
183
|
-
body = [F.read(reqfile)]
|
184
|
-
size = Rack::Utils.bytesize(body.first)
|
185
|
-
@res["Content-Length"] = size
|
186
|
-
@res.write body
|
187
|
-
@res.finish
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
def get_git_dir(path)
|
192
|
-
root = @config[:project_root] || `pwd`
|
193
|
-
path = File.join(root, path)
|
194
|
-
if File.exists?(path) # TODO: check is a valid git directory
|
195
|
-
return path
|
196
|
-
end
|
197
|
-
false
|
198
|
-
end
|
199
|
-
|
200
|
-
def get_service_type
|
201
|
-
service_type = @req.params['service']
|
202
|
-
return false if !service_type
|
203
|
-
return false if service_type[0, 4] != 'git-'
|
204
|
-
service_type.gsub('git-', '')
|
205
|
-
end
|
206
|
-
|
207
|
-
def match_routing
|
208
|
-
cmd = nil
|
209
|
-
path = nil
|
210
|
-
SERVICES.each do |method, handler, match, rpc|
|
211
|
-
if m = Regexp.new(match).match(@req.path_info)
|
212
|
-
return ['not_allowed'] if method != @req.request_method
|
213
|
-
cmd = handler
|
214
|
-
path = m[1]
|
215
|
-
file = @req.path_info.sub(path + '/', '')
|
216
|
-
return [cmd, path, file, rpc]
|
217
|
-
end
|
218
|
-
end
|
219
|
-
return nil
|
220
|
-
end
|
221
|
-
|
222
|
-
def has_access(rpc, check_content_type = false)
|
223
|
-
if check_content_type
|
224
|
-
return false if @req.content_type != "application/x-git-%s-request" % rpc
|
225
|
-
end
|
226
|
-
return false if !['upload-pack', 'receive-pack'].include? rpc
|
227
|
-
if rpc == 'receive-pack'
|
228
|
-
return @config[:receive_pack] if @config.include? :receive_pack
|
229
|
-
end
|
230
|
-
if rpc == 'upload-pack'
|
231
|
-
return @config[:upload_pack] if @config.include? :upload_pack
|
232
|
-
end
|
233
|
-
return get_config_setting(rpc)
|
234
|
-
end
|
235
|
-
|
236
|
-
def get_config_setting(service_name)
|
237
|
-
service_name = service_name.gsub('-', '')
|
238
|
-
setting = get_git_config("http.#{service_name}")
|
239
|
-
if service_name == 'uploadpack'
|
240
|
-
return setting != 'false'
|
241
|
-
else
|
242
|
-
return setting == 'true'
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
def get_git_config(config_name)
|
247
|
-
cmd = git_command("config #{config_name}")
|
248
|
-
`#{cmd}`.chomp
|
249
|
-
end
|
250
|
-
|
251
|
-
def read_body
|
252
|
-
if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/
|
253
|
-
input = Zlib::GzipReader.new(@req.body).read
|
254
|
-
else
|
255
|
-
input = @req.body.read
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
def update_server_info
|
260
|
-
cmd = git_command("update-server-info")
|
261
|
-
`#{cmd}`
|
262
|
-
end
|
263
|
-
|
264
|
-
def git_command(command)
|
265
|
-
git_bin = @config[:git_path] || 'git'
|
266
|
-
command = "#{git_bin} #{command}"
|
267
|
-
command
|
268
|
-
end
|
269
|
-
|
270
|
-
# --------------------------------------
|
271
|
-
# HTTP error response handling functions
|
272
|
-
# --------------------------------------
|
273
|
-
|
274
|
-
PLAIN_TYPE = {"Content-Type" => "text/plain"}
|
275
|
-
|
276
|
-
def render_method_not_allowed
|
277
|
-
if @env['SERVER_PROTOCOL'] == "HTTP/1.1"
|
278
|
-
[405, PLAIN_TYPE, ["Method Not Allowed"]]
|
279
|
-
else
|
280
|
-
[400, PLAIN_TYPE, ["Bad Request"]]
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
def render_not_found
|
285
|
-
[404, PLAIN_TYPE, ["Not Found"]]
|
286
|
-
end
|
287
|
-
|
288
|
-
def render_no_access
|
289
|
-
[403, PLAIN_TYPE, ["Forbidden"]]
|
290
|
-
end
|
291
|
-
|
292
|
-
|
293
|
-
# ------------------------------
|
294
|
-
# packet-line handling functions
|
295
|
-
# ------------------------------
|
296
|
-
|
297
|
-
def pkt_flush
|
298
|
-
'0000'
|
299
|
-
end
|
300
|
-
|
301
|
-
def pkt_write(str)
|
302
|
-
(str.size + 4).to_s(base=16).rjust(4, '0') + str
|
303
|
-
end
|
304
|
-
|
305
|
-
|
306
|
-
# ------------------------
|
307
|
-
# header writing functions
|
308
|
-
# ------------------------
|
309
|
-
|
310
|
-
def hdr_nocache
|
311
|
-
@res["Expires"] = "Fri, 01 Jan 1980 00:00:00 GMT"
|
312
|
-
@res["Pragma"] = "no-cache"
|
313
|
-
@res["Cache-Control"] = "no-cache, max-age=0, must-revalidate"
|
314
|
-
end
|
315
|
-
|
316
|
-
def hdr_cache_forever
|
317
|
-
now = Time.now().to_i
|
318
|
-
@res["Date"] = now.to_s
|
319
|
-
@res["Expires"] = (now + 31536000).to_s;
|
320
|
-
@res["Cache-Control"] = "public, max-age=31536000";
|
321
|
-
end
|
322
|
-
|
323
|
-
end
|
324
|
-
end
|