diff options
author | Dylan Griffith <dyl.griffith@gmail.com> | 2018-04-26 09:45:01 +0800 |
---|---|---|
committer | Dylan Griffith <dyl.griffith@gmail.com> | 2018-04-26 09:45:01 +0800 |
commit | c80e6b9c1229776cf5af065954b99c182cc046c2 (patch) | |
tree | 5b9d1ca0c9f0101fd663fd83d68012c49f0ab54b /config | |
parent | 51cc01b6c9468056f40cdc8deb0e4b6414a3ccb9 (diff) | |
parent | 55f07cc32e7684b21e0c1662c70128df14c6abf7 (diff) | |
download | gitlab-ce-c80e6b9c1229776cf5af065954b99c182cc046c2.tar.gz |
Merge branch 'master' into siemens-runner-per-group
Diffstat (limited to 'config')
-rw-r--r-- | config/initializers/1_settings.rb | 2 | ||||
-rw-r--r-- | config/initializers/2_gitlab.rb | 1 | ||||
-rw-r--r-- | config/initializers/deprecations.rb | 2 | ||||
-rw-r--r-- | config/initializers/lograge.rb | 18 | ||||
-rw-r--r-- | config/karma.config.js | 2 | ||||
-rw-r--r-- | config/routes/user.rb | 18 | ||||
-rw-r--r-- | config/settings.rb | 126 |
7 files changed, 148 insertions, 21 deletions
diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 9b00ae459a3..575f27d1ea9 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -1,4 +1,4 @@ -require_dependency File.expand_path('../../lib/gitlab', __dir__) # Load Gitlab as soon as possible +require_relative '../settings' # Default settings Settings['ldap'] ||= Settingslogic.new({}) diff --git a/config/initializers/2_gitlab.rb b/config/initializers/2_gitlab.rb new file mode 100644 index 00000000000..1d2ab606a63 --- /dev/null +++ b/config/initializers/2_gitlab.rb @@ -0,0 +1 @@ +require_relative '../../lib/gitlab' diff --git a/config/initializers/deprecations.rb b/config/initializers/deprecations.rb index f3f47b2ccf0..2476ea9e38a 100644 --- a/config/initializers/deprecations.rb +++ b/config/initializers/deprecations.rb @@ -1,5 +1,5 @@ deprecator = ActiveSupport::Deprecation.new('11.0', 'GitLab') -if Gitlab.com? || Rails.env.development? +if Gitlab.dev_env_or_com? ActiveSupport::Deprecation.deprecate_methods(Gitlab::GitalyClient::StorageSettings, :legacy_disk_path, deprecator: deprecator) end diff --git a/config/initializers/lograge.rb b/config/initializers/lograge.rb index 49fdd23064c..114c1cb512f 100644 --- a/config/initializers/lograge.rb +++ b/config/initializers/lograge.rb @@ -1,21 +1,3 @@ -# Monkey patch lograge until https://github.com/roidrage/lograge/pull/241 is released -module Lograge - class RequestLogSubscriber < ActiveSupport::LogSubscriber - def strip_query_string(path) - index = path.index('?') - index ? path[0, index] : path - end - - def extract_location - location = Thread.current[:lograge_location] - return {} unless location - - Thread.current[:lograge_location] = nil - { location: strip_query_string(location) } - end - end -end - # Only use Lograge for Rails unless Sidekiq.server? filename = File.join(Rails.root, 'log', "#{Rails.env}_json.log") diff --git a/config/karma.config.js b/config/karma.config.js index 61f02294157..691cda98861 100644 --- a/config/karma.config.js +++ b/config/karma.config.js @@ -33,7 +33,7 @@ webpackConfig.plugins.push( }) ); -webpackConfig.devtool = 'cheap-inline-source-map'; +webpackConfig.devtool = process.env.BABEL_ENV !== 'coverage' && 'cheap-inline-source-map'; // Karma configuration module.exports = function(config) { diff --git a/config/routes/user.rb b/config/routes/user.rb index 57fb37530bb..f8677693fab 100644 --- a/config/routes/user.rb +++ b/config/routes/user.rb @@ -1,3 +1,21 @@ +# Allows individual providers to be directed to a chosen controller +# Call from inside devise_scope +def override_omniauth(provider, controller, path_prefix = '/users/auth') + match "#{path_prefix}/#{provider}/callback", + to: "#{controller}##{provider}", + as: "#{provider}_omniauth_callback", + via: [:get, :post] +end + +# Use custom controller for LDAP omniauth callback +if Gitlab::Auth::LDAP::Config.enabled? + devise_scope :user do + Gitlab::Auth::LDAP::Config.available_servers.each do |server| + override_omniauth(server['provider_name'], 'ldap/omniauth_callbacks') + end + end +end + devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations, passwords: :passwords, diff --git a/config/settings.rb b/config/settings.rb new file mode 100644 index 00000000000..69d637761ea --- /dev/null +++ b/config/settings.rb @@ -0,0 +1,126 @@ +require 'settingslogic' + +class Settings < Settingslogic + source ENV.fetch('GITLAB_CONFIG') { Pathname.new(File.expand_path('..', __dir__)).join('config/gitlab.yml') } + namespace ENV.fetch('GITLAB_ENV') { Rails.env } + + class << self + def gitlab_on_standard_port? + on_standard_port?(gitlab) + end + + def host_without_www(url) + host(url).sub('www.', '') + end + + def build_gitlab_ci_url + custom_port = + if on_standard_port?(gitlab) + nil + else + ":#{gitlab.port}" + end + + [ + gitlab.protocol, + "://", + gitlab.host, + custom_port, + gitlab.relative_url_root + ].join('') + end + + def build_pages_url + base_url(pages).join('') + end + + def build_gitlab_shell_ssh_path_prefix + user_host = "#{gitlab_shell.ssh_user}@#{gitlab_shell.ssh_host}" + + if gitlab_shell.ssh_port != 22 + "ssh://#{user_host}:#{gitlab_shell.ssh_port}/" + else + if gitlab_shell.ssh_host.include? ':' + "[#{user_host}]:" + else + "#{user_host}:" + end + end + end + + def build_base_gitlab_url + base_url(gitlab).join('') + end + + def build_gitlab_url + (base_url(gitlab) + [gitlab.relative_url_root]).join('') + end + + # check that values in `current` (string or integer) is a contant in `modul`. + def verify_constant_array(modul, current, default) + values = default || [] + unless current.nil? + values = [] + current.each do |constant| + values.push(verify_constant(modul, constant, nil)) + end + values.delete_if { |value| value.nil? } + end + + values + end + + # check that `current` (string or integer) is a contant in `modul`. + def verify_constant(modul, current, default) + constant = modul.constants.find { |name| modul.const_get(name) == current } + value = constant.nil? ? default : modul.const_get(constant) + if current.is_a? String + value = modul.const_get(current.upcase) rescue default + end + + value + end + + def absolute(path) + File.expand_path(path, Rails.root) + end + + private + + def base_url(config) + custom_port = on_standard_port?(config) ? nil : ":#{config.port}" + + [ + config.protocol, + "://", + config.host, + custom_port + ] + end + + def on_standard_port?(config) + config.port.to_i == (config.https ? 443 : 80) + end + + # Extract the host part of the given +url+. + def host(url) + url = url.downcase + url = "http://#{url}" unless url.start_with?('http') + + # Get rid of the path so that we don't even have to encode it + url_without_path = url.sub(%r{(https?://[^/]+)/?.*}, '\1') + + URI.parse(url_without_path).host + end + + # Runs every minute in a random ten-minute period on Sundays, to balance the + # load on the server receiving these pings. The usage ping is safe to run + # multiple times because of a 24 hour exclusive lock. + def cron_for_usage_ping + hour = rand(24) + minute = rand(6) + + "#{minute}0-#{minute}9 #{hour} * * 0" + end + end +end |