GitLab steht Mittwoch, den 08. Juli, zwischen 09:00 und 13:00 Uhr aufgrund von Wartungsarbeiten nicht zur Verfügung.

mail_room.rb 1.41 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'yaml'
require 'json'
5
require_relative 'redis/queues' unless defined?(Gitlab::Redis::Queues)
6 7 8

module Gitlab
  module MailRoom
9 10 11 12 13 14 15 16 17
    DEFAULT_CONFIG = {
      enabled: false,
      port: 143,
      ssl: false,
      start_tls: false,
      mailbox: 'inbox',
      idle_timeout: 60
    }.freeze

18 19 20 21 22 23 24 25 26
    class << self
      def enabled?
        config[:enabled] && config[:address]
      end

      def config
        @config ||= fetch_config
      end

27 28
      def reset_config!
        @config = nil
29 30
      end

31 32 33
      private

      def fetch_config
34
        return {} unless File.exist?(config_file)
35

36 37 38 39
        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
40 41

        if config[:enabled] && config[:address]
42 43
          gitlab_redis_queues = Gitlab::Redis::Queues.new(rails_env)
          config[:redis_url] = gitlab_redis_queues.url
44

45 46
          if gitlab_redis_queues.sentinels?
            config[:sentinels] = gitlab_redis_queues.sentinels
47
          end
48
        end
49 50

        config
51 52
      end

53 54 55 56
      def rails_env
        @rails_env ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
      end

57
      def config_file
Lin Jen-Shin's avatar
Lin Jen-Shin committed
58
        ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] || File.expand_path('../../config/gitlab.yml', __dir__)
59 60 61 62
      end
    end
  end
end