diff options
-rw-r--r-- | config.yml.example | 7 | ||||
-rw-r--r-- | lib/gitlab_config.rb | 4 | ||||
-rw-r--r-- | lib/gitlab_net.rb | 15 |
3 files changed, 24 insertions, 2 deletions
diff --git a/config.yml.example b/config.yml.example index c4fb088..6b0dbeb 100644 --- a/config.yml.example +++ b/config.yml.example @@ -1,9 +1,14 @@ # 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" diff --git a/lib/gitlab_config.rb b/lib/gitlab_config.rb index 6e16a13..6cfee5d 100644 --- a/lib/gitlab_config.rb +++ b/lib/gitlab_config.rb @@ -18,4 +18,8 @@ class GitlabConfig def gitlab_url @config['gitlab_url'] ||= "http://localhost/" end + + def http_settings + @config['http_settings'] ||= {} + end end diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb index 884d95e..ef4d915 100644 --- a/lib/gitlab_net.rb +++ b/lib/gitlab_net.rb @@ -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 |