diff options
author | Rémy Coutable <remy@rymai.me> | 2017-01-24 12:45:09 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-01-24 12:45:09 +0000 |
commit | 01fa19edfe2646ad904db6ff50047c2eab61e9d9 (patch) | |
tree | 2ca20e8f95240ab62c1196192813db8b1865a6d0 /lib/api/deploy_keys.rb | |
parent | fe0dbf61c1cefa02bd1db0ec087aef030f150f2d (diff) | |
parent | 18417c9ee8b0e0bfa4ee41dd8ada969c0ede07f9 (diff) | |
download | gitlab-ce-01fa19edfe2646ad904db6ff50047c2eab61e9d9.tar.gz |
Merge branch 'grapify-deploy-keys' into 'master'
Grapify all endpoints of the deploy keys API
See merge request !8721
Diffstat (limited to 'lib/api/deploy_keys.rb')
-rw-r--r-- | lib/api/deploy_keys.rb | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb index f6cb17bafd8..64da7d6b86f 100644 --- a/lib/api/deploy_keys.rb +++ b/lib/api/deploy_keys.rb @@ -38,26 +38,25 @@ module API present key, with: Entities::SSHKey end - # TODO: for 9.0 we should check if params are there with the params block - # grape provides, at this point we'd change behaviour so we can't - # Behaviour now if you don't provide all required params: it renders a - # validation error or two. desc 'Add new deploy key to currently authenticated user' do success Entities::SSHKey end + params do + requires :key, type: String, desc: 'The new deploy key' + requires :title, type: String, desc: 'The name of the deploy key' + end post ":id/#{path}" do - attrs = attributes_for_keys [:title, :key] - attrs[:key].strip! if attrs[:key] + params[:key].strip! # Check for an existing key joined to this project - key = user_project.deploy_keys.find_by(key: attrs[:key]) + key = user_project.deploy_keys.find_by(key: params[:key]) if key present key, with: Entities::SSHKey break end # Check for available deploy keys in other projects - key = current_user.accessible_deploy_keys.find_by(key: attrs[:key]) + key = current_user.accessible_deploy_keys.find_by(key: params[:key]) if key user_project.deploy_keys << key present key, with: Entities::SSHKey @@ -65,7 +64,7 @@ module API end # Create a new deploy key - key = DeployKey.new attrs + key = DeployKey.new(declared_params(include_missing: false)) if key.valid? && user_project.deploy_keys << key present key, with: Entities::SSHKey else |