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
6c308a02
Commit
6c308a02
authored
Mar 03, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract Gitlab::Geo::BaseTransfer
parent
f7c2df72
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
42 deletions
+49
-42
lib/gitlab/geo/base_request.rb
lib/gitlab/geo/base_request.rb
+35
-0
lib/gitlab/geo/jwt_request_decoder.rb
lib/gitlab/geo/jwt_request_decoder.rb
+3
-3
lib/gitlab/geo/transfer.rb
lib/gitlab/geo/transfer.rb
+4
-4
lib/gitlab/geo/transfer_request.rb
lib/gitlab/geo/transfer_request.rb
+3
-31
spec/lib/gitlab/geo/jwt_request_decoder_spec.rb
spec/lib/gitlab/geo/jwt_request_decoder_spec.rb
+2
-2
spec/requests/api/geo_spec.rb
spec/requests/api/geo_spec.rb
+1
-1
spec/services/geo/file_upload_service_spec.rb
spec/services/geo/file_upload_service_spec.rb
+1
-1
No files found.
lib/gitlab/geo/base_request.rb
0 → 100644
View file @
6c308a02
module
Gitlab
module
Geo
class
BaseRequest
GITLAB_GEO_AUTH_TOKEN_TYPE
=
'GL-Geo'
.
freeze
attr_reader
:request_data
def
initialize
(
request_data
=
{})
@request_data
=
request_data
end
def
headers
{
'Authorization'
=>
geo_auth_token
(
request_data
)
}
end
private
def
geo_auth_token
(
message
)
geo_node
=
requesting_node
return
unless
geo_node
payload
=
{
data:
message
.
to_json
,
iat:
Time
.
now
.
to_i
}
token
=
JWT
.
encode
(
payload
,
geo_node
.
secret_access_key
,
'HS256'
)
"
#{
GITLAB_GEO_AUTH_TOKEN_TYPE
}
#{
geo_node
.
access_key
}
:
#{
token
}
"
end
def
requesting_node
Gitlab
::
Geo
.
current_node
end
end
end
end
lib/gitlab/geo/jwt_request_decoder.rb
View file @
6c308a02
...
...
@@ -16,7 +16,7 @@ module Gitlab
private
def
decode_geo_request
# A Geo
transfer
request has an Authorization header:
# A Geo request has an Authorization header:
# Authorization: GL-Geo: <Geo Access Key>:<JWT payload>
#
# For example:
...
...
@@ -41,7 +41,7 @@ module Gitlab
data
&
.
deep_symbolize_keys!
data
rescue
JWT
::
DecodeError
=>
e
Rails
.
logger
.
error
(
"Error decoding Geo
transfer
request:
#{
e
}
"
)
Rails
.
logger
.
error
(
"Error decoding Geo request:
#{
e
}
"
)
end
end
...
...
@@ -58,7 +58,7 @@ module Gitlab
tokens
=
auth_header
.
split
(
' '
)
return
unless
tokens
.
count
==
2
return
unless
tokens
[
0
]
==
Gitlab
::
Geo
::
Transfer
Request
::
GITLAB_GEO_AUTH_TOKEN_TYPE
return
unless
tokens
[
0
]
==
Gitlab
::
Geo
::
Base
Request
::
GITLAB_GEO_AUTH_TOKEN_TYPE
# Split at the first occurence of a colon
geo_tokens
=
tokens
[
1
].
split
(
':'
,
2
)
...
...
lib/gitlab/geo/transfer.rb
View file @
6c308a02
...
...
@@ -20,11 +20,11 @@ module Gitlab
return
unless
primary
url
=
primary
.
geo_transfers_url
(
file_type
,
file_id
.
to_s
)
req_header
=
TransferRequest
.
new
(
request_data
).
header
req_header
s
=
TransferRequest
.
new
(
request_data
).
headers
return
unless
ensure_path_exists
download_file
(
url
,
req_header
)
download_file
(
url
,
req_header
s
)
end
private
...
...
@@ -56,12 +56,12 @@ module Gitlab
# Use HTTParty for now but switch to curb if performance becomes
# an issue
def
download_file
(
url
,
req_header
)
def
download_file
(
url
,
req_header
s
)
file_size
=
-
1
begin
File
.
open
(
filename
,
"wb"
)
do
|
file
|
response
=
HTTParty
.
get
(
url
,
headers:
req_header
,
stream_body:
true
)
do
|
fragment
|
response
=
HTTParty
.
get
(
url
,
headers:
req_header
s
,
stream_body:
true
)
do
|
fragment
|
file
.
write
(
fragment
)
end
...
...
lib/gitlab/geo/transfer_request.rb
View file @
6c308a02
module
Gitlab
module
Geo
class
TransferRequest
GITLAB_GEO_AUTH_TOKEN_TYPE
=
'GL-Geo'
.
freeze
attr_reader
:request_data
def
initialize
(
request_data
)
@request_data
=
request_data
end
def
header
{
"Authorization"
=>
geo_transfer_auth
(
request_data
.
to_json
),
"X-Sendfile-Type"
=>
"X-Sendfile"
}
end
private
def
geo_transfer_auth
(
message
)
geo_node
=
requesting_node
return
unless
geo_node
payload
=
{
data:
message
,
iat:
Time
.
now
.
to_i
}
token
=
JWT
.
encode
(
payload
,
geo_node
.
secret_access_key
,
'HS256'
)
"
#{
GITLAB_GEO_AUTH_TOKEN_TYPE
}
#{
geo_node
.
access_key
}
:
#{
token
}
"
end
def
requesting_node
Gitlab
::
Geo
.
current_node
class
TransferRequest
<
BaseRequest
def
headers
super
.
merge
({
'X-Sendfile-Type'
=>
'X-Sendfile'
})
end
end
end
...
...
spec/lib/gitlab/geo/jwt_request_decoder_spec.rb
View file @
6c308a02
...
...
@@ -5,7 +5,7 @@ describe Gitlab::Geo::JwtRequestDecoder do
let
(
:data
)
{
{
input:
123
}
}
let
(
:request
)
{
Gitlab
::
Geo
::
TransferRequest
.
new
(
data
)
}
subject
{
described_class
.
new
(
request
.
header
[
'Authorization'
])
}
subject
{
described_class
.
new
(
request
.
header
s
[
'Authorization'
])
}
describe
'#decode'
do
it
'decodes correct data'
do
...
...
@@ -13,7 +13,7 @@ describe Gitlab::Geo::JwtRequestDecoder do
end
it
'fails to decode with wrong key'
do
data
=
request
.
header
[
'Authorization'
]
data
=
request
.
header
s
[
'Authorization'
]
primary_node
.
secret_access_key
=
''
primary_node
.
save
...
...
spec/requests/api/geo_spec.rb
View file @
6c308a02
...
...
@@ -10,7 +10,7 @@ describe API::Geo, api: true do
end
before
(
:each
)
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:current_node
)
{
geo
_node
}
allow
(
Gitlab
::
Geo
).
to
receive
(
:current_node
)
{
primary
_node
}
end
describe
'POST /geo/receive_events authentication'
do
...
...
spec/services/geo/file_upload_service_spec.rb
View file @
6c308a02
...
...
@@ -5,7 +5,7 @@ describe Geo::FileUploadService, services: true do
let
(
:params
)
{
{
id:
lfs_object
.
id
,
type:
'lfs'
}
}
let
(
:lfs_transfer
)
{
Gitlab
::
Geo
::
LfsTransfer
.
new
(
lfs_object
)
}
let
(
:transfer_request
)
{
Gitlab
::
Geo
::
TransferRequest
.
new
(
lfs_transfer
.
request_data
)
}
let
(
:req_header
)
{
transfer_request
.
header
[
'Authorization'
]
}
let
(
:req_header
)
{
transfer_request
.
header
s
[
'Authorization'
]
}
before
do
create
(
:geo_node
,
:current
)
...
...
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