Commit 30171090 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 76f7f349
...@@ -21,7 +21,7 @@ class GitlabAccess ...@@ -21,7 +21,7 @@ class GitlabAccess
else else
# reset GL_ID env since we stop git push here # reset GL_ID env since we stop git push here
ENV['GL_ID'] = nil ENV['GL_ID'] = nil
puts "GitLab: You are not allowed to access #{@ref_name}!" puts "GitLab: You are not allowed to access some of the refs!"
exit 1 exit 1
end end
end end
......
...@@ -23,8 +23,8 @@ class GitlabNet ...@@ -23,8 +23,8 @@ class GitlabNet
params.merge!(user_id: actor.gsub("user-", "")) params.merge!(user_id: actor.gsub("user-", ""))
end end
url = "#{host}/allowed?" + URI.encode_www_form(params) url = "#{host}/allowed"
resp = get(url) resp = post(url, params)
!!(resp.code == '200' && resp.body == 'true') !!(resp.code == '200' && resp.body == 'true')
end end
...@@ -59,10 +59,15 @@ class GitlabNet ...@@ -59,10 +59,15 @@ class GitlabNet
end end
end end
def http_request_for(url) def http_request_for(url, method = :get)
user = config.http_settings['user'] user = config.http_settings['user']
password = config.http_settings['password'] password = config.http_settings['password']
Net::HTTP::Get.new(url.request_uri).tap { |r| r.basic_auth(user, password) if user && password }
if method == :get
Net::HTTP::Get.new(url.request_uri).tap { |r| r.basic_auth(user, password) if user && password }
else
Net::HTTP::Post.new(url.request_uri).tap { |r| r.basic_auth(user, password) if user && password }
end
end end
def get(url) def get(url)
...@@ -81,6 +86,23 @@ class GitlabNet ...@@ -81,6 +86,23 @@ class GitlabNet
end end
end end
def post(url, params)
$logger.debug "Performing POST #{url}"
url = URI.parse(url)
http = http_client_for(url)
request = http_request_for(url, :post)
request.set_form_data(params)
http.start { |http| http.request(request) }.tap do |resp|
if resp.code == "200"
$logger.debug { "Received response #{resp.code} => <#{resp.body}>." }
else
$logger.error { "API call <POST #{url}> failed: #{resp.code} => <#{resp.body}>." }
end
end
end
def cert_store def cert_store
@cert_store ||= OpenSSL::X509::Store.new.tap do |store| @cert_store ||= OpenSSL::X509::Store.new.tap do |store|
store.set_default_paths store.set_default_paths
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment