Commit 87d40fd276ade536e0b6b3019e52c2e1844e47ea
1 parent
c23eb408
Exists in
master
and in
4 other branches
Docs added
Showing
4 changed files
with
106 additions
and
0 deletions
Show diff stats
doc/api/README.md
@@ -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: | ||
34 | + [Snippets](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/snippets.md) | 34 | + [Snippets](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/snippets.md) |
35 | + [Issues](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md) | 35 | + [Issues](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md) |
36 | + [Milestones](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/milestones.md) | 36 | + [Milestones](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/milestones.md) |
37 | ++ [SSH Keys](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/keys.md) |
@@ -0,0 +1,79 @@ | @@ -0,0 +1,79 @@ | ||
1 | +## List keys | ||
2 | + | ||
3 | +Get a list of currently authenticated user's keys. | ||
4 | + | ||
5 | +``` | ||
6 | +GET /keys | ||
7 | +``` | ||
8 | + | ||
9 | +```json | ||
10 | +[ | ||
11 | + { | ||
12 | + "id": 1, | ||
13 | + "title" : "Public key" | ||
14 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 | ||
15 | + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 | ||
16 | + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", | ||
17 | + }, | ||
18 | + { | ||
19 | + "id": 3, | ||
20 | + "title" : "Another Public key" | ||
21 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 | ||
22 | + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 | ||
23 | + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" | ||
24 | + } | ||
25 | +] | ||
26 | +``` | ||
27 | + | ||
28 | +## Single key | ||
29 | + | ||
30 | +Get a single key. | ||
31 | + | ||
32 | +``` | ||
33 | +GET /keys/:id | ||
34 | +``` | ||
35 | + | ||
36 | +Parameters: | ||
37 | + | ||
38 | ++ `id` (required) - The ID of a key | ||
39 | + | ||
40 | +```json | ||
41 | +{ | ||
42 | + "id": 1, | ||
43 | + "title" : "Public key" | ||
44 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 | ||
45 | + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 | ||
46 | + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" | ||
47 | + } | ||
48 | +``` | ||
49 | +## Add key | ||
50 | + | ||
51 | +Create new key owned by currently authenticated user | ||
52 | + | ||
53 | +``` | ||
54 | +POST /keys | ||
55 | +``` | ||
56 | + | ||
57 | +Parameters: | ||
58 | + | ||
59 | ++ `title` (required) - new SSH Key | ||
60 | ++ `key` (optional) - new SSH key's title | ||
61 | + | ||
62 | +Will return created key with status `201 Created` on success, or `404 Not | ||
63 | +found` on fail. | ||
64 | + | ||
65 | +## Delete key | ||
66 | + | ||
67 | +Delete key owned by currently authenticated user | ||
68 | + | ||
69 | +``` | ||
70 | +DELETE /keys/:id | ||
71 | +``` | ||
72 | + | ||
73 | +Parameters: | ||
74 | + | ||
75 | ++ `id` (required) - key ID | ||
76 | + | ||
77 | +Will return `200 OK` on success, or `404 Not Found` on fail. | ||
78 | + | ||
79 | + |
lib/api/keys.rb
@@ -10,6 +10,14 @@ module Gitlab | @@ -10,6 +10,14 @@ module Gitlab | ||
10 | get do | 10 | get do |
11 | present current_user.keys, with: Entities::Key | 11 | present current_user.keys, with: Entities::Key |
12 | end | 12 | end |
13 | + # Get single key owned by currently authenticated user | ||
14 | + # | ||
15 | + # Example Request: | ||
16 | + # GET /keys/:id | ||
17 | + get "/:id" do | ||
18 | + key = current_user.keys.find params[:id] | ||
19 | + present key, with: Entities::Key | ||
20 | + end | ||
13 | # Add new ssh key to currently authenticated user | 21 | # Add new ssh key to currently authenticated user |
14 | # | 22 | # |
15 | # Parameters: | 23 | # Parameters: |
spec/requests/api/ssh_keys_spec.rb
@@ -28,6 +28,20 @@ describe Gitlab::Keys do | @@ -28,6 +28,20 @@ describe Gitlab::Keys do | ||
28 | end | 28 | end |
29 | end | 29 | end |
30 | 30 | ||
31 | + describe "GET /keys/:id" do | ||
32 | + it "should returm single key" do | ||
33 | + user.keys << key | ||
34 | + user.save | ||
35 | + get api("/keys/#{key.id}", user) | ||
36 | + response.status.should == 200 | ||
37 | + json_response["title"].should == key.title | ||
38 | + end | ||
39 | + it "should return 404 Not Found within invalid ID" do | ||
40 | + get api("/keys/42", user) | ||
41 | + response.status.should == 404 | ||
42 | + end | ||
43 | + end | ||
44 | + | ||
31 | describe "POST /keys" do | 45 | describe "POST /keys" do |
32 | it "should not create invalid ssh key" do | 46 | it "should not create invalid ssh key" do |
33 | post api("/keys", user), { title: "invalid key" } | 47 | post api("/keys", user), { title: "invalid key" } |
@@ -49,6 +63,10 @@ describe Gitlab::Keys do | @@ -49,6 +63,10 @@ describe Gitlab::Keys do | ||
49 | delete api("/keys/#{key.id}", user) | 63 | delete api("/keys/#{key.id}", user) |
50 | }.to change{user.keys.count}.by(-1) | 64 | }.to change{user.keys.count}.by(-1) |
51 | end | 65 | end |
66 | + it "should return 404 Not Found within invalid ID" do | ||
67 | + delete api("/keys/42", user) | ||
68 | + response.status.should == 404 | ||
69 | + end | ||
52 | end | 70 | end |
53 | 71 | ||
54 | end | 72 | end |