diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | config/initializers/1_settings.rb | 6 | ||||
-rw-r--r-- | config/mail_room.yml | 85 | ||||
-rw-r--r-- | lib/tasks/gitlab/check.rake | 10 | ||||
-rw-r--r-- | spec/config/mail_room_spec.rb | 56 | ||||
-rw-r--r-- | spec/fixtures/mail_room_disabled.yml | 11 | ||||
-rw-r--r-- | spec/fixtures/mail_room_enabled.yml | 11 |
7 files changed, 135 insertions, 45 deletions
diff --git a/CHANGELOG b/CHANGELOG index ae9b25fd7bb..8de86f53129 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ v 8.6.0 (unreleased) - Improve the formatting for the user page bio (Connor Shea) - Fix issue when pushing to projects ending in .wiki - Fix avatar stretching by providing a cropping feature (Johann Pardanaud) + - Don't load all of GitLab in mail_room - Strip leading and trailing spaces in URL validator (evuez) - Return empty array instead of 404 when commit has no statuses in commit status API - Update documentation to reflect Guest role not being enforced on internal projects diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 713204b1c51..626268d7648 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -207,11 +207,7 @@ Settings.gitlab_ci['builds_path'] = File.expand_path(Settings.gitlab_c # Reply by email # Settings['incoming_email'] ||= Settingslogic.new({}) -Settings.incoming_email['enabled'] = false if Settings.incoming_email['enabled'].nil? -Settings.incoming_email['port'] = 143 if Settings.incoming_email['port'].nil? -Settings.incoming_email['ssl'] = false if Settings.incoming_email['ssl'].nil? -Settings.incoming_email['start_tls'] = false if Settings.incoming_email['start_tls'].nil? -Settings.incoming_email['mailbox'] = "inbox" if Settings.incoming_email['mailbox'].nil? +Settings.incoming_email['enabled'] = false if Settings.incoming_email['enabled'].nil? # # Build Artifacts diff --git a/config/mail_room.yml b/config/mail_room.yml index 42f6f74c465..f266a70ee0d 100644 --- a/config/mail_room.yml +++ b/config/mail_room.yml @@ -1,39 +1,52 @@ :mailboxes: <% -require_relative 'config/environment.rb' - -if Gitlab::IncomingEmail.enabled? - config = Gitlab::IncomingEmail.config - - redis_config_file = "config/resque.yml" - redis_url = - if File.exists?(redis_config_file) - YAML.load_file(redis_config_file)[Rails.env] - else - "redis://localhost:6379" - end - %> - - - :host: <%= config.host.to_json %> - :port: <%= config.port.to_json %> - :ssl: <%= config.ssl.to_json %> - :start_tls: <%= config.start_tls.to_json %> - :email: <%= config.user.to_json %> - :password: <%= config.password.to_json %> - - :name: <%= config.mailbox.to_json %> - - :delete_after_delivery: true - - :delivery_method: sidekiq - :delivery_options: - :redis_url: <%= redis_url.to_json %> - :namespace: resque:gitlab - :queue: incoming_email - :worker: EmailReceiverWorker - - :arbitration_method: redis - :arbitration_options: - :redis_url: <%= redis_url.to_json %> - :namespace: mail_room:gitlab +require "yaml" +require "json" + +rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" + +config_file = ENV["MAIL_ROOM_GITLAB_CONFIG_FILE"] || "config/gitlab.yml" +if File.exists?(config_file) + all_config = YAML.load_file(config_file)[rails_env] + + config = all_config["incoming_email"] || {} + config['enabled'] = false if config['enabled'].nil? + config['port'] = 143 if config['port'].nil? + config['ssl'] = false if config['ssl'].nil? + config['start_tls'] = false if config['start_tls'].nil? + config['mailbox'] = "inbox" if config['mailbox'].nil? + + if config['enabled'] && config['address'] && config['address'].include?('%{key}') + redis_config_file = "config/resque.yml" + redis_url = + if File.exists?(redis_config_file) + YAML.load_file(redis_config_file)[rails_env] + else + "redis://localhost:6379" + end + %> + - + :host: <%= config['host'].to_json %> + :port: <%= config['port'].to_json %> + :ssl: <%= config['ssl'].to_json %> + :start_tls: <%= config['start_tls'].to_json %> + :email: <%= config['user'].to_json %> + :password: <%= config['password'].to_json %> + + :name: <%= config['mailbox'].to_json %> + + :delete_after_delivery: true + + :delivery_method: sidekiq + :delivery_options: + :redis_url: <%= redis_url.to_json %> + :namespace: resque:gitlab + :queue: incoming_email + :worker: EmailReceiverWorker + + :arbitration_method: redis + :arbitration_options: + :redis_url: <%= redis_url.to_json %> + :namespace: mail_room:gitlab + <% end %> <% end %> diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index d59872dc3a2..581ab26db79 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -728,13 +728,15 @@ namespace :gitlab do def check_imap_authentication print "IMAP server credentials are correct? ... " - config = Gitlab.config.incoming_email + config_path = Rails.root.join('config', 'mail_room.yml') + config_file = YAML.load(ERB.new(File.read(config_path)).result) + config = config_file[:mailboxes].first if config begin - imap = Net::IMAP.new(config.host, port: config.port, ssl: config.ssl) - imap.starttls if config.start_tls - imap.login(config.user, config.password) + imap = Net::IMAP.new(config[:host], port: config[:port], ssl: config[:ssl]) + imap.starttls if config[:start_tls] + imap.login(config[:email], config[:password]) connected = true rescue connected = false diff --git a/spec/config/mail_room_spec.rb b/spec/config/mail_room_spec.rb new file mode 100644 index 00000000000..462afb24f08 --- /dev/null +++ b/spec/config/mail_room_spec.rb @@ -0,0 +1,56 @@ +require "spec_helper" + +describe "mail_room.yml" do + let(:config_path) { "config/mail_room.yml" } + let(:configuration) { YAML.load(ERB.new(File.read(config_path)).result) } + + context "when incoming email is disabled" do + before do + ENV["MAIL_ROOM_GITLAB_CONFIG_FILE"] = Rails.root.join("spec/fixtures/mail_room_disabled.yml").to_s + end + + after do + ENV["MAIL_ROOM_GITLAB_CONFIG_FILE"] = nil + end + + it "contains no configuration" do + expect(configuration[:mailboxes]).to be_nil + end + end + + context "when incoming email is enabled" do + before do + ENV["MAIL_ROOM_GITLAB_CONFIG_FILE"] = Rails.root.join("spec/fixtures/mail_room_enabled.yml").to_s + end + + after do + ENV["MAIL_ROOM_GITLAB_CONFIG_FILE"] = nil + end + + it "contains the intended configuration" do + expect(configuration[:mailboxes].length).to eq(1) + + mailbox = configuration[:mailboxes].first + + expect(mailbox[:host]).to eq("imap.gmail.com") + expect(mailbox[:port]).to eq(993) + expect(mailbox[:ssl]).to eq(true) + expect(mailbox[:start_tls]).to eq(false) + expect(mailbox[:email]).to eq("gitlab-incoming@gmail.com") + expect(mailbox[:password]).to eq("[REDACTED]") + expect(mailbox[:name]).to eq("inbox") + + redis_config_file = Rails.root.join('config', 'resque.yml') + + redis_url = + if File.exists?(redis_config_file) + YAML.load_file(redis_config_file)[Rails.env] + else + "redis://localhost:6379" + end + + expect(mailbox[:delivery_options][:redis_url]).to eq(redis_url) + expect(mailbox[:arbitration_options][:redis_url]).to eq(redis_url) + end + end +end diff --git a/spec/fixtures/mail_room_disabled.yml b/spec/fixtures/mail_room_disabled.yml new file mode 100644 index 00000000000..97f8cff051f --- /dev/null +++ b/spec/fixtures/mail_room_disabled.yml @@ -0,0 +1,11 @@ +test: + incoming_email: + enabled: false + address: "gitlab-incoming+%{key}@gmail.com" + user: "gitlab-incoming@gmail.com" + password: "[REDACTED]" + host: "imap.gmail.com" + port: 993 + ssl: true + start_tls: false + mailbox: "inbox" diff --git a/spec/fixtures/mail_room_enabled.yml b/spec/fixtures/mail_room_enabled.yml new file mode 100644 index 00000000000..9c94649244d --- /dev/null +++ b/spec/fixtures/mail_room_enabled.yml @@ -0,0 +1,11 @@ +test: + incoming_email: + enabled: true + address: "gitlab-incoming+%{key}@gmail.com" + user: "gitlab-incoming@gmail.com" + password: "[REDACTED]" + host: "imap.gmail.com" + port: 993 + ssl: true + start_tls: false + mailbox: "inbox" |