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
da3d3ba8
Commit
da3d3ba8
authored
Aug 03, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Endpoints to enable and disable deploy keys
Resolves #20123
parent
e63729d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
165 additions
and
0 deletions
+165
-0
CHANGELOG
CHANGELOG
+1
-0
doc/api/deploy_keys.md
doc/api/deploy_keys.md
+49
-0
lib/api/deploy_keys.rb
lib/api/deploy_keys.rb
+31
-0
spec/requests/api/deploy_keys_spec.rb
spec/requests/api/deploy_keys_spec.rb
+84
-0
No files found.
CHANGELOG
View file @
da3d3ba8
...
...
@@ -4,6 +4,7 @@ v 8.11.0 (unreleased)
- Fix the title of the toggle dropdown button. !5515 (herminiotorres)
- Improve diff performance by eliminating redundant checks for text blobs
- Convert switch icon into icon font (ClemMakesApps)
- API: Endpoints for enabling and disabling deploy keys
- Remove magic comments (`# encoding: UTF-8`) from Ruby files. !5456 (winniehell)
- Add support for relative links starting with ./ or / to RelativeLinkFilter (winniehell)
- Fix CI status icon link underline (ClemMakesApps)
...
...
doc/api/deploy_keys.md
View file @
da3d3ba8
...
...
@@ -159,3 +159,52 @@ Example response:
"id"
:
13
}
```
## Enable a deploy key
Enables a deploy key for a project so this can be used. Returns the enabled key, with a status code 201 when successful.
```
curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/deploy_keys/13/enable
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer | yes | The ID of the project |
|
`key_id`
| integer | yes | The ID of the deploy key |
Example response:
```
json
```json
{
"key"
:
"ssh-rsa AAAA..."
,
"id"
:
12
,
"title"
:
"My deploy key"
,
"created_at"
:
"2015-08-29T12:44:31.550Z"
}
```
## Disable a deploy key
Disable a deploy key for a project. Returns the disabled key.
```
curl -X DELETE -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/deploy_keys/13/disable
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer | yes | The ID of the project |
|
`key_id`
| integer | yes | The ID of the deploy key |
Example response:
```
json
{
"key"
:
"ssh-rsa AAAA..."
,
"id"
:
12
,
"title"
:
"My deploy key"
,
"created_at"
:
"2015-08-29T12:44:31.550Z"
}
```
lib/api/deploy_keys.rb
View file @
da3d3ba8
...
...
@@ -74,6 +74,37 @@ module API
end
end
desc
'Enable a deploy key for a project'
do
detail
'This feature was added in GitLab 8.11'
success
Entities
::
SSHKey
end
params
do
requires
:key_id
,
type:
Integer
,
desc:
'The ID of the deploy key'
end
post
":id/
#{
path
}
/:key_id/enable"
do
key
=
DeployKey
.
find
(
params
[
:key_id
])
if
user_project
.
deploy_keys
<<
key
present
key
,
with:
Entities
::
SSHKey
else
render_validation_error!
(
key
)
end
end
desc
'Disable a deploy key for a project'
do
detail
'This feature was added in GitLab 8.11'
success
Entities
::
SSHKey
end
params
do
requires
:key_id
,
type:
Integer
,
desc:
'The ID of the deploy key'
end
delete
":id/
#{
path
}
/:key_id/disable"
do
key
=
user_project
.
deploy_keys_projects
.
find_by
(
deploy_key_id:
params
[
:key_id
])
key
.
destroy
present
key
.
deploy_key
,
with:
Entities
::
SSHKey
end
# Delete existing deploy key of currently authenticated user
#
# Example Request:
...
...
spec/requests/api/deploy_keys.rb
→
spec/requests/api/deploy_keys
_spec
.rb
View file @
da3d3ba8
...
...
@@ -3,17 +3,17 @@ require 'spec_helper'
describe
API
::
API
,
api:
true
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:deploy_keys_project
)
{
create
(
:deploy_keys_project
,
project:
project
)
}
let
(
:
admin
)
{
create
(
:admin
)
}
let
(
:
deploy_key
)
{
deploy_keys_project
.
deploy_key
}
describe
'GET /deploy_keys'
do
before
{
admin
}
context
'when unauthenticated'
do
it
'should return authentication error'
do
get
api
(
'/deploy_keys'
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
...
...
@@ -21,18 +21,64 @@ describe API::API, api: true do
context
'when authenticated as non-admin user'
do
it
'should return a 403 error'
do
get
api
(
'/deploy_keys'
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
context
'when authenticated as admin'
do
it
'should return all deploy keys'
do
get
api
(
'/deploy_keys'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
deploy_keys_project
.
deploy_key
.
id
)
end
end
end
describe
'POST /projects/:id/deploy_keys/:key_id/enable'
do
let
(
:project2
)
{
create
(
:empty_project
)
}
context
'when the user can admin the project'
do
it
'enables the key'
do
expect
do
post
api
(
"/projects/
#{
project2
.
id
}
/deploy_keys/
#{
deploy_key
.
id
}
/enable"
,
admin
)
end
.
to
change
{
project2
.
deploy_keys
.
count
}.
from
(
0
).
to
(
1
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'id'
]).
to
eq
(
deploy_key
.
id
)
end
end
context
'when authenticated as non-admin user'
do
it
'should return a 404 error'
do
post
api
(
"/projects/
#{
project2
.
id
}
/deploy_keys/
#{
deploy_key
.
id
}
/enable"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'DELETE /projects/:id/deploy_keys/:key_id/disable'
do
context
'when the user can admin the project'
do
it
'disables the key'
do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/
#{
deploy_key
.
id
}
/disable"
,
admin
)
end
.
to
change
{
project
.
deploy_keys
.
count
}.
from
(
1
).
to
(
0
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'id'
]).
to
eq
(
deploy_key
.
id
)
end
end
context
'when authenticated as non-admin user'
do
it
'should return a 404 error'
do
delete
api
(
"/projects/
#{
project
.
id
}
/deploy_keys/
#{
deploy_key
.
id
}
/disable"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
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