Commit 3599cb87 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'improve-project-mirror-api-code-quality' into 'master'

Improve project mirror API code quality

See merge request gitlab-org/gitlab!25345
parents 9a308d4b 87488907
...@@ -9,11 +9,11 @@ module API ...@@ -9,11 +9,11 @@ module API
@github_webhook_signature ||= headers['X-Hub-Signature'] @github_webhook_signature ||= headers['X-Hub-Signature']
end end
def authenticate_from_github_webhook! def render_invalid_github_signature!
return unless github_webhook_signature if Guest.can?(:read_project, project)
unauthorized!
unless valid_github_signature? else
Guest.can?(:read_project, project) ? unauthorized! : not_found! not_found!
end end
end end
...@@ -28,10 +28,16 @@ module API ...@@ -28,10 +28,16 @@ module API
end end
def authenticate_with_webhook_token! def authenticate_with_webhook_token!
if github_webhook_signature return not_found! unless project
not_found! unless project
authenticate_from_github_webhook! unless valid_github_signature?
render_invalid_github_signature!
end
end
def try_authenticate_with_webhook_token!
if github_webhook_signature
authenticate_with_webhook_token!
else else
authenticate! authenticate!
authorize_admin_project authorize_admin_project
...@@ -79,7 +85,7 @@ module API ...@@ -79,7 +85,7 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Triggers a pull mirror operation' desc 'Triggers a pull mirror operation'
post ":id/mirror/pull" do post ":id/mirror/pull" do
authenticate_with_webhook_token! try_authenticate_with_webhook_token!
break render_api_error!('The project is not mirrored', 400) unless project.mirror? break render_api_error!('The project is not mirrored', 400) unless project.mirror?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment