From 935b6ae6534e77f2b9e84bcb686aeeda88089122 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 4 Feb 2013 17:53:43 +0200 Subject: Internal API --- lib/api/internal.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/api/internal.rb (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb new file mode 100644 index 00000000000..c12605841ab --- /dev/null +++ b/lib/api/internal.rb @@ -0,0 +1,24 @@ +module Gitlab + # Access API + class Internal < Grape::API + + get "/allowed" do + user = User.find_by_username(params[:username]) + project = Project.find_with_namespace(params[:project]) + action = case params[:action] + when 'git-upload-pack' + then :download_code + when 'git-receive-pack' + then + if project.protected_branch?(params[:ref]) + :push_code_to_protected_branches + else + :push_code + end + end + + user.can?(action, project) + end + end +end + -- cgit v1.2.1 From 70e3bffd95eb5736dd108e0836abaa85a2f1c742 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 5 Feb 2013 12:47:50 +0200 Subject: Fixed: post-receive, project remove, tests --- lib/api/internal.rb | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index c12605841ab..576b64d04c3 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -1,23 +1,37 @@ module Gitlab - # Access API + # Internal access API class Internal < Grape::API + namespace 'internal' do + # + # Check if ssh key has access to project code + # + get "/allowed" do + key = Key.find(params[:key_id]) + user = key.user - get "/allowed" do - user = User.find_by_username(params[:username]) - project = Project.find_with_namespace(params[:project]) - action = case params[:action] - when 'git-upload-pack' - then :download_code - when 'git-receive-pack' - then - if project.protected_branch?(params[:ref]) - :push_code_to_protected_branches - else - :push_code + project = Project.find_with_namespace(params[:project]) + action = case params[:action] + when 'git-upload-pack' + then :download_code + when 'git-receive-pack' + then + if project.protected_branch?(params[:ref]) + :push_code_to_protected_branches + else + :push_code + end end - end - user.can?(action, project) + user.can?(action, project) + end + + # + # Discover user by ssh key + # + get "/discover" do + key = Key.find(params[:key_id]) + present key.user, with: Entities::User + end end end end -- cgit v1.2.1 From bd3288e3207c12e90d7fed629b345cfe83018bbf Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 5 Feb 2013 15:55:49 +0200 Subject: api check call --- lib/api/internal.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 576b64d04c3..0a0f55bc512 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -32,6 +32,12 @@ module Gitlab key = Key.find(params[:key_id]) present key.user, with: Entities::User end + + get "/check" do + { + api_version: '3' + } + end end end end -- cgit v1.2.1 From 8ae1d812dc9c8099b691e164e7119ede7eb21c61 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 7 Feb 2013 09:56:13 +0200 Subject: deploy keys support for gitlab-shell api --- lib/api/internal.rb | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 0a0f55bc512..3e5e3a478ba 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -7,22 +7,27 @@ module Gitlab # get "/allowed" do key = Key.find(params[:key_id]) - user = key.user - project = Project.find_with_namespace(params[:project]) - action = case params[:action] - when 'git-upload-pack' - then :download_code - when 'git-receive-pack' - then - if project.protected_branch?(params[:ref]) - :push_code_to_protected_branches - else - :push_code + git_cmd = params[:action] + + if key.is_deploy_key + project == key.project && git_cmd == 'git-upload-pack' + else + user = key.user + action = case git_cmd + when 'git-upload-pack' + then :download_code + when 'git-receive-pack' + then + if project.protected_branch?(params[:ref]) + :push_code_to_protected_branches + else + :push_code + end end - end - user.can?(action, project) + user.can?(action, project) + end end # -- cgit v1.2.1