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

settings.rb « product_analytics « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c5f25c36b9188d42d66f079fcdcecb721e85cb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

module ProductAnalytics
  class Settings
    BASE_CONFIG_KEYS = %w[product_analytics_data_collector_host cube_api_base_url cube_api_key].freeze

    JITSU_CONFIG_KEYS = (%w[jitsu_host jitsu_project_xid jitsu_administrator_email jitsu_administrator_password] +
    %w[product_analytics_clickhouse_connection_string] + BASE_CONFIG_KEYS).freeze

    SNOWPLOW_CONFIG_KEYS = (%w[product_analytics_configurator_connection_string] +
      BASE_CONFIG_KEYS).freeze

    ALL_CONFIG_KEYS = (ProductAnalytics::Settings::BASE_CONFIG_KEYS + ProductAnalytics::Settings::JITSU_CONFIG_KEYS +
      ProductAnalytics::Settings::SNOWPLOW_CONFIG_KEYS).freeze

    def initialize(project:)
      @project = project
    end

    def enabled?
      ::Gitlab::CurrentSettings.product_analytics_enabled? && configured?
    end

    def configured?
      return configured_snowplow? if Feature.enabled?(:product_analytics_snowplow_support, @project)

      JITSU_CONFIG_KEYS.all? do |key|
        get_setting_value(key).present?
      end
    end

    def configured_snowplow?
      SNOWPLOW_CONFIG_KEYS.all? do |key|
        get_setting_value(key).present?
      end
    end

    ALL_CONFIG_KEYS.each do |key|
      define_method key.to_sym do
        get_setting_value(key)
      end
    end

    class << self
      def for_project(project)
        ProductAnalytics::Settings.new(project: project)
      end
    end

    private

    # rubocop:disable GitlabSecurity/PublicSend
    def get_setting_value(key)
      @project.project_setting.public_send(key).presence ||
        ::Gitlab::CurrentSettings.public_send(key)
    end
    # rubocop:enable GitlabSecurity/PublicSend
  end
end