Commit 5c66f954 authored by Kirill Smelkov's avatar Kirill Smelkov

Allow to configure gitlab socket just by path

@jacobvosmaer noted that from user perspective it is not very handy to
have URL-encoded paths for sockets, and this way it is also not
consistent with everything else in GitLab where we use just
unix://path/to/socket instead of unix://path%2Fto%2Fsocket .

Be friends to users and allow them to configure socket path just with paths
with secondary gitlab_socket option, handler for which just encodes the
path and adds http+unix:// prefix, so internal handling is always by URL.

To protect from inconsistent input, configuration handler checks that
only one of gitlab_url or gitlab_socket can be given at a time.

NOTE CGI::escape() is used instead of URL::escape() because the latter
does not escape '/' characters by default:

    http://stackoverflow.com/questions/14989581/ruby-1-9-3-add-unsafe-characters-to-uri-escape
parent 184385ac
......@@ -13,8 +13,18 @@ user: git
# only listen on a Unix domain socket. For Unix domain sockets use
# "http+unix://<urlquoted-path-to-socket>/", e.g.
# "http+unix://%2Fpath%2Fto%2Fsocket/"
#
# see also: gitlab_socket
gitlab_url: "http://localhost:8080/"
# Path to unix socket for gitlab instance.
# Can be used instead of http+unix://... if one is not comfortable with
# URL-encoding socket path in gitlab_url. Only one of gitlab_url or
# gitlab_socket can be non-empty. Default to ""
#
# see also: gitlab_url
gitlab_socket: ""
# See installation.md#using-https for additional HTTPS configuration details.
http_settings:
# user: someone
......
require 'yaml'
require 'cgi'
class GitlabConfig
attr_reader :config
......@@ -24,7 +25,20 @@ class GitlabConfig
end
def gitlab_url
@config['gitlab_url'] ||= "http://localhost/"
gitlab_url = @config['gitlab_url']
gitlab_socket = @config['gitlab_socket']
if !gitlab_url.empty? && !gitlab_socket.empty?
raise "Only one of gitlab_url or gitlab_socket can be non-empty"
end
url = gitlab_url
if !url
if !gitlab_socket.empty?
url = "http+unix://#{CGI::escape(gitlab_socket)}/"
else
url = "http://localhost/"
end
end
url
end
def http_settings
......
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