3 # Copyright (C) 2011-2014 Gitorious AS
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 require "gitorious/configurable"
19 require "gitorious/mount_point"
20 require "gitorious/openid"
21 require "gitorious/kerberos"
26 # Application-wide configuration settings.
27 Configuration = Configurable.new("GITORIOUS")
28 Configuration.rename("gitorious_host", "host")
29 Configuration.rename("sender_email_address", "email_sender")
30 Configuration.rename("gitorious_support_email", "support_email")
31 Configuration.rename("gitorious_clone_host", "git_daemon_host")
32 Configuration.rename("use_ssl", "scheme", <<-EOF) { |use_ssl| use_ssl ? "https" : "http" }
33 The scheme setting should be set to "http"
36 Configuration.rename("gitorious_user", "user")
37 Configuration.rename("repos_and_projects_private_by_default", "projects_default_private", <<-EOF)
38 Please note that this setting has been
39 split into two settings:
40 projects_default_private and repositories_default_private.
42 Configuration.rename("disable_record_throttling", "enable_record_throttling", <<-EOF) { |d| !d }
43 You should invert this value.
45 Configuration.rename("exception_notification_emails", "exception_recipients")
46 Configuration.rename("only_site_admins_can_create_projects", "enable_project_approvals")
47 Configuration.rename("hide_http_clone_urls", "enable_git_http", <<-MSG) { |d| !d }
48 You should invert this value.
50 Configuration.rename("hide_git_clone_urls", "enable_git_daemon", <<-MSG) { |d| !d }
51 You should invert this value.
53 Configuration.rename("custom_username_label", "username_label")
54 Configuration.rename("use_ldap_authorization", "enable_ldap_authorization")
55 Configuration.rename("show_license_descriptions_in_sidebar", "enable_sidebar_license_descriptions")
57 Configuration.on_deprecation do |old, new, comment|
59 WARNING! Setting '#{old}' in config/gitorious.yml is deprecated.
60 Use '#{new}' instead. Many configuration settings have changed
61 in Gitorious 3, please refer to config/gitorious.sample.yml for full documentation.
67 return @site if @site && cache?
68 host = Gitorious::Configuration.get("host", "gitorious.local")
69 port = Gitorious::Configuration.get("port")
70 scheme = Gitorious::Configuration.get("scheme")
71 @site = Gitorious::HttpMountPoint.new(host, port, scheme)
74 def self.scheme; site.scheme; end
75 def self.host; site.host; end
76 def self.port; site.port; end
77 def self.ssl?; site.ssl?; end
78 def self.default_port?; site.default_port?; end
79 def self.url(path); site.url(path); end
82 return @git_daemon if @git_daemon && cache?
83 return nil if !Gitorious::Configuration.get("enable_git_daemon", false)
84 host = Gitorious::Configuration.get("git_daemon_host") { Gitorious.host }
85 port = Gitorious::Configuration.get("git_daemon_port")
86 @git_daemon = Gitorious::GitMountPoint.new(host, port)
90 return @ssh_daemon if @ssh_daemon && cache?
91 return nil if !Gitorious::Configuration.get("enable_ssh_daemon", true)
92 host = Gitorious::Configuration.get("ssh_daemon_host") { Gitorious.host }
93 port = Gitorious::Configuration.get("ssh_daemon_port") { 22 }
94 @ssh_daemon = Gitorious::GitSshMountPoint.new(Gitorious.user, host, port)
98 return @git_http if @git_http && cache?
99 return nil if !Gitorious::Configuration.get("enable_git_http", true)
100 host = Gitorious::Configuration.get("git_http_host") { Gitorious.host }
101 port = Gitorious::Configuration.get("git_http_port") { Gitorious.port }
102 scheme = Gitorious::Configuration.get("git_http_scheme") { Gitorious.scheme }
103 @git_http = Gitorious::HttpMountPoint.new(host, port, scheme)
106 def self.default_remote_url(repository)
107 (ssh_daemon || git_daemon || git_http).url(repository.gitdir)
110 def self.email_sender
111 return @email_sender if @email_sender && cache?
112 default = "Gitorious <no-reply@#{host}>"
113 @email_sender = Gitorious::Configuration.get("email_sender", default)
117 return @user if @user && cache?
118 @user = Gitorious::Configuration.get("user", "git")
122 return @public if !@public.nil? && cache?
123 @public = Gitorious::Configuration.get("public_mode", true)
126 def self.private_repositories?
127 return @private_repos if !@private_repos.nil? && cache?
128 @private_repos = Gitorious::Configuration.get("enable_private_repositories", false)
131 def self.projects_default_private?
132 return @projdefpriv if !@projdefpriv.nil? && cache?
133 @projdefpriv = private_repositories? && Gitorious::Configuration.get("projects_default_private", false)
136 def self.repositories_default_private?
137 return @repodefpriv if !@repodefpriv.nil? && cache?
138 @repodefpriv = private_repositories? && Gitorious::Configuration.get("repositories_default_private", false)
141 def self.support_email
142 return @support_email if @support_email && cache?
143 @support_email = Gitorious::Configuration.get("support_email") do
144 "gitorious-support@#{host}"
148 def self.archive_cache_dir
149 return @archive_cache_dir if @archive_cache_dir && cache?
150 @archive_cache_dir = Gitorious::Configuration.get("archive_cache_dir")
153 def self.archive_work_dir
154 return @archive_work_dir if @archive_work_dir && cache?
155 @archive_work_dir = Gitorious::Configuration.get("archive_work_dir")
158 def self.diff_timeout
159 return @diff_timeout if @diff_timeout && cache?
160 @diff_timeout = Gitorious::Configuration.get("merge_request_diff_timeout", 10).to_i
164 @is_gitorious_org = Gitorious::Configuration.get("is_gitorious_dot_org", false)
168 return @git_binary if @git_binary && cache?
169 @git_binary = Gitorious::Configuration.get("git_binary", "/usr/bin/env git")
173 return @git_version if @git_version && cache?
174 @git_version = Gitorious::Configuration.get("git_version")
178 return @site_name if @site_name && cache?
179 @site_name = Gitorious::Configuration.get("site_name", "Gitorious")
182 def self.registrations_enabled?
183 Gitorious::Configuration.get("enable_registrations", Gitorious.public?)
186 def self.max_tarball_size
187 return @max_tarball_size if @max_tarball_size && cache?
188 mts = Gitorious::Configuration.get("max_tarball_size", 0)
189 return mts.to_i * 1024 if mts =~ /k$/i
190 return mts.to_i * 1024 * 1024 if mts =~ /m$/i
191 return mts.to_i * 1024 * 1024 * 1024 if mts =~ /g$/i
192 @max_tarball_size = mts.to_i
195 def self.tarballable?(repository)
196 return true if max_tarball_size == 0 || repository.disk_usage.nil?
197 return repository.disk_usage <= max_tarball_size
208 def self.restrict_team_creation_to_site_admins?
209 Gitorious::Configuration.get("only_site_admins_can_create_teams")
213 return @executor if @executor
216 require 'gitorious/test_executor'
217 @executor = TestExecutor.new
219 require 'gitorious/command_executor'
220 @executor = CommandExecutor.new
225 return @mirrors if @mirrors
226 @mirrors = Gitorious::MirrorManager.new(Gitorious::Configuration.get('mirrors', []))
231 return Rails.env.production? if defined?(Rails)