Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
87488907
Commit
87488907
authored
Feb 17, 2020
by
Giorgenes Gelatti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve project mirror API code quality
parent
12ac49bf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
+15
-9
ee/lib/api/project_mirror.rb
ee/lib/api/project_mirror.rb
+15
-9
No files found.
ee/lib/api/project_mirror.rb
View file @
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?
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment