Commit 38e4aa8a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'post-api' into 'master'

Make gitlab-shell work with new /api/allowed method

See merge request !39
parents 76f7f349 30171090
......@@ -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']
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
......
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