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
Tatuya Kamada
gitlab-ce
Commits
18417c9e
Commit
18417c9e
authored
Jan 23, 2017
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grapify all endpoints of the deploy keys API
parent
6c65f7a7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
16 deletions
+10
-16
lib/api/deploy_keys.rb
lib/api/deploy_keys.rb
+8
-9
spec/requests/api/deploy_keys_spec.rb
spec/requests/api/deploy_keys_spec.rb
+2
-7
No files found.
lib/api/deploy_keys.rb
View file @
18417c9e
...
...
@@ -38,26 +38,25 @@ module API
present
key
,
with:
Entities
::
SSHKey
end
# TODO: for 9.0 we should check if params are there with the params block
# grape provides, at this point we'd change behaviour so we can't
# Behaviour now if you don't provide all required params: it renders a
# validation error or two.
desc
'Add new deploy key to currently authenticated user'
do
success
Entities
::
SSHKey
end
params
do
requires
:key
,
type:
String
,
desc:
'The new deploy key'
requires
:title
,
type:
String
,
desc:
'The name of the deploy key'
end
post
":id/
#{
path
}
"
do
attrs
=
attributes_for_keys
[
:title
,
:key
]
attrs
[
:key
].
strip!
if
attrs
[
:key
]
params
[
:key
].
strip!
# Check for an existing key joined to this project
key
=
user_project
.
deploy_keys
.
find_by
(
key:
attr
s
[
:key
])
key
=
user_project
.
deploy_keys
.
find_by
(
key:
param
s
[
:key
])
if
key
present
key
,
with:
Entities
::
SSHKey
break
end
# Check for available deploy keys in other projects
key
=
current_user
.
accessible_deploy_keys
.
find_by
(
key:
attr
s
[
:key
])
key
=
current_user
.
accessible_deploy_keys
.
find_by
(
key:
param
s
[
:key
])
if
key
user_project
.
deploy_keys
<<
key
present
key
,
with:
Entities
::
SSHKey
...
...
@@ -65,7 +64,7 @@ module API
end
# Create a new deploy key
key
=
DeployKey
.
new
attrs
key
=
DeployKey
.
new
(
declared_params
(
include_missing:
false
))
if
key
.
valid?
&&
user_project
.
deploy_keys
<<
key
present
key
,
with:
Entities
::
SSHKey
else
...
...
spec/requests/api/deploy_keys_spec.rb
View file @
18417c9e
...
...
@@ -73,19 +73,14 @@ describe API::DeployKeys, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
),
{
title:
'invalid key'
}
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'key'
]).
to
eq
([
'can\'t be blank'
,
'is invalid'
])
expect
(
json_response
[
'error'
]).
to
eq
(
'key is missing'
)
end
it
'should not create a key without title'
do
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
),
key:
'some key'
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'can\'t be blank'
])
expect
(
json_response
[
'error'
]).
to
eq
(
'title is missing'
)
end
it
'should create new ssh key'
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