diff options
author | Nihad Abbasov <narkoz.2008@gmail.com> | 2012-09-21 15:49:28 +0400 |
---|---|---|
committer | Nihad Abbasov <narkoz.2008@gmail.com> | 2012-09-21 15:49:28 +0400 |
commit | b62445813dffec92e85540ed081e4d6e12d58dc0 (patch) | |
tree | 6417cd7e74ded09612892d963c1423c9c82a8de2 /lib | |
parent | 4a072be2d775d5ce59573cfb447ddab940854d54 (diff) |
API: SSH keys belong to user entity
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api.rb | 1 | ||||
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/keys.rb | 50 | ||||
-rw-r--r-- | lib/api/users.rb | 59 |
4 files changed, 55 insertions, 59 deletions
diff --git a/lib/api.rb b/lib/api.rb index 3b62f31bf32..2890a8cc9e8 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -17,7 +17,6 @@ module Gitlab mount Projects mount Issues mount Milestones - mount Keys mount Session end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index ee6f15f1218..ee693de699e 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -60,8 +60,8 @@ module Gitlab expose :closed, :updated_at, :created_at end - class Key < Grape::Entity - expose :id, :title, :key + class SSHKey < Grape::Entity + expose :id, :title, :key end end end diff --git a/lib/api/keys.rb b/lib/api/keys.rb deleted file mode 100644 index 4c302727c4f..00000000000 --- a/lib/api/keys.rb +++ /dev/null @@ -1,50 +0,0 @@ -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 - # 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 - # - # Parameters: - # key (required) - New SSH Key - # title (required) - New SSH Key's title - # Example Request: - # POST /keys - post do - attrs = attributes_for_keys [:title, :key] - key = current_user.keys.new attrs - 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 - diff --git a/lib/api/users.rb b/lib/api/users.rb index 98ced6f8e5b..0ca8fb2a1ae 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -25,12 +25,59 @@ module Gitlab end end - # Get currently authenticated user - # - # Example Request: - # GET /user - get "/user" do - present @current_user, with: Entities::User + resource :user do + # Get currently authenticated user + # + # Example Request: + # GET /user + get do + present @current_user, with: Entities::User + end + + # Get currently authenticated user's keys + # + # Example Request: + # GET /user/keys + get "keys" do + present current_user.keys, with: Entities::SSHKey + end + + # Get single key owned by currently authenticated user + # + # Example Request: + # GET /user/keys/:id + get "keys/:id" do + key = current_user.keys.find params[:id] + present key, with: Entities::SSHKey + 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 /user/keys + post "keys" do + attrs = attributes_for_keys [:title, :key] + key = current_user.keys.new attrs + if key.save + present key, with: Entities::SSHKey + else + not_found! + end + end + + # Delete existed ssh key of currently authenticated user + # + # Parameters: + # id (required) - SSH Key ID + # Example Request: + # DELETE /user/keys/:id + delete "keys/:id" do + key = current_user.keys.find params[:id] + key.delete + end end end end |