summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2017-01-23 17:06:57 +0100
committerRobert Schilling <rschilling@student.tugraz.at>2017-01-23 17:06:57 +0100
commit18417c9ee8b0e0bfa4ee41dd8ada969c0ede07f9 (patch)
tree3f7811eb4f5b005fcac7e6fdfb4cf0120ae9f2bb
parent6c65f7a7ce52fadcf53ea2395103de32b0107874 (diff)
downloadgitlab-ce-18417c9ee8b0e0bfa4ee41dd8ada969c0ede07f9.tar.gz
Grapify all endpoints of the deploy keys APIgrapify-deploy-keys
-rw-r--r--lib/api/deploy_keys.rb17
-rw-r--r--spec/requests/api/deploy_keys_spec.rb9
2 files changed, 10 insertions, 16 deletions
diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb
index 85360730841..28eea79fbaf 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
diff --git a/spec/requests/api/deploy_keys_spec.rb b/spec/requests/api/deploy_keys_spec.rb
index 5c14db067a8..766234d7104 100644
--- a/spec/requests/api/deploy_keys_spec.rb
+++ b/spec/requests/api/deploy_keys_spec.rb
@@ -73,19 +73,14 @@ describe API::DeployKeys, api: true do
post api("/projects/#{project.id}/deploy_keys", admin), { title: 'invalid key' }
expect(response).to have_http_status(400)
- expect(json_response['message']['key']).to eq([
- 'can\'t be blank',
- 'is invalid'
- ])
+ expect(json_response['error']).to eq('key is missing')
end
it 'should not create a key without title' do
post api("/projects/#{project.id}/deploy_keys", admin), key: 'some key'
expect(response).to have_http_status(400)
- expect(json_response['message']['title']).to eq([
- 'can\'t be blank'
- ])
+ expect(json_response['error']).to eq('title is missing')
end
it 'should create new ssh key' do