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
2b6bd6a3
Commit
2b6bd6a3
authored
Aug 03, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Grape DSL for deploy keys endpoints
Also a minor clean up of the post endpoint
parent
da3d3ba8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
40 deletions
+34
-40
lib/api/deploy_keys.rb
lib/api/deploy_keys.rb
+34
-39
spec/requests/api/deploy_keys_spec.rb
spec/requests/api/deploy_keys_spec.rb
+0
-1
No files found.
lib/api/deploy_keys.rb
View file @
2b6bd6a3
...
@@ -10,6 +10,9 @@ module API
...
@@ -10,6 +10,9 @@ module API
present
keys
,
with:
Entities
::
SSHKey
present
keys
,
with:
Entities
::
SSHKey
end
end
params
do
requires
:id
,
type:
String
,
desc:
'The ID of the project'
end
resource
:projects
do
resource
:projects
do
before
{
authorize_admin_project
}
before
{
authorize_admin_project
}
...
@@ -17,52 +20,42 @@ module API
...
@@ -17,52 +20,42 @@ module API
# Use "projects/:id/deploy_keys/..." instead.
# Use "projects/:id/deploy_keys/..." instead.
#
#
%w(keys deploy_keys)
.
each
do
|
path
|
%w(keys deploy_keys)
.
each
do
|
path
|
# Get a specific project's deploy keys
desc
"Get a specific project's deploy keys"
do
#
success
Entities
::
SSHKey
# Example Request:
end
# GET /projects/:id/deploy_keys
get
":id/
#{
path
}
"
do
get
":id/
#{
path
}
"
do
present
user_project
.
deploy_keys
,
with:
Entities
::
SSHKey
present
user_project
.
deploy_keys
,
with:
Entities
::
SSHKey
end
end
# Get single deploy key owned by currently authenticated user
desc
'Get single deploy key'
do
#
success
Entities
::
SSHKey
# Example Request:
end
# GET /projects/:id/deploy_keys/:key_id
params
do
requires
:key_id
,
type:
Integer
,
desc:
'The ID of the deploy key'
end
get
":id/
#{
path
}
/:key_id"
do
get
":id/
#{
path
}
/:key_id"
do
key
=
user_project
.
deploy_keys
.
find
params
[
:key_id
]
key
=
user_project
.
deploy_keys
.
find
params
[
:key_id
]
present
key
,
with:
Entities
::
SSHKey
present
key
,
with:
Entities
::
SSHKey
end
end
# Add new deploy key to currently authenticated user
desc
'Add new deploy key to currently authenticated user'
do
# If deploy key already exists - it will be joined to project
success
Entities
::
SSHKey
# but only if original one was accessible by same user
end
#
params
do
# Parameters:
requires
:key
,
type:
String
,
desc:
"The new deploy key"
# key (required) - New deploy Key
requires
:title
,
type:
String
,
desc:
'The title to identify the key from'
# title (required) - New deploy Key's title
end
# Example Request:
# POST /projects/:id/deploy_keys
post
":id/
#{
path
}
"
do
post
":id/
#{
path
}
"
do
attrs
=
attributes_for_keys
[
:title
,
:key
]
attrs
=
declared
(
params
,
include_parent_namespaces:
false
).
to_h
if
attrs
[
:key
].
present?
attrs
[
:key
].
strip!
# check if key already exist in project
key
=
user_project
.
deploy_keys
.
find_by
(
key:
attrs
[
:key
])
key
=
user_project
.
deploy_keys
.
find_by
(
key:
attrs
[
:key
])
if
key
present
key
,
with:
Entities
::
SSHKey
if
key
present
key
,
with:
Entities
::
SSHKey
next
end
# Check for available deploy keys in other projects
# Check for available deploy keys in other projects
key
=
current_user
.
accessible_deploy_keys
.
find_by
(
key:
attrs
[
:key
])
key
=
current_user
.
accessible_deploy_keys
.
find_by
(
key:
attrs
[
:key
])
if
key
if
key
user_project
.
deploy_keys
<<
key
user_project
.
deploy_keys
<<
key
present
key
,
with:
Entities
::
SSHKey
present
key
,
with:
Entities
::
SSHKey
next
end
end
end
key
=
DeployKey
.
new
attrs
key
=
DeployKey
.
new
attrs
...
@@ -105,12 +98,14 @@ module API
...
@@ -105,12 +98,14 @@ module API
present
key
.
deploy_key
,
with:
Entities
::
SSHKey
present
key
.
deploy_key
,
with:
Entities
::
SSHKey
end
end
# Delete existing deploy key of currently authenticated user
desc
'Delete existing deploy key of currently authenticated user'
do
#
success
Key
# Example Request:
end
# DELETE /projects/:id/deploy_keys/:key_id
params
do
requires
:key_id
,
type:
Integer
,
desc:
'The ID of the deploy key'
end
delete
":id/
#{
path
}
/:key_id"
do
delete
":id/
#{
path
}
/:key_id"
do
key
=
user_project
.
deploy_keys
.
find
params
[
:key_id
]
key
=
user_project
.
deploy_keys
.
find
(
params
[
:key_id
])
key
.
destroy
key
.
destroy
end
end
end
end
...
...
spec/requests/api/deploy_keys_spec.rb
View file @
2b6bd6a3
...
@@ -27,7 +27,6 @@ describe API::API, api: true do
...
@@ -27,7 +27,6 @@ describe API::API, api: true do
end
end
context
'when authenticated as admin'
do
context
'when authenticated as admin'
do
it
'should return all deploy keys'
do
it
'should return all deploy keys'
do
get
api
(
'/deploy_keys'
,
admin
)
get
api
(
'/deploy_keys'
,
admin
)
...
...
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