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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
c25630ee
Commit
c25630ee
authored
Aug 30, 2016
by
Patricio Cano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored handling of the `LfsToken` and added functionality to it to simplify external code.
parent
48f1a61f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
21 deletions
+46
-21
app/helpers/lfs_helper.rb
app/helpers/lfs_helper.rb
+1
-3
lib/api/internal.rb
lib/api/internal.rb
+11
-9
lib/gitlab/auth.rb
lib/gitlab/auth.rb
+10
-9
lib/gitlab/lfs_token.rb
lib/gitlab/lfs_token.rb
+8
-0
spec/lib/gitlab/lfs_token_spec.rb
spec/lib/gitlab/lfs_token_spec.rb
+16
-0
No files found.
app/helpers/lfs_helper.rb
View file @
c25630ee
...
@@ -25,9 +25,7 @@ module LfsHelper
...
@@ -25,9 +25,7 @@ module LfsHelper
def
lfs_download_access?
def
lfs_download_access?
return
false
unless
project
.
lfs_enabled?
return
false
unless
project
.
lfs_enabled?
return
true
if
project
.
public?
return
true
if
project
.
public?
||
ci?
||
lfs_deploy_key?
return
true
if
ci?
return
true
if
lfs_deploy_key?
(
user
&&
user
.
can?
(
:download_code
,
project
))
(
user
&&
user
.
can?
(
:download_code
,
project
))
end
end
...
...
lib/api/internal.rb
View file @
c25630ee
...
@@ -80,16 +80,18 @@ module API
...
@@ -80,16 +80,18 @@ module API
key
=
Key
.
find
(
params
[
:key_id
])
key
=
Key
.
find
(
params
[
:key_id
])
user
=
key
.
user
user
=
key
.
user
if
user
token_handler
=
token
=
Gitlab
::
LfsToken
.
new
(
user
).
generate
if
user
response
=
{
username:
user
.
username
,
lfs_token:
token
}
Gitlab
::
LfsToken
.
new
(
user
)
else
else
token
=
Gitlab
::
LfsToken
.
new
(
key
).
generate
Gitlab
::
LfsToken
.
new
(
key
)
response
=
{
username:
"lfs-deploy-key-
#{
key
.
id
}
"
,
lfs_token:
token
}
end
end
response
[
:repository_http_path
]
=
project
.
http_url_to_repo
{
response
username:
token_handler
.
actor_name
,
lfs_token:
token_handler
.
generate
,
repository_http_path:
project
.
http_url_to_repo
}
end
end
get
"/merge_request_urls"
do
get
"/merge_request_urls"
do
...
...
lib/gitlab/auth.rb
View file @
c25630ee
...
@@ -117,15 +117,16 @@ module Gitlab
...
@@ -117,15 +117,16 @@ module Gitlab
end
end
def
lfs_token_check
(
login
,
password
)
def
lfs_token_check
(
login
,
password
)
if
login
.
include?
(
'lfs-deploy-key'
)
actor
=
key
=
DeployKey
.
find
(
login
.
gsub
(
'lfs-deploy-key-'
,
''
))
if
login
.
include?
(
'lfs-deploy-key'
)
token
=
Gitlab
::
LfsToken
.
new
(
key
).
value
DeployKey
.
find
(
login
.
gsub
(
'lfs-deploy-key-'
,
''
))
Result
.
new
(
key
,
:lfs_deploy_token
)
if
key
&&
token
==
password
else
else
User
.
by_login
(
login
)
user
=
User
.
by_login
(
login
)
end
token
=
Gitlab
::
LfsToken
.
new
(
user
).
value
Result
.
new
(
user
,
:lfs_token
)
if
user
&&
token
==
password
token_handler
=
Gitlab
::
LfsToken
.
new
(
actor
)
end
Result
.
new
(
actor
,
token_handler
.
type
)
if
actor
&&
token_handler
.
value
==
password
end
end
end
end
end
end
...
...
lib/gitlab/lfs_token.rb
View file @
c25630ee
...
@@ -22,6 +22,14 @@ module Gitlab
...
@@ -22,6 +22,14 @@ module Gitlab
end
end
end
end
def
type
actor
.
is_a?
(
User
)
?
:lfs_token
:
:lfs_deploy_token
end
def
actor_name
actor
.
is_a?
(
User
)
?
actor
.
username
:
"lfs-deploy-key-
#{
actor
.
id
}
"
end
private
private
def
redis_key
def
redis_key
...
...
spec/lib/gitlab/lfs_token_spec.rb
View file @
c25630ee
...
@@ -23,6 +23,14 @@ describe Gitlab::LfsToken, lib: true do
...
@@ -23,6 +23,14 @@ describe Gitlab::LfsToken, lib: true do
let
(
:handler
)
{
described_class
.
new
(
actor
)
}
let
(
:handler
)
{
described_class
.
new
(
actor
)
}
it_behaves_like
'an LFS token generator'
it_behaves_like
'an LFS token generator'
it
'returns the correct username'
do
expect
(
handler
.
actor_name
).
to
eq
(
actor
.
username
)
end
it
'returns the correct token type'
do
expect
(
handler
.
type
).
to
eq
(
:lfs_token
)
end
end
end
context
'when the actor is a deploy key'
do
context
'when the actor is a deploy key'
do
...
@@ -30,6 +38,14 @@ describe Gitlab::LfsToken, lib: true do
...
@@ -30,6 +38,14 @@ describe Gitlab::LfsToken, lib: true do
let
(
:handler
)
{
described_class
.
new
(
actor
)
}
let
(
:handler
)
{
described_class
.
new
(
actor
)
}
it_behaves_like
'an LFS token generator'
it_behaves_like
'an LFS token generator'
it
'returns the correct username'
do
expect
(
handler
.
actor_name
).
to
eq
(
"lfs-deploy-key-
#{
actor
.
id
}
"
)
end
it
'returns the correct token type'
do
expect
(
handler
.
type
).
to
eq
(
:lfs_deploy_token
)
end
end
end
end
end
end
end
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