Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
9add3fbb
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9add3fbb
编写于
4月 22, 2016
作者:
J
Jacob Vosmaer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Some changes after review from Rémy and Valery
上级
d3541da4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
28 deletion
+33
-28
app/controllers/projects/git_http_controller.rb
app/controllers/projects/git_http_controller.rb
+33
-28
未找到文件。
app/controllers/projects/git_http_controller.rb
浏览文件 @
9add3fbb
class
Projects::GitHttpController
<
Projects
::
ApplicationController
class
Projects::GitHttpController
<
Projects
::
ApplicationController
skip_before_action
:repository
skip_before_action
:repository
before_action
:authenticate_user
before_action
:authenticate_user
before_action
:project_found?
before_action
:ensure_project_found?
# We support two actions (git push and git pull) which use four
# GET /foo/bar.git/info/refs?service=git-upload-pack (git pull)
# different HTTP requests:
# GET /foo/bar.git/info/refs?service=git-receive-pack (git push)
#
def
info_refs
# - GET /foo/bar.git/info/refs?service=git-upload-pack (pull)
# - GET /foo/bar.git/info/refs?service=git-receive-pack (push)
# - POST /foo/bar.git/git-upload-pack (pull)
# - POST /foo/bar.git/git-receive-pack" (push)
#
# The Rails routes divide these four requests over three methods:
# info_refs, git_upload_pack, and git_receive_pack.
def
git_rpc
if
upload_pack?
&&
upload_pack_allowed?
if
upload_pack?
&&
upload_pack_allowed?
render_ok
render_ok
elsif
receive_pack?
&&
receive_pack_allowed?
elsif
receive_pack?
&&
receive_pack_allowed?
...
@@ -24,8 +15,22 @@ class Projects::GitHttpController < Projects::ApplicationController
...
@@ -24,8 +15,22 @@ class Projects::GitHttpController < Projects::ApplicationController
end
end
end
end
%i{info_refs git_receive_pack git_upload_pack}
.
each
do
|
method
|
# POST /foo/bar.git/git-upload-pack (git pull)
alias_method
method
,
:git_rpc
def
git_upload_pack
if
upload_pack?
&&
upload_pack_allowed?
render_ok
else
render_not_found
end
end
# POST /foo/bar.git/git-receive-pack" (git push)
def
git_receive_pack
if
receive_pack?
&&
receive_pack_allowed?
render_ok
else
render_not_found
end
end
end
private
private
...
@@ -34,7 +39,7 @@ class Projects::GitHttpController < Projects::ApplicationController
...
@@ -34,7 +39,7 @@ class Projects::GitHttpController < Projects::ApplicationController
return
if
project
&&
project
.
public?
&&
upload_pack?
return
if
project
&&
project
.
public?
&&
upload_pack?
authenticate_or_request_with_http_basic
do
|
login
,
password
|
authenticate_or_request_with_http_basic
do
|
login
,
password
|
return
@ci
=
true
if
ci_request?
(
login
,
password
)
return
@ci
=
true
if
valid_
ci_request?
(
login
,
password
)
@user
=
Gitlab
::
Auth
.
new
.
find
(
login
,
password
)
@user
=
Gitlab
::
Auth
.
new
.
find
(
login
,
password
)
@user
||=
oauth_access_token_check
(
login
,
password
)
@user
||=
oauth_access_token_check
(
login
,
password
)
...
@@ -42,19 +47,21 @@ class Projects::GitHttpController < Projects::ApplicationController
...
@@ -42,19 +47,21 @@ class Projects::GitHttpController < Projects::ApplicationController
end
end
end
end
def
project_found?
def
ensure_
project_found?
render_not_found
if
project
.
blank?
render_not_found
if
project
.
blank?
end
end
def
ci_request?
(
login
,
password
)
def
valid_
ci_request?
(
login
,
password
)
matched_login
=
/(?<s>^[a-zA-Z]*-ci)-token$/
.
match
(
login
)
matched_login
=
/(?<s
ervice
>^[a-zA-Z]*-ci)-token$/
.
match
(
login
)
if
project
&&
matched_login
.
present?
&&
upload_pack?
if
project
&&
matched_login
.
present?
&&
upload_pack?
underscored_service
=
matched_login
[
's'
].
underscore
underscored_service
=
matched_login
[
's
ervice
'
].
underscore
if
underscored_service
==
'gitlab_ci'
if
underscored_service
==
'gitlab_ci'
return
project
&&
project
.
valid_build_token?
(
password
)
return
project
&&
project
.
valid_build_token?
(
password
)
elsif
Service
.
available_services_names
.
include?
(
underscored_service
)
elsif
Service
.
available_services_names
.
include?
(
underscored_service
)
# We treat underscored_service as a trusted input because it is included
# in the Service.available_services_names whitelist.
service_method
=
"
#{
underscored_service
}
_service"
service_method
=
"
#{
underscored_service
}
_service"
service
=
project
.
send
(
service_method
)
service
=
project
.
send
(
service_method
)
...
@@ -126,6 +133,7 @@ class Projects::GitHttpController < Projects::ApplicationController
...
@@ -126,6 +133,7 @@ class Projects::GitHttpController < Projects::ApplicationController
return
id
.
slice
(
0
,
id
.
length
-
suffix
.
length
)
if
id
.
end_with?
(
suffix
)
return
id
.
slice
(
0
,
id
.
length
-
suffix
.
length
)
if
id
.
end_with?
(
suffix
)
end
end
# No valid id was found.
nil
nil
end
end
...
@@ -140,14 +148,14 @@ class Projects::GitHttpController < Projects::ApplicationController
...
@@ -140,14 +148,14 @@ class Projects::GitHttpController < Projects::ApplicationController
end
end
def
upload_pack?
def
upload_pack?
rpc
==
'git-upload-pack'
git_command
==
'git-upload-pack'
end
end
def
receive_pack?
def
receive_pack?
rpc
==
'git-receive-pack'
git_command
==
'git-receive-pack'
end
end
def
rpc
def
git_command
if
action_name
==
'info_refs'
if
action_name
==
'info_refs'
params
[
:service
]
params
[
:service
]
else
else
...
@@ -178,11 +186,8 @@ class Projects::GitHttpController < Projects::ApplicationController
...
@@ -178,11 +186,8 @@ class Projects::GitHttpController < Projects::ApplicationController
true
true
elsif
user
elsif
user
Gitlab
::
GitAccess
.
new
(
user
,
project
).
download_access_check
.
allowed?
Gitlab
::
GitAccess
.
new
(
user
,
project
).
download_access_check
.
allowed?
elsif
project
.
public?
# Allow clone/fetch for public projects
true
else
else
false
project
.
public?
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录