summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-09-03 13:46:14 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-09-03 13:46:14 +0300
commit3017109027b213c8c724f628fc34726fff7a403d (patch)
tree333531d5fc74d66eec4fbe1a5fb34fb2725f1d4d
parent76f7f349669524809db2daa34d07d4af9b9e9544 (diff)
downloadgitlab-shell-3017109027b213c8c724f628fc34726fff7a403d.tar.gz
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>
-rw-r--r--lib/gitlab_access.rb2
-rw-r--r--lib/gitlab_net.rb30
2 files changed, 27 insertions, 5 deletions
diff --git a/lib/gitlab_access.rb b/lib/gitlab_access.rb
index 1f328b7..63c074b 100644
--- a/lib/gitlab_access.rb
+++ b/lib/gitlab_access.rb
@@ -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
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index 65c2828..1eb043f 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -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']
- 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
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