From 267cd3e3594dcb1555b5018723f3cc620873499d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Wed, 15 Feb 2017 23:08:30 -0300 Subject: Incorporate Gitaly client for refs service --- lib/api/internal.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 523f38d129e..56c597dffcb 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -138,8 +138,11 @@ module API return unless Gitlab::GitalyClient.enabled? + relative_path = Gitlab::RepoPath.strip_storage_path(params[:repo_path]) + project = Project.find_by_full_path(relative_path.sub(/\.(git|wiki)\z/, '')) + begin - Gitlab::GitalyClient::Notifications.new(params[:repo_path]).post_receive + Gitlab::GitalyClient::Notifications.new(project.repository_storage, relative_path).post_receive rescue GRPC::Unavailable => e render_api_error(e, 500) end -- cgit v1.2.1 From 20d415a676fc4ee7e6f48e56e1abbb8d78abf75f Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 7 Apr 2017 11:19:20 +0200 Subject: Use Gitlab::Git::Repository#gitaly_... more --- lib/api/internal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 56c597dffcb..70d0d57204d 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -142,7 +142,7 @@ module API project = Project.find_by_full_path(relative_path.sub(/\.(git|wiki)\z/, '')) begin - Gitlab::GitalyClient::Notifications.new(project.repository_storage, relative_path).post_receive + Gitlab::GitalyClient::Notifications.new(project.repository).post_receive rescue GRPC::Unavailable => e render_api_error(e, 500) end -- cgit v1.2.1 From 710cd82cc16a9c67458c72ea6b2c4b676234ef79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 5 Apr 2017 09:29:30 +0200 Subject: Set Git-specific env in /api/internal/allowed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- lib/api/internal.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 70d0d57204d..215bc03d0e9 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -11,14 +11,16 @@ module API # Params: # key_id - ssh key id for Git over SSH # user_id - user id for Git over HTTP + # protocol - Git access protocol being used, e.g. HTTP or SSH # project - project path with namespace # action - git action (git-upload-pack or git-receive-pack) - # ref - branch name - # forced_push - forced_push - # protocol - Git access protocol being used, e.g. HTTP or SSH + # changes - changes as "oldrev newrev ref", see Gitlab::ChangesList post "/allowed" do status 200 + # Stores some Git-specific env thread-safely + Gitlab::Git::Env.set(parse_env) + actor = if params[:key_id] Key.find_by(id: params[:key_id]) @@ -30,18 +32,10 @@ module API actor.update_last_used_at if actor.is_a?(Key) - access = - if wiki? - Gitlab::GitAccessWiki.new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities) - else - Gitlab::GitAccess.new(actor, - project, - protocol, - authentication_abilities: ssh_authentication_abilities, - env: parse_allowed_environment_variables) - end - - access_status = access.check(params[:action], params[:changes]) + access_checker = wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess + access_status = access_checker + .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities) + .check(params[:action], params[:changes]) response = { status: access_status.status, message: access_status.message } -- cgit v1.2.1 From 2951a8543ef97ceb1bcaca5f5140d822729c950b Mon Sep 17 00:00:00 2001 From: James Lopez Date: Wed, 5 Oct 2016 16:41:32 +0200 Subject: Add user activity service and spec. Also added relevant - NOT offline - migration It uses a user activity table instead of a column in users. Tested with mySQL and postgreSQL --- lib/api/internal.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 215bc03d0e9..d374d183dcd 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -15,6 +15,16 @@ module API # project - project path with namespace # action - git action (git-upload-pack or git-receive-pack) # changes - changes as "oldrev newrev ref", see Gitlab::ChangesList + helpers do + def log_user_activity(actor) + commands = Gitlab::GitAccess::DOWNLOAD_COMMANDS + + Gitlab::GitAccess::PUSH_COMMANDS + + Gitlab::GitAccess::GIT_ANNEX_COMMANDS + + ::Users::ActivityService.new(actor, 'Git SSH').execute if commands.include?(params[:action]) + end + end + post "/allowed" do status 200 @@ -40,6 +50,8 @@ module API response = { status: access_status.status, message: access_status.message } if access_status.status + log_user_activity(actor) + # Return the repository full path so that gitlab-shell has it when # handling ssh commands response[:repository_path] = -- cgit v1.2.1 From 380e40fee30d836e6dffb1e956df39033d43a671 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Wed, 12 Apr 2017 16:13:24 +0100 Subject: Remove unused user activities code --- lib/api/internal.rb | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index d374d183dcd..5b48ee8665f 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -15,16 +15,6 @@ module API # project - project path with namespace # action - git action (git-upload-pack or git-receive-pack) # changes - changes as "oldrev newrev ref", see Gitlab::ChangesList - helpers do - def log_user_activity(actor) - commands = Gitlab::GitAccess::DOWNLOAD_COMMANDS + - Gitlab::GitAccess::PUSH_COMMANDS + - Gitlab::GitAccess::GIT_ANNEX_COMMANDS - - ::Users::ActivityService.new(actor, 'Git SSH').execute if commands.include?(params[:action]) - end - end - post "/allowed" do status 200 -- cgit v1.2.1 From 615a77df83cc84e6b3c0ac221035ad88e73a5ac8 Mon Sep 17 00:00:00 2001 From: Luigi Leoni Date: Thu, 27 Apr 2017 09:33:48 +0200 Subject: Wrong method call on notify_post_receive. --- lib/api/internal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 5b48ee8665f..ebed26dd178 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -140,7 +140,7 @@ module API begin Gitlab::GitalyClient::Notifications.new(project.repository).post_receive rescue GRPC::Unavailable => e - render_api_error(e, 500) + render_api_error!(e, 500) end end end -- cgit v1.2.1 From c45341c816d78d51aee84a6068d778b9cbc502c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Fri, 28 Apr 2017 13:52:09 -0300 Subject: Generate and handle a gl_repository param to pass around components This new param allows us to share project information between components that don't share or don't have access to the same filesystem mountpoints, for example between Gitaly and Rails or between Rails and Gitlab-Shell hooks. The previous parameters are still supported, but if found, gl_repository is prefered. The old parameters should be deprecated once all components support the new format. --- lib/api/internal.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index ebed26dd178..ddb2047f686 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -42,6 +42,10 @@ module API if access_status.status log_user_activity(actor) + # Project id to pass between components that don't share/don't have + # access to the same filesystem mounts + response[:gl_repository] = "#{wiki? ? 'wiki' : 'project'}-#{project.id}" + # Return the repository full path so that gitlab-shell has it when # handling ssh commands response[:repository_path] = @@ -134,11 +138,9 @@ module API return unless Gitlab::GitalyClient.enabled? - relative_path = Gitlab::RepoPath.strip_storage_path(params[:repo_path]) - project = Project.find_by_full_path(relative_path.sub(/\.(git|wiki)\z/, '')) - begin - Gitlab::GitalyClient::Notifications.new(project.repository).post_receive + repository = wiki? ? project.wiki.repository : project.repository + Gitlab::GitalyClient::Notifications.new(repository.raw_repository).post_receive rescue GRPC::Unavailable => e render_api_error!(e, 500) end -- cgit v1.2.1 From 8bc381db90c92bca6ba868d1588af1ad1a41073b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Wed, 3 May 2017 18:07:54 -0300 Subject: Pass GL_REPOSITORY in Workhorse responses --- lib/api/internal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index ddb2047f686..2a11790b215 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -44,7 +44,7 @@ module API # Project id to pass between components that don't share/don't have # access to the same filesystem mounts - response[:gl_repository] = "#{wiki? ? 'wiki' : 'project'}-#{project.id}" + response[:gl_repository] = Gitlab::GlRepository.gl_repository(project, wiki?) # Return the repository full path so that gitlab-shell has it when # handling ssh commands -- cgit v1.2.1 From d40e1f547ea9e31e822229bb808aaa6b9201f473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 3 May 2017 13:22:03 +0200 Subject: Enable the Style/TrailingCommaInLiteral cop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the EnforcedStyleForMultiline: no_comma option. Signed-off-by: Rémy Coutable --- lib/api/internal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 2a11790b215..96aaaf868ea 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -90,7 +90,7 @@ module API { api_version: API.version, gitlab_version: Gitlab::VERSION, - gitlab_rev: Gitlab::REVISION, + gitlab_rev: Gitlab::REVISION } end -- cgit v1.2.1