Commit b2e46f44ceee2078b8e1d92ae5ff892c044bc0e7

Authored by Riyad Preukschas
1 parent 44969039

Refactor Settings initializer

All overrides are marked as deprecated.
Default settings are at the bottom.
Showing 1 changed file with 200 additions and 6 deletions   Show diff stats
config/initializers/1_settings.rb
@@ -2,23 +2,43 @@ class Settings < Settingslogic @@ -2,23 +2,43 @@ class Settings < Settingslogic
2 source "#{Rails.root}/config/gitlab.yml" 2 source "#{Rails.root}/config/gitlab.yml"
3 3
4 class << self 4 class << self
  5 + # FIXME: Deprecated: remove for 4.1
5 def web_protocol 6 def web_protocol
  7 + ActiveSupport::Deprecation.warn("Settings.web_protocol is deprecated and will be removed from GitLab 4.1", caller)
  8 + gitlab.protocol
  9 + rescue Settingslogic::MissingSetting
6 self.web['protocol'] ||= web.https ? "https" : "http" 10 self.web['protocol'] ||= web.https ? "https" : "http"
7 end 11 end
8 12
  13 + # FIXME: Deprecated: remove for 4.1
9 def web_host 14 def web_host
  15 + ActiveSupport::Deprecation.warn("Settings.web_host is deprecated and will be removed from GitLab 4.1", caller)
  16 + gitlab.host
  17 + rescue Settingslogic::MissingSetting
10 self.web['host'] ||= 'localhost' 18 self.web['host'] ||= 'localhost'
11 end 19 end
12 20
  21 + # FIXME: Deprecated: remove for 4.1
13 def email_from 22 def email_from
  23 + ActiveSupport::Deprecation.warn("Settings.email_from is deprecated and will be removed from GitLab 4.1", caller)
  24 + gitlab.email_from
  25 + rescue Settingslogic::MissingSetting
14 self.email['from'] ||= ("notify@" + web_host) 26 self.email['from'] ||= ("notify@" + web_host)
15 end 27 end
16 28
  29 + # FIXME: Deprecated: remove for 4.1
17 def url 30 def url
  31 + ActiveSupport::Deprecation.warn("Settings.url is deprecated and will be removed from GitLab 4.1", caller)
  32 + gitlab.url
  33 + rescue Settingslogic::MissingSetting
18 self['url'] ||= build_url 34 self['url'] ||= build_url
19 end 35 end
20 36
  37 + # FIXME: Deprecated: remove for 4.1
21 def web_port 38 def web_port
  39 + ActiveSupport::Deprecation.warn("Settings.web_port is deprecated and will be removed from GitLab 4.1", caller)
  40 + gitlab.port.to_i
  41 + rescue Settingslogic::MissingSetting
22 if web.https 42 if web.https
23 web['port'] = 443 43 web['port'] = 443
24 else 44 else
@@ -26,11 +46,17 @@ class Settings &lt; Settingslogic @@ -26,11 +46,17 @@ class Settings &lt; Settingslogic
26 end.to_i 46 end.to_i
27 end 47 end
28 48
  49 + # FIXME: Deprecated: remove for 4.1
29 def web_custom_port? 50 def web_custom_port?
  51 + ActiveSupport::Deprecation.warn("Settings.web_custom_port? is deprecated and will be removed from GitLab 4.1", caller)
  52 + gitlab_on_non_standard_port?
  53 + rescue Settingslogic::MissingSetting
30 ![443, 80].include?(web_port) 54 ![443, 80].include?(web_port)
31 end 55 end
32 56
  57 + # FIXME: Deprecated: remove for 4.1
33 def build_url 58 def build_url
  59 + ActiveSupport::Deprecation.warn("Settings.build_url is deprecated and will be removed from GitLab 4.1", caller)
34 if web_custom_port? 60 if web_custom_port?
35 custom_port = ":#{web_port}" 61 custom_port = ":#{web_port}"
36 else 62 else
@@ -44,19 +70,35 @@ class Settings &lt; Settingslogic @@ -44,19 +70,35 @@ class Settings &lt; Settingslogic
44 ].join('') 70 ].join('')
45 end 71 end
46 72
  73 + # FIXME: Deprecated: remove for 4.1
47 def ssh_port 74 def ssh_port
  75 + ActiveSupport::Deprecation.warn("Settings.ssh_port is deprecated and will be removed from GitLab 4.1", caller)
  76 + gitolite.ssh_port
  77 + rescue Settingslogic::MissingSetting
48 git_host['port'] || 22 78 git_host['port'] || 22
49 end 79 end
50 80
  81 + # FIXME: Deprecated: remove for 4.1
51 def ssh_user 82 def ssh_user
  83 + ActiveSupport::Deprecation.warn("Settings.ssh_user is deprecated and will be removed from GitLab 4.1", caller)
  84 + gitolite.ssh_user
  85 + rescue Settingslogic::MissingSetting
52 git_host['git_user'] || 'git' 86 git_host['git_user'] || 'git'
53 end 87 end
54 88
  89 + # FIXME: Deprecated: remove for 4.1
55 def ssh_host 90 def ssh_host
  91 + ActiveSupport::Deprecation.warn("Settings.ssh_host is deprecated and will be removed from GitLab 4.1", caller)
  92 + gitolite.ssh_host
  93 + rescue Settingslogic::MissingSetting
56 git_host['host'] || web_host || 'localhost' 94 git_host['host'] || web_host || 'localhost'
57 end 95 end
58 96
  97 + # FIXME: Deprecated: remove for 4.1
59 def ssh_path 98 def ssh_path
  99 + ActiveSupport::Deprecation.warn("Settings.ssh_path is deprecated and will be removed from GitLab 4.1", caller)
  100 + gitolite.ssh_path_prefix
  101 + rescue Settingslogic::MissingSetting
60 if ssh_port != 22 102 if ssh_port != 22
61 "ssh://#{ssh_user}@#{ssh_host}:#{ssh_port}/" 103 "ssh://#{ssh_user}@#{ssh_host}:#{ssh_port}/"
62 else 104 else
@@ -64,15 +106,27 @@ class Settings &lt; Settingslogic @@ -64,15 +106,27 @@ class Settings &lt; Settingslogic
64 end 106 end
65 end 107 end
66 108
  109 + # FIXME: Deprecated: remove for 4.1
67 def git_base_path 110 def git_base_path
  111 + ActiveSupport::Deprecation.warn("Settings.git_base_path is deprecated and will be removed from GitLab 4.1", caller)
  112 + gitolite.repos_path
  113 + rescue Settingslogic::MissingSetting
68 git_host['base_path'] || '/home/git/repositories/' 114 git_host['base_path'] || '/home/git/repositories/'
69 end 115 end
70 116
  117 + # FIXME: Deprecated: remove for 4.1
71 def git_hooks_path 118 def git_hooks_path
  119 + ActiveSupport::Deprecation.warn("Settings.git_hooks_path is deprecated and will be removed from GitLab 4.1", caller)
  120 + gitolite.hooks_path
  121 + rescue Settingslogic::MissingSetting
72 git_host['hooks_path'] || '/home/git/share/gitolite/hooks/' 122 git_host['hooks_path'] || '/home/git/share/gitolite/hooks/'
73 end 123 end
74 124
  125 + # FIXME: Deprecated: remove for 4.1
75 def git_upload_pack 126 def git_upload_pack
  127 + ActiveSupport::Deprecation.warn("Settings.git_upload_pack is deprecated and will be removed from GitLab 4.1", caller)
  128 + gitolite.upload_pack
  129 + rescue Settingslogic::MissingSetting
76 if git_host['upload_pack'] != false 130 if git_host['upload_pack'] != false
77 true 131 true
78 else 132 else
@@ -80,7 +134,11 @@ class Settings &lt; Settingslogic @@ -80,7 +134,11 @@ class Settings &lt; Settingslogic
80 end 134 end
81 end 135 end
82 136
  137 + # FIXME: Deprecated: remove for 4.1
83 def git_receive_pack 138 def git_receive_pack
  139 + ActiveSupport::Deprecation.warn("Settings.git_receive_pack is deprecated and will be removed from GitLab 4.1", caller)
  140 + gitolite.receive_pack
  141 + rescue Settingslogic::MissingSetting
84 if git_host['receive_pack'] != false 142 if git_host['receive_pack'] != false
85 true 143 true
86 else 144 else
@@ -88,71 +146,207 @@ class Settings &lt; Settingslogic @@ -88,71 +146,207 @@ class Settings &lt; Settingslogic
88 end 146 end
89 end 147 end
90 148
  149 + # FIXME: Deprecated: remove for 4.1
91 def git_bin_path 150 def git_bin_path
  151 + ActiveSupport::Deprecation.warn("Settings.git_bin_path is deprecated and will be removed from GitLab 4.1", caller)
  152 + git.bin_path
  153 + rescue Settingslogic::MissingSetting
92 git['path'] || '/usr/bin/git' 154 git['path'] || '/usr/bin/git'
93 end 155 end
94 156
  157 + # FIXME: Deprecated: remove for 4.1
95 def git_max_size 158 def git_max_size
  159 + ActiveSupport::Deprecation.warn("Settings.git_max_size is deprecated and will be removed from GitLab 4.1", caller)
  160 + git.max_size
  161 + rescue Settingslogic::MissingSetting
96 git['git_max_size'] || 5242880 # 5.megabytes 162 git['git_max_size'] || 5242880 # 5.megabytes
97 end 163 end
98 164
  165 + # FIXME: Deprecated: remove for 4.1
99 def git_timeout 166 def git_timeout
  167 + ActiveSupport::Deprecation.warn("Settings.git_timeout is deprecated and will be removed from GitLab 4.1", caller)
  168 + git.timeout
  169 + rescue Settingslogic::MissingSetting
100 git['git_timeout'] || 10 170 git['git_timeout'] || 10
101 end 171 end
102 172
  173 + # FIXME: Deprecated: remove for 4.1
103 def gitolite_admin_uri 174 def gitolite_admin_uri
  175 + ActiveSupport::Deprecation.warn("Settings.gitolite_admin_uri is deprecated and will be removed from GitLab 4.1", caller)
  176 + gitolite.admin_uri
  177 + rescue Settingslogic::MissingSetting
104 git_host['admin_uri'] || 'git@localhost:gitolite-admin' 178 git_host['admin_uri'] || 'git@localhost:gitolite-admin'
105 end 179 end
106 180
  181 + # FIXME: Deprecated: remove for 4.1
107 def gitolite_config_file 182 def gitolite_config_file
  183 + ActiveSupport::Deprecation.warn("Settings.gitolite_config_file is deprecated and will be removed from GitLab 4.1", caller)
  184 + gitolite.config_file
  185 + rescue Settingslogic::MissingSetting
108 git_host['config_file'] || 'gitolite.conf' 186 git_host['config_file'] || 'gitolite.conf'
109 end 187 end
110 188
  189 + # FIXME: Deprecated: remove for 4.1
111 def gitolite_admin_key 190 def gitolite_admin_key
  191 + ActiveSupport::Deprecation.warn("Settings.gitolite_admin_key is deprecated and will be removed from GitLab 4.1", caller)
  192 + gitolite.admin_key
  193 + rescue Settingslogic::MissingSetting
112 git_host['gitolite_admin_key'] || 'gitlab' 194 git_host['gitolite_admin_key'] || 'gitlab'
113 end 195 end
114 196
  197 + # FIXME: Deprecated: remove for 4.1
115 def default_projects_limit 198 def default_projects_limit
  199 + ActiveSupport::Deprecation.warn("Settings.default_projects_limit is deprecated and will be removed from GitLab 4.1", caller)
  200 + gitlab.default_projects_limit
  201 + rescue Settingslogic::MissingSetting
116 app['default_projects_limit'] || 10 202 app['default_projects_limit'] || 10
117 end 203 end
118 204
  205 + # FIXME: Deprecated: remove for 4.1
119 def backup_path 206 def backup_path
120 - t = app['backup_path'] || "backups/"  
121 - t = /^\//.match(t) ? t : Rails.root .join(t)  
122 - t 207 + ActiveSupport::Deprecation.warn("Settings.backup_path is deprecated and will be removed from GitLab 4.1", caller)
  208 + backup.path
  209 + rescue Settingslogic::MissingSetting
  210 + File.expand_path(app['backup_path'] || "backups/", Rails.root)
123 end 211 end
124 212
  213 + # FIXME: Deprecated: remove for 4.1
125 def backup_keep_time 214 def backup_keep_time
  215 + ActiveSupport::Deprecation.warn("Settings.backup_keep_time is deprecated and will be removed from GitLab 4.1", caller)
  216 + backup.keep_time
  217 + rescue Settingslogic::MissingSetting
126 app['backup_keep_time'] || 0 218 app['backup_keep_time'] || 0
127 end 219 end
128 220
  221 + # FIXME: Deprecated: remove for 4.1
129 def ldap_enabled? 222 def ldap_enabled?
130 - ldap && ldap['enabled'] 223 + ActiveSupport::Deprecation.warn("Settings.ldap_enabled? is deprecated and will be removed from GitLab 4.1", caller)
  224 + ldap.enabled
131 rescue Settingslogic::MissingSetting 225 rescue Settingslogic::MissingSetting
132 false 226 false
133 end 227 end
134 228
  229 + # FIXME: Deprecated: remove for 4.1
135 def omniauth_enabled? 230 def omniauth_enabled?
136 - omniauth && omniauth['enabled'] 231 + ActiveSupport::Deprecation.warn("Settings.omniauth_enabled? is deprecated and will be removed from GitLab 4.1", caller)
  232 + omniauth.enabled
137 rescue Settingslogic::MissingSetting 233 rescue Settingslogic::MissingSetting
138 false 234 false
139 end 235 end
140 236
  237 + # FIXME: Deprecated: remove for 4.1
141 def omniauth_providers 238 def omniauth_providers
142 - (omniauth_enabled? && omniauth['providers']) || [] 239 + ActiveSupport::Deprecation.warn("Settings.omniauth_providers is deprecated and will be removed from GitLab 4.1", caller)
  240 + omniauth.providers
  241 + rescue Settingslogic::MissingSetting
  242 + []
143 end 243 end
144 244
  245 + # FIXME: Deprecated: remove for 4.1
145 def disable_gravatar? 246 def disable_gravatar?
  247 + ActiveSupport::Deprecation.warn("Settings.disable_gravatar? is deprecated and will be removed from GitLab 4.1", caller)
  248 + !gravatar.enabled
  249 + rescue Settingslogic::MissingSetting
146 app['disable_gravatar'] || false 250 app['disable_gravatar'] || false
147 end 251 end
148 252
  253 + # FIXME: Deprecated: remove for 4.1
149 def gravatar_url 254 def gravatar_url
  255 + ActiveSupport::Deprecation.warn("Settings.gravatar_url is deprecated and will be removed from GitLab 4.1", caller)
  256 + gravatar.plain_url
  257 + rescue Settingslogic::MissingSetting
150 app['gravatar_url'] || 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm' 258 app['gravatar_url'] || 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm'
151 end 259 end
152 260
  261 + # FIXME: Deprecated: remove for 4.1
153 def gravatar_ssl_url 262 def gravatar_ssl_url
  263 + ActiveSupport::Deprecation.warn("Settings.gravatar_ssl_url is deprecated and will be removed from GitLab 4.1", caller)
  264 + gravatar.ssl_url
  265 + rescue Settingslogic::MissingSetting
154 app['gravatar_ssl_url'] || 'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm' 266 app['gravatar_ssl_url'] || 'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm'
155 end 267 end
156 268
  269 +
  270 +
  271 + def gitlab_on_non_standard_port?
  272 + ![443, 80].include?(gitlab.port.to_i)
  273 + end
  274 +
  275 + private
  276 +
  277 + def build_gitolite_ssh_path_prefix
  278 + if gitolite.ssh_port != 22
  279 + "ssh://#{gitolite.ssh_user}@#{gitolite.ssh_host}:#{gitolite.ssh_port}/"
  280 + else
  281 + "#{gitolite.ssh_user}@#{gitolite.ssh_host}:"
  282 + end
  283 + end
  284 +
  285 + def build_gitlab_url
  286 + if gitlab_on_non_standard_port?
  287 + custom_port = ":#{gitlab.port}"
  288 + else
  289 + custom_port = nil
  290 + end
  291 + [ gitlab.protocol,
  292 + "://",
  293 + gitlab.host,
  294 + custom_port
  295 + ].join('')
  296 + end
157 end 297 end
158 end 298 end
  299 +
  300 +
  301 +# Default settings
  302 +
  303 +# FIXME: Deprecated: remove for 4.1
  304 +# all Settings.web ...
  305 +# all Settings.app ...
  306 +# all Settings.email ...
  307 +# all Settings.git_host ...
  308 +Settings['pre_40_config'] ||= Settings['web'].present?
  309 +
  310 +Settings['ldap'] ||= Settingslogic.new({})
  311 +Settings.ldap['enabled'] ||= false
  312 +
  313 +Settings['omniauth'] ||= Settingslogic.new({})
  314 +Settings.omniauth['enabled'] ||= false
  315 +Settings.omniauth['providers'] ||= []
  316 +
  317 +Settings['gitlab'] ||= Settingslogic.new({})
  318 +Settings.gitlab['default_projects_limit'] ||= Settings.pre_40_config ? Settings.default_projects_limit : 10
  319 +Settings.gitlab['host'] ||= Settings.pre_40_config ? Settings.web_host : 'localhost'
  320 +Settings.gitlab['https'] ||= Settings.pre_40_config ? Settings.web.https : false
  321 +Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
  322 +Settings.gitlab['protocol'] ||= Settings.gitlab.https ? "https" : "http"
  323 +Settings.gitlab['email_from'] ||= Settings.pre_40_config ? Settings.email_from : "gitlab@#{Settings.gitlab.host}"
  324 +Settings.gitlab['url'] ||= Settings.pre_40_config ? Settings.url : Settings.send(:build_gitlab_url)
  325 +
  326 +Settings['gravatar'] ||= Settingslogic.new({})
  327 +Settings.gravatar['enabled'] ||= Settings.pre_40_config ? !Settings.disable_gravatar? : true
  328 +Settings.gravatar['plain_url'] ||= Settings.pre_40_config ? Settings.gravatar_url : 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm'
  329 +Settings.gravatar['ssl_url'] ||= Settings.pre_40_config ? Settings.gravatar_ssl_url : 'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm'
  330 +
  331 +Settings['gitolite'] ||= Settingslogic.new({})
  332 +Settings.gitolite['admin_key'] ||= Settings.pre_40_config ? Settings.gitolite_admin_key : 'gitlab'
  333 +Settings.gitolite['admin_uri'] ||= Settings.pre_40_config ? Settings.gitolite_admin_uri : 'git@localhost:gitolite-admin'
  334 +Settings.gitolite['config_file'] ||= Settings.pre_40_config ? Settings.gitolite_config_file : 'gitolite.conf'
  335 +Settings.gitolite['hooks_path'] ||= Settings.pre_40_config ? Settings.git_hooks_path : '/home/git/share/gitolite/hooks/'
  336 +Settings.gitolite['receive_pack'] ||= Settings.pre_40_config ? Settings.git_receive_pack : (Settings.gitolite['receive_pack'] != false)
  337 +Settings.gitolite['repos_path'] ||= Settings.pre_40_config ? Settings.git_base_path : '/home/git/repositories/'
  338 +Settings.gitolite['upload_pack'] ||= Settings.pre_40_config ? Settings.git_upload_pack : (Settings.gitolite['upload_pack'] != false)
  339 +Settings.gitolite['ssh_host'] ||= Settings.pre_40_config ? Settings.ssh_host : (Settings.gitlab.host || 'localhost')
  340 +Settings.gitolite['ssh_port'] ||= Settings.pre_40_config ? Settings.ssh_port : 22
  341 +Settings.gitolite['ssh_user'] ||= Settings.pre_40_config ? Settings.ssh_user : 'git'
  342 +Settings.gitolite['ssh_path_prefix'] ||= Settings.pre_40_config ? Settings.ssh_path : Settings.send(:build_gitolite_ssh_path_prefix)
  343 +
  344 +Settings['backup'] ||= Settingslogic.new({})
  345 +Settings.backup['keep_time'] ||= Settings.pre_40_config ? Settings.backup_keep_time : 0
  346 +Settings.backup['path'] = Settings.pre_40_config ? Settings.backup_path : File.expand_path(Settings.backup['path'] || "tmp/backups/", Rails.root)
  347 +
  348 +Settings['git'] ||= Settingslogic.new({})
  349 +Settings.git['max_size'] ||= Settings.pre_40_config ? Settings.git_max_size : 5242880 # 5.megabytes
  350 +Settings.git['bin_path'] ||= Settings.pre_40_config ? Settings.git_bin_path : '/usr/bin/git'
  351 +Settings.git['timeout'] ||= Settings.pre_40_config ? Settings.git_timeout : 10
  352 +Settings.git['path'] ||= Settings.git.bin_path # FIXME: Deprecated: remove for 4.1