Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-01 00:08:52 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-01 00:08:52 +0300
commitd5d3c03598df712550acf0c6463a61c6e7dcc19e (patch)
treed0fdf0f9cd6df46aea6ed16b6556f44055efb642 /lib/gitlab/mail_room.rb
parent0434f38ef1dce4fe640fe1e4542235746ceb943c (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/mail_room.rb')
-rw-r--r--lib/gitlab/mail_room.rb62
1 files changed, 42 insertions, 20 deletions
diff --git a/lib/gitlab/mail_room.rb b/lib/gitlab/mail_room.rb
index f7699ef1718..bd69843adf1 100644
--- a/lib/gitlab/mail_room.rb
+++ b/lib/gitlab/mail_room.rb
@@ -2,6 +2,7 @@
require 'yaml'
require 'json'
+require 'pathname'
require_relative 'redis/queues' unless defined?(Gitlab::Redis::Queues)
# This service is run independently of the main Rails process,
@@ -21,39 +22,60 @@ module Gitlab
log_path: RAILS_ROOT_DIR.join('log', 'mail_room_json.log')
}.freeze
+ # Email specific configuration which is merged with configuration
+ # fetched from YML config file.
+ ADDRESS_SPECIFIC_CONFIG = {
+ incoming_email: {
+ queue: 'email_receiver',
+ worker: 'EmailReceiverWorker'
+ },
+ service_desk_email: {
+ queue: 'service_desk_email_receiver',
+ worker: 'ServiceDeskEmailReceiverWorker'
+ }
+ }.freeze
+
class << self
- def enabled?
- config[:enabled] && config[:address]
+ def enabled_configs
+ @enabled_configs ||= configs.select { |config| enabled?(config) }
end
- def config
- @config ||= fetch_config
- end
+ private
- def reset_config!
- @config = nil
+ def enabled?(config)
+ config[:enabled] && !config[:address].to_s.empty?
end
- private
+ def configs
+ ADDRESS_SPECIFIC_CONFIG.keys.map { |key| fetch_config(key) }
+ end
- def fetch_config
+ def fetch_config(config_key)
return {} unless File.exist?(config_file)
- config = load_from_yaml || {}
- config = DEFAULT_CONFIG.merge(config) do |_key, oldval, newval|
+ config = merged_configs(config_key)
+ config.merge!(redis_config) if enabled?(config)
+ config[:log_path] = File.expand_path(config[:log_path], RAILS_ROOT_DIR)
+
+ config
+ end
+
+ def merged_configs(config_key)
+ yml_config = load_yaml.fetch(config_key, {})
+ specific_config = ADDRESS_SPECIFIC_CONFIG.fetch(config_key, {})
+ DEFAULT_CONFIG.merge(specific_config, yml_config) do |_key, oldval, newval|
newval.nil? ? oldval : newval
end
+ end
- if config[:enabled] && config[:address]
- gitlab_redis_queues = Gitlab::Redis::Queues.new(rails_env)
- config[:redis_url] = gitlab_redis_queues.url
+ def redis_config
+ gitlab_redis_queues = Gitlab::Redis::Queues.new(rails_env)
+ config = { redis_url: gitlab_redis_queues.url }
- if gitlab_redis_queues.sentinels?
- config[:sentinels] = gitlab_redis_queues.sentinels
- end
+ if gitlab_redis_queues.sentinels?
+ config[:sentinels] = gitlab_redis_queues.sentinels
end
- config[:log_path] = File.expand_path(config[:log_path], RAILS_ROOT_DIR)
config
end
@@ -65,8 +87,8 @@ module Gitlab
ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] || File.expand_path('../../config/gitlab.yml', __dir__)
end
- def load_from_yaml
- YAML.load_file(config_file)[rails_env].deep_symbolize_keys[:incoming_email]
+ def load_yaml
+ @yaml ||= YAML.load_file(config_file)[rails_env].deep_symbolize_keys
end
end
end