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

snowplow_micro.rb « destinations « tracking « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7a95e88d0b97dba79f23f4865f209bd83b7f940 (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
60
61
62
# frozen_string_literal: true
#
module Gitlab
  module Tracking
    module Destinations
      class SnowplowMicro < Snowplow
        include ::Gitlab::Utils::StrongMemoize
        extend ::Gitlab::Utils::Override

        DEFAULT_URI = 'http://localhost:9090'

        override :options
        def options(group)
          super.update(
            protocol: uri.scheme,
            port: uri.port,
            force_secure_tracker: false
          ).transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
        end

        override :enabled?
        def enabled?
          true
        end

        override :hostname
        def hostname
          "#{uri.host}:#{uri.port}"
        end

        def uri
          strong_memoize(:snowplow_uri) do
            base = base_uri
            uri = URI(base)
            uri = URI("http://#{base}") unless %w[http https].include?(uri.scheme)
            uri
          end
        end

        private

        override :cookie_domain
        def cookie_domain
          '.gitlab.com'
        end

        override :protocol
        def protocol
          uri.scheme
        end

        def base_uri
          url = Gitlab.config.snowplow_micro.address
          scheme = Gitlab.config.gitlab.https ? 'https' : 'http'
          "#{scheme}://#{url}"
        rescue Settingslogic::MissingSetting
          ENV['SNOWPLOW_MICRO_URI'] || DEFAULT_URI
        end
      end
    end
  end
end