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
else
# reset GL_ID env since we stop git push here
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
end
end
......
......@@ -23,8 +23,8 @@ class GitlabNet
params.merge!(user_id: actor.gsub("user-", ""))
end
url = "#{host}/allowed?" + URI.encode_www_form(params)
resp = get(url)
url = "#{host}/allowed"
resp = post(url, params)
!!(resp.code == '200' && resp.body == 'true')
end
......@@ -59,10 +59,15 @@ class GitlabNet
end
end
def http_request_for(url)
def http_request_for(url, method = :get)
user = config.http_settings['user']
password = config.http_settings['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
def get(url)
......@@ -81,6 +86,23 @@ class GitlabNet
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
@cert_store ||= OpenSSL::X509::Store.new.tap do |store|
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