Read about our upcoming Code of Conduct on this issue

light_settings.rb 674 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

class LightSettings
  GL_HOST ||= 'gitlab.com'
  GL_SUBDOMAIN_REGEX ||= %r{\A[a-z0-9]+\.gitlab\.com\z}.freeze

  class << self
    def com?
      return Thread.current[:is_com] unless Thread.current[:is_com].nil?

      Thread.current[:is_com] = host == GL_HOST || gl_subdomain?
    end

    private

    def config
      YAML.safe_load(File.read(settings_path), aliases: true)[Rails.env]
    end

    def settings_path
      Rails.root.join('config', 'gitlab.yml')
    end

    def host
25
      config.dig('gitlab', 'host') || ENV['GITLAB_HOST'] || 'localhost'
26
27
28
29
30
31
32
    end

    def gl_subdomain?
      GL_SUBDOMAIN_REGEX === host
    end
  end
end