Commit acdeb0bf authored by Akzhan's avatar Akzhan

http_settings configuration option added.

Now it supports:

 * self_signed_cert option to allow self-signed certificates over https protocol.
 * user and password options to pass though http auth.
parent 601450c3
# GitLab user. git by default
user: git
# Url to gitlab instance. Used for api calls
# Url to gitlab instance. Used for api calls. Should be ends with slash.
gitlab_url: "http://localhost/"
http_settings:
# user: someone
# password: somepass
self_signed_cert: false
# Repositories path
repos_path: "/home/git/repositories"
......
......@@ -18,4 +18,8 @@ class GitlabConfig
def gitlab_url
@config['gitlab_url'] ||= "http://localhost/"
end
def http_settings
@config['http_settings'] ||= {}
end
end
......@@ -30,15 +30,28 @@ class GitlabNet
protected
def config
@config ||= GitlabConfig.new
end
def host
"#{GitlabConfig.new.gitlab_url}/api/v3/internal"
"#{config.gitlab_url}/api/v3/internal"
end
def get(url)
url = URI.parse(url)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = (url.port == 443)
if config.http_settings['self_signed_cert'] && http.use_ssl?
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
request = Net::HTTP::Get.new(url.request_uri)
if config.http_settings['user'] && config.http_settings['password']
request.basic_auth config.http_settings['user'], config.http_settings['password']
end
http.start {|http| http.request(request) }
end
end
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