Commit 0611c5c6120503b57237c2580fddf318cd6a552a
1 parent
50e8d6c0
Exists in
master
and in
4 other branches
Fix deploy key api 500 if key is empty
Showing
1 changed file
with
16 additions
and
14 deletions
Show diff stats
lib/api/projects.rb
| @@ -428,21 +428,23 @@ module API | @@ -428,21 +428,23 @@ module API | ||
| 428 | post ":id/keys" do | 428 | post ":id/keys" do |
| 429 | attrs = attributes_for_keys [:title, :key] | 429 | attrs = attributes_for_keys [:title, :key] |
| 430 | 430 | ||
| 431 | - attrs[:key].strip! | ||
| 432 | - | ||
| 433 | - # check if key already exist in project | ||
| 434 | - key = user_project.deploy_keys.find_by_key(attrs[:key]) | ||
| 435 | - if key | ||
| 436 | - present key, with: Entities::SSHKey | ||
| 437 | - return | ||
| 438 | - end | 431 | + if attrs[:key].present? |
| 432 | + attrs[:key].strip! | ||
| 433 | + | ||
| 434 | + # check if key already exist in project | ||
| 435 | + key = user_project.deploy_keys.find_by_key(attrs[:key]) | ||
| 436 | + if key | ||
| 437 | + present key, with: Entities::SSHKey | ||
| 438 | + return | ||
| 439 | + end | ||
| 439 | 440 | ||
| 440 | - # Check for available deploy keys in other projects | ||
| 441 | - key = current_user.owned_deploy_keys.find_by_key(attrs[:key]) | ||
| 442 | - if key | ||
| 443 | - user_project.deploy_keys << key | ||
| 444 | - present key, with: Entities::SSHKey | ||
| 445 | - return | 441 | + # Check for available deploy keys in other projects |
| 442 | + key = current_user.owned_deploy_keys.find_by_key(attrs[:key]) | ||
| 443 | + if key | ||
| 444 | + user_project.deploy_keys << key | ||
| 445 | + present key, with: Entities::SSHKey | ||
| 446 | + return | ||
| 447 | + end | ||
| 446 | end | 448 | end |
| 447 | 449 | ||
| 448 | key = DeployKey.new attrs | 450 | key = DeployKey.new attrs |