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
Jérome Perrin
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
Show 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
def
lfs_download_access?
return
false
unless
project
.
lfs_enabled?
return
true
if
project
.
public?
return
true
if
ci?
return
true
if
lfs_deploy_key?
return
true
if
project
.
public?
||
ci?
||
lfs_deploy_key?
(
user
&&
user
.
can?
(
:download_code
,
project
))
end
...
...
lib/api/internal.rb
View file @
c25630ee
...
...
@@ -80,16 +80,18 @@ module API
key
=
Key
.
find
(
params
[
:key_id
])
user
=
key
.
user
token_handler
=
if
user
token
=
Gitlab
::
LfsToken
.
new
(
user
).
generate
response
=
{
username:
user
.
username
,
lfs_token:
token
}
Gitlab
::
LfsToken
.
new
(
user
)
else
token
=
Gitlab
::
LfsToken
.
new
(
key
).
generate
response
=
{
username:
"lfs-deploy-key-
#{
key
.
id
}
"
,
lfs_token:
token
}
Gitlab
::
LfsToken
.
new
(
key
)
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
get
"/merge_request_urls"
do
...
...
lib/gitlab/auth.rb
View file @
c25630ee
...
...
@@ -117,15 +117,16 @@ module Gitlab
end
def
lfs_token_check
(
login
,
password
)
actor
=
if
login
.
include?
(
'lfs-deploy-key'
)
key
=
DeployKey
.
find
(
login
.
gsub
(
'lfs-deploy-key-'
,
''
))
token
=
Gitlab
::
LfsToken
.
new
(
key
).
value
Result
.
new
(
key
,
:lfs_deploy_token
)
if
key
&&
token
==
password
DeployKey
.
find
(
login
.
gsub
(
'lfs-deploy-key-'
,
''
))
else
user
=
User
.
by_login
(
login
)
token
=
Gitlab
::
LfsToken
.
new
(
user
).
value
Result
.
new
(
user
,
:lfs_token
)
if
user
&&
token
==
password
User
.
by_login
(
login
)
end
token_handler
=
Gitlab
::
LfsToken
.
new
(
actor
)
Result
.
new
(
actor
,
token_handler
.
type
)
if
actor
&&
token_handler
.
value
==
password
end
end
end
...
...
lib/gitlab/lfs_token.rb
View file @
c25630ee
...
...
@@ -22,6 +22,14 @@ module Gitlab
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
def
redis_key
...
...
spec/lib/gitlab/lfs_token_spec.rb
View file @
c25630ee
...
...
@@ -23,6 +23,14 @@ describe Gitlab::LfsToken, lib: true do
let
(
:handler
)
{
described_class
.
new
(
actor
)
}
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
context
'when the actor is a deploy key'
do
...
...
@@ -30,6 +38,14 @@ describe Gitlab::LfsToken, lib: true do
let
(
:handler
)
{
described_class
.
new
(
actor
)
}
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
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