summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-23 05:56:27 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-23 05:56:27 -0700
commit07d17a8b3e7fd6cae2118c360e5381973f75dd9b (patch)
treecf5bbd1c02107d2e38981daa312bc267cf780ca5
parent601450c30d66a17b3b445f0ca7367eae458efcdd (diff)
parentacdeb0bf1f7660031183e5fea785d6d665013284 (diff)
downloadgitlab-shell-07d17a8b3e7fd6cae2118c360e5381973f75dd9b.tar.gz
Merge pull request #23 from regru/http_settings_option
http_settings configuration option added.
-rw-r--r--config.yml.example7
-rw-r--r--lib/gitlab_config.rb4
-rw-r--r--lib/gitlab_net.rb15
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