debian-mirror-gitlab/lib/gitlab/mail_room.rb

61 lines
1.4 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
require 'yaml'
require 'json'
2017-09-10 17:25:29 +05:30
require_relative 'redis/queues' unless defined?(Gitlab::Redis::Queues)
2016-09-13 17:45:13 +05:30
module Gitlab
module MailRoom
2018-03-17 18:26:18 +05:30
DEFAULT_CONFIG = {
enabled: false,
port: 143,
ssl: false,
start_tls: false,
mailbox: 'inbox',
idle_timeout: 60
}.freeze
2016-09-13 17:45:13 +05:30
class << self
def enabled?
config[:enabled] && config[:address]
end
def config
@config ||= fetch_config
end
def reset_config!
@config = nil
end
private
def fetch_config
return {} unless File.exist?(config_file)
2018-03-17 18:26:18 +05:30
config = YAML.load_file(config_file)[rails_env].deep_symbolize_keys[:incoming_email] || {}
config = DEFAULT_CONFIG.merge(config) do |_key, oldval, newval|
newval.nil? ? oldval : newval
end
2016-09-13 17:45:13 +05:30
if config[:enabled] && config[:address]
2017-09-10 17:25:29 +05:30
gitlab_redis_queues = Gitlab::Redis::Queues.new(rails_env)
config[:redis_url] = gitlab_redis_queues.url
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
if gitlab_redis_queues.sentinels?
config[:sentinels] = gitlab_redis_queues.sentinels
2017-08-17 22:00:37 +05:30
end
2016-09-13 17:45:13 +05:30
end
config
end
2018-03-17 18:26:18 +05:30
def rails_env
@rails_env ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
end
2016-09-13 17:45:13 +05:30
def config_file
ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] || File.expand_path('../../../config/gitlab.yml', __FILE__)
end
end
end
end