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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
87d40fd2
Commit
87d40fd2
authored
Sep 16, 2012
by
Alex Denisov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs added
parent
c23eb408
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
0 deletions
+106
-0
doc/api/README.md
doc/api/README.md
+1
-0
doc/api/keys.md
doc/api/keys.md
+79
-0
lib/api/keys.rb
lib/api/keys.rb
+8
-0
spec/requests/api/ssh_keys_spec.rb
spec/requests/api/ssh_keys_spec.rb
+18
-0
No files found.
doc/api/README.md
View file @
87d40fd2
...
@@ -34,3 +34,4 @@ When listing resources you can pass the following parameters:
...
@@ -34,3 +34,4 @@ When listing resources you can pass the following parameters:
+
[
Snippets
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/snippets.md
)
+
[
Snippets
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/snippets.md
)
+
[
Issues
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md
)
+
[
Issues
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md
)
+
[
Milestones
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/milestones.md
)
+
[
Milestones
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/milestones.md
)
+
[
SSH Keys
](
https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/keys.md
)
doc/api/keys.md
0 → 100644
View file @
87d40fd2
## List keys
Get a list of currently authenticated user's keys.
```
GET /keys
```
```
json
[
{
"id"
:
1
,
"title"
:
"Public key"
"key"
:
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
,
},
{
"id"
:
3
,
"title"
:
"Another Public key"
"key"
:
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
}
]
```
## Single key
Get a single key.
```
GET /keys/:id
```
Parameters:
+
`id`
(required) - The ID of a key
```
json
{
"id"
:
1
,
"title"
:
"Public key"
"key"
:
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
}
```
## Add key
Create new key owned by currently authenticated user
```
POST /keys
```
Parameters:
+
`title`
(required) - new SSH Key
+
`key`
(optional) - new SSH key's title
Will return created key with status
`201 Created`
on success, or
`404 Not
found`
on fail.
## Delete key
Delete key owned by currently authenticated user
```
DELETE /keys/:id
```
Parameters:
+
`id`
(required) - key ID
Will return
`200 OK`
on success, or
`404 Not Found`
on fail.
lib/api/keys.rb
View file @
87d40fd2
...
@@ -10,6 +10,14 @@ module Gitlab
...
@@ -10,6 +10,14 @@ module Gitlab
get
do
get
do
present
current_user
.
keys
,
with:
Entities
::
Key
present
current_user
.
keys
,
with:
Entities
::
Key
end
end
# Get single key owned by currently authenticated user
#
# Example Request:
# GET /keys/:id
get
"/:id"
do
key
=
current_user
.
keys
.
find
params
[
:id
]
present
key
,
with:
Entities
::
Key
end
# Add new ssh key to currently authenticated user
# Add new ssh key to currently authenticated user
#
#
# Parameters:
# Parameters:
...
...
spec/requests/api/ssh_keys_spec.rb
View file @
87d40fd2
...
@@ -28,6 +28,20 @@ describe Gitlab::Keys do
...
@@ -28,6 +28,20 @@ describe Gitlab::Keys do
end
end
end
end
describe
"GET /keys/:id"
do
it
"should returm single key"
do
user
.
keys
<<
key
user
.
save
get
api
(
"/keys/
#{
key
.
id
}
"
,
user
)
response
.
status
.
should
==
200
json_response
[
"title"
].
should
==
key
.
title
end
it
"should return 404 Not Found within invalid ID"
do
get
api
(
"/keys/42"
,
user
)
response
.
status
.
should
==
404
end
end
describe
"POST /keys"
do
describe
"POST /keys"
do
it
"should not create invalid ssh key"
do
it
"should not create invalid ssh key"
do
post
api
(
"/keys"
,
user
),
{
title:
"invalid key"
}
post
api
(
"/keys"
,
user
),
{
title:
"invalid key"
}
...
@@ -49,6 +63,10 @@ describe Gitlab::Keys do
...
@@ -49,6 +63,10 @@ describe Gitlab::Keys do
delete
api
(
"/keys/
#{
key
.
id
}
"
,
user
)
delete
api
(
"/keys/
#{
key
.
id
}
"
,
user
)
}.
to
change
{
user
.
keys
.
count
}.
by
(
-
1
)
}.
to
change
{
user
.
keys
.
count
}.
by
(
-
1
)
end
end
it
"should return 404 Not Found within invalid ID"
do
delete
api
(
"/keys/42"
,
user
)
response
.
status
.
should
==
404
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