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
Boxiang Sun
gitlab-ce
Commits
c23eb408
Commit
c23eb408
authored
Sep 16, 2012
by
Alex Denisov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SSH Keys API implemented
parent
caef9ed1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
0 deletions
+106
-0
lib/api.rb
lib/api.rb
+1
-0
lib/api/entities.rb
lib/api/entities.rb
+6
-0
lib/api/keys.rb
lib/api/keys.rb
+44
-0
spec/requests/api/ssh_keys_spec.rb
spec/requests/api/ssh_keys_spec.rb
+55
-0
No files found.
lib/api.rb
View file @
c23eb408
...
...
@@ -17,5 +17,6 @@ module Gitlab
mount
Projects
mount
Issues
mount
Milestones
mount
Keys
end
end
lib/api/entities.rb
View file @
c23eb408
...
...
@@ -48,5 +48,11 @@ module Gitlab
expose
:assignee
,
:author
,
using:
Entities
::
UserBasic
expose
:closed
,
:updated_at
,
:created_at
end
class
Key
<
Grape
::
Entity
expose
:id
,
:title
,
:key
end
end
end
lib/api/keys.rb
0 → 100644
View file @
c23eb408
module
Gitlab
# Keys API
class
Keys
<
Grape
::
API
before
{
authenticate!
}
resource
:keys
do
# Get currently authenticated user's keys
#
# Example Request:
# GET /keys
get
do
present
current_user
.
keys
,
with:
Entities
::
Key
end
# Add new ssh key to currently authenticated user
#
# Parameters:
# key (required) - New SSH Key
# title (required) - New SSH Key's title
# Example Request:
# POST /keys
post
do
key
=
current_user
.
keys
.
new
(
title:
params
[
:title
],
key:
params
[
:key
]
)
if
key
.
save
present
key
,
with:
Entities
::
Key
else
not_found!
end
end
# Delete existed ssh key of currently authenticated user
#
# Parameters:
# id (required) - SSH Key ID
# Example Request:
# DELETE /keys/:id
delete
"/:id"
do
key
=
current_user
.
keys
.
find
params
[
:id
]
key
.
delete
end
end
end
end
spec/requests/api/ssh_keys_spec.rb
0 → 100644
View file @
c23eb408
require
'spec_helper'
describe
Gitlab
::
Keys
do
include
ApiHelpers
let
(
:user
)
{
user
=
Factory
.
create
:user
user
.
reset_authentication_token!
user
}
let
(
:key
)
{
Factory
.
create
:key
,
{
user:
user
}}
describe
"GET /keys"
do
context
"when unauthenticated"
do
it
"should return authentication error"
do
get
api
(
"/keys"
)
response
.
status
.
should
==
401
end
end
context
"when authenticated"
do
it
"should return array of ssh keys"
do
user
.
keys
<<
key
user
.
save
get
api
(
"/keys"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
"title"
].
should
==
key
.
title
end
end
end
describe
"POST /keys"
do
it
"should not create invalid ssh key"
do
post
api
(
"/keys"
,
user
),
{
title:
"invalid key"
}
response
.
status
.
should
==
404
end
it
"should create ssh key"
do
key_attrs
=
Factory
.
attributes
:key
expect
{
post
api
(
"/keys"
,
user
),
key_attrs
}.
to
change
{
user
.
keys
.
count
}.
by
(
1
)
end
end
describe
"DELETE /keys/:id"
do
it
"should delete existed key"
do
user
.
keys
<<
key
user
.
save
expect
{
delete
api
(
"/keys/
#{
key
.
id
}
"
,
user
)
}.
to
change
{
user
.
keys
.
count
}.
by
(
-
1
)
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