Skip to content

Commit 3017109

Browse files
committed
GitLab /api/allowed endpoint requires POST request
This commit made changes to GitLab shell to work with huge pushed (ex. 1k branhes) using POST request to API Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
1 parent 76f7f34 commit 3017109

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/gitlab_access.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def exec
2121
else
2222
# reset GL_ID env since we stop git push here
2323
ENV['GL_ID'] = nil
24-
puts "GitLab: You are not allowed to access #{@ref_name}!"
24+
puts "GitLab: You are not allowed to access some of the refs!"
2525
exit 1
2626
end
2727
end

lib/gitlab_net.rb

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def allowed?(cmd, repo, actor, changes)
2323
params.merge!(user_id: actor.gsub("user-", ""))
2424
end
2525

26-
url = "#{host}/allowed?" + URI.encode_www_form(params)
27-
resp = get(url)
26+
url = "#{host}/allowed"
27+
resp = post(url, params)
2828

2929
!!(resp.code == '200' && resp.body == 'true')
3030
end
@@ -59,10 +59,15 @@ def http_client_for(url)
5959
end
6060
end
6161

62-
def http_request_for(url)
62+
def http_request_for(url, method = :get)
6363
user = config.http_settings['user']
6464
password = config.http_settings['password']
65-
Net::HTTP::Get.new(url.request_uri).tap { |r| r.basic_auth(user, password) if user && password }
65+
66+
if method == :get
67+
Net::HTTP::Get.new(url.request_uri).tap { |r| r.basic_auth(user, password) if user && password }
68+
else
69+
Net::HTTP::Post.new(url.request_uri).tap { |r| r.basic_auth(user, password) if user && password }
70+
end
6671
end
6772

6873
def get(url)
@@ -81,6 +86,23 @@ def get(url)
8186
end
8287
end
8388

89+
def post(url, params)
90+
$logger.debug "Performing POST #{url}"
91+
92+
url = URI.parse(url)
93+
http = http_client_for(url)
94+
request = http_request_for(url, :post)
95+
request.set_form_data(params)
96+
97+
http.start { |http| http.request(request) }.tap do |resp|
98+
if resp.code == "200"
99+
$logger.debug { "Received response #{resp.code} => <#{resp.body}>." }
100+
else
101+
$logger.error { "API call <POST #{url}> failed: #{resp.code} => <#{resp.body}>." }
102+
end
103+
end
104+
end
105+
84106
def cert_store
85107
@cert_store ||= OpenSSL::X509::Store.new.tap do |store|
86108
store.set_default_paths

0 commit comments

Comments
 (0)