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
42ea9799
Commit
42ea9799
authored
Mar 17, 2020
by
Ash McKenzie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Geo redirect message for all secondary HTTP pushes
parent
06dfc9ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
ee/lib/ee/api/internal/base.rb
ee/lib/ee/api/internal/base.rb
+14
-0
ee/spec/requests/api/internal/base_spec.rb
ee/spec/requests/api/internal/base_spec.rb
+21
-2
No files found.
ee/lib/ee/api/internal/base.rb
View file @
42ea9799
...
...
@@ -18,6 +18,7 @@ module EE
override
:ee_post_receive_response_hook
def
ee_post_receive_response_hook
(
response
)
response
.
add_basic_message
(
geo_redirect_to_primary_message
)
if
display_geo_redirect_to_primary_message?
response
.
add_basic_message
(
geo_secondary_lag_message
)
if
geo_display_secondary_lag_message?
end
...
...
@@ -41,6 +42,19 @@ module EE
end
end
def
display_geo_redirect_to_primary_message?
::
Gitlab
::
Geo
.
primary?
&&
geo_redirect_to_primary_message
end
def
geo_redirect_to_primary_message
return
unless
geo_referred_node
@geo_redirect_to_primary_message
||=
begin
url
=
"
#{
::
Gitlab
::
Geo
.
current_node
.
url
.
chomp
(
'/'
)
}
/
#{
project
.
full_path
}
.git"
::
Gitlab
::
Geo
.
redirecting_push_to_primary_message
(
url
)
end
end
override
:check_allowed
def
check_allowed
(
params
)
ip
=
params
.
fetch
(
:check_ip
,
nil
)
...
...
ee/spec/requests/api/internal/base_spec.rb
View file @
42ea9799
...
...
@@ -4,8 +4,10 @@ require 'spec_helper'
describe
API
::
Internal
::
Base
do
include
EE
::
GeoHelpers
let_it_be
(
:primary_node
,
reload:
true
)
{
create
(
:geo_node
,
:primary
)
}
let_it_be
(
:secondary_node
,
reload:
true
)
{
create
(
:geo_node
)
}
let_it_be
(
:primary_url
)
{
'http://primary.example.com'
}
let_it_be
(
:secondary_url
)
{
'http://secondary.example.com'
}
let_it_be
(
:primary_node
,
reload:
true
)
{
create
(
:geo_node
,
:primary
,
url:
primary_url
)
}
let_it_be
(
:secondary_node
,
reload:
true
)
{
create
(
:geo_node
,
url:
secondary_url
)
}
describe
'POST /internal/post_receive'
,
:geo
do
let_it_be
(
:user
)
{
create
(
:user
)
}
...
...
@@ -96,6 +98,23 @@ describe API::Internal::Base do
expect
(
json_response
[
'messages'
]).
not_to
include
({
'message'
=>
a_string_matching
(
'replication lag'
),
'type'
=>
anything
})
end
end
it
'includes a message advising a redirection occurred'
do
redirect_message
=
<<~
STR
You're pushing to a Geo secondary! We'll help you by redirecting this
request to the primary:
http://primary.example.com/
#{
project
.
full_path
}
.git
STR
post
api
(
'/internal/post_receive'
),
params:
valid_params
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'messages'
]).
to
include
({
'type'
=>
'basic'
,
'message'
=>
redirect_message
})
end
end
context
'when the push was not redirected from a Geo secondary to the primary'
do
...
...
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