Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-04-05 10:29:30 +0300
committerRémy Coutable <remy@rymai.me>2017-04-10 17:10:18 +0300
commit710cd82cc16a9c67458c72ea6b2c4b676234ef79 (patch)
treef2a28252f72948c1d59ada30fe3957dacd3caf6f /lib
parent05aa038c42a64da76a419b8177ba6c7242f67687 (diff)
Set Git-specific env in /api/internal/allowed
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r--lib/api/helpers/internal_helpers.rb6
-rw-r--r--lib/api/internal.rb24
2 files changed, 12 insertions, 18 deletions
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index 2135a787b11..810e5063996 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -53,12 +53,12 @@ module API
]
end
- def parse_allowed_environment_variables
- return if params[:env].blank?
+ def parse_env
+ return {} if params[:env].blank?
JSON.parse(params[:env])
-
rescue JSON::ParserError
+ {}
end
end
end
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 }