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

remote.rb « file « external « config « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3984bf9e4f8d17203d023f15b558cca5ed8137f9 (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
63
64
65
66
67
# frozen_string_literal: true

module Gitlab
  module Ci
    class Config
      module External
        module File
          class Remote < Base
            include Gitlab::Utils::StrongMemoize

            def initialize(params, context)
              @location = params[:remote]

              super
            end

            def content
              strong_memoize(:content) { fetch_remote_content }
            end

            def metadata
              super.merge(
                type: :remote,
                location: masked_location,
                blob: nil,
                raw: masked_location,
                extra: {}
              )
            end

            private

            def validate_location!
              super

              unless ::Gitlab::UrlSanitizer.valid?(location)
                errors.push("Remote file `#{masked_location}` does not have a valid address!")
              end
            end

            def fetch_remote_content
              begin
                response = context.logger.instrument(:config_file_fetch_remote_content) do
                  Gitlab::HTTP.get(location)
                end
              rescue SocketError
                errors.push("Remote file `#{masked_location}` could not be fetched because of a socket error!")
              rescue Timeout::Error
                errors.push("Remote file `#{masked_location}` could not be fetched because of a timeout error!")
              rescue Gitlab::HTTP::Error
                errors.push("Remote file `#{masked_location}` could not be fetched because of HTTP error!")
              rescue Gitlab::HTTP::BlockedUrlError => e
                errors.push("Remote file could not be fetched because #{e}!")
              end

              if response&.code.to_i >= 400
                errors.push("Remote file `#{masked_location}` could not be fetched because of HTTP code `#{response.code}` error!")
              end

              response.body if errors.none?
            end
          end
        end
      end
    end
  end
end